Skip to content

mimiquate/candlex

Repository files navigation

Candlex

ci Hex.pm Docs

An Nx backend for candle (docs, repo, crate) machine learning framework

Installation

If available in Hex, the package can be installed by adding candlex to your list of dependencies in mix.exs:

def deps do
  [
    {:candlex, "~> 0.1.10"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/candlex.

Usage

Just configure Nx to default to Candlex backend in your configuration:

# Possibly config/runtime.exs

config :nx, default_backend: Candlex.Backend

or in your scripts, precede all your Nx operations with:

Nx.default_backend(Candlex.Backend)

More details in Nx backends

CANDLEX_NIF_BUILD

Defaults to false. If true the native binary is built locally, which may be useful if no precompiled binary is available for your target environment. Once set, you must run mix deps.clean candlex --build explicitly to force to recompile. Building has a number of dependencies, see Building from source below.

CANDLEX_NIF_TARGET

The default value is cpu, which implies the final the binary supports targeting only the host CPU.

Value Target environment
cpu
cuda CUDA 12.x

To use Candlex with NVidia GPU you need CUDA compatible with your GPU drivers.

Building from source

To build the native binary locally you need to set CANDLEX_NIF_BUILD=true. Keep in mind that the compilation usually takes time.

You will need the following installed in your system for the compilation:

  • Git for fetching candle-core source
  • Rust with cargo to compile rustler NIFs

GPU support

To build native binary with GPU support, you need to run in an environment that has CUDA installed, then you can build with CANDLEX_NIF_TARGET=cuda. See the CANDLEX_NIF_TARGET for more details.

Releasing

To publish a new version of this package:

  1. Update version in mix.exs, .github/workflows/binaries.yml and README.md.
  2. git commit -am "build: bump version to <tag-version>"
  3. git tag -s <tag-version> to create new signed tag.
  4. git push origin <tag-version> to push the tag.
  5. Wait for the binaries.yml GitHub workflow to build all the NIF binaries.
  6. Publish the newly created draft release in GitHub (the download won't find the binaries otherwise).
  7. mix rustler_precompiled.download Candlex.Native --all --print to generate binaries checksums locally.
  8. rm -r native/candlex/target priv/native to leave out rust crate build artifacts from published elixir package.
  9. mix hex.build --unpack to check the package includes the correct files.
  10. mix hex.publish to publish package to Hex.pm.
  11. git push origin main

License

Copyright 2023 Mimiquate

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.