Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Candlex: an Nx.Backend for candle ML framework #1294

Closed
wants to merge 196 commits into from

Conversation

grzuy
Copy link
Contributor

@grzuy grzuy commented Aug 30, 2023

UPDATE: Released in https://hex.pm/packages/candlex and kept as separate repo in https://github.com/mimiquate/candlex.


An experimental work-in-progress exploring the possibility of implementing an Nx.Backend for candle-core rust crate.

Note that https://github.com/huggingface/candle is still in early development and a moving target.

Still a lot of Nx.Backend behavior callbacks pending implementation, so plan it continue making progress here to cover as much as possible.

No CUDA at the moment, only CPU.
UPDATE: Decent CUDA support for a small subset of backend functions.
UPDATE2: Decent CUDA support for slightly more than half backend callbacks.

UPDATE3:

  • About ~90 out of 117 Nx.Backend callbacks have some form of implementation (complete or partial).
  • Device support: Yes, CPU and GPU/CUDA
  • Axon's examples/vision/mnist.exs and examples/generative/fashionmnist_autoencoder.exs are working using Candlex.Backend with similar performance to Torchx both in cpu and cuda. Other examples failing because of still some missing callback or callback option.

Pending:

  • Consider rustler_precompiled to avoid dependency on the rust toolchain
  • Update github actions to run candlex tests
  • Cover more Nx.Backend callbacks (tensor operations)
  • Better support for f16 and bf16
  • Make it work with more elaborated Axon model examples

Updates to upstream candle as part of this effort:
huggingface/candle#741
huggingface/candle#925
huggingface/candle#988
huggingface/candle#996
huggingface/candle#1037


UPDATE 4: Also published in a separate repo: https://github.com/mimiquate/candlex.

@grzuy
Copy link
Contributor Author

grzuy commented Oct 6, 2023

This is awesome!

I have dropped some comments and ultimately we will only know if we should merge this or not based on how complete Candle is. If it is missing many operations, then perhaps it is better to wait, but I don't see any problems from a glance. We will need to discuss between us too.

Hi guys, updated this pull request description with a summary of the current status of this effort.

@grzuy grzuy marked this pull request as ready for review October 6, 2023 20:03
@grzuy
Copy link
Contributor Author

grzuy commented Oct 9, 2023

@josevalim @polvalente Got this PR to a point it might make sense to slow down a bit and wait for some feedback from you guys on whether you see a good fit for that inside Nx or release is separtely for now.

Thanks in advance!

@grzuy grzuy changed the title Candlex: an Nx.Backend for candle rust crate Candlex: an Nx.Backend for candle ML framework Oct 25, 2023
@grzuy
Copy link
Contributor Author

grzuy commented Oct 27, 2023

While this package is in consideration for inclusion as part of this repo, found it valuable to publish separately too (https://github.com/mimiquate/candlex), so it's easier for anyone to navigate it, try it out, open issues, propose improvements via PRs, etc. In case gets accepted here we can just archive the separate repo.

Plan to keep this PR up to date with any updates upstream.

Thanks again!

@josevalim
Copy link
Collaborator

Hi @grzuy! I did another pass over it and it looks really solid!

However, after working on Nx over the last few days, i believe we should not merge this. Adding new features to Nx already requires us to add code to both EXLA and Torchx. Although both projects are in C++, it is already time consuming. Adding a Rust project means both additional tooling and an additional language, and I am worried it will harm our productivity.

Therefore I suggest to keep it in a separate project (but feel free to submit a PR to the README to link to it). :)

Have a good one!

@josevalim josevalim closed this Nov 7, 2023
@grzuy
Copy link
Contributor Author

grzuy commented Nov 8, 2023

Hi @josevalim,

Reasonable. Sounds good.
Thank you for the feedback!

Will PR to README later.

Thanks!

@grzuy grzuy deleted the candlex branch November 8, 2023 12:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants