# Candlex


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.8"}

Documentation can be generated with [ExDoc](
and published on [HexDocs]( Once published, the docs can
be found at <>.

## 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:


More details in [Nx backends](


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.


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 ``.
1. `git tag -s <tag-version>` to create new signed tag.
1. `git push origin <tag-version>` to push the tag.
1. Wait for the `binaries.yml` GitHub workflow to build all the NIF binaries.
1. `mix Candlex.Native --all --print` to generate binaries checksums locally.
1. `rm -r native/candlex/target priv/native` to leave out rust crate build artifacts from published elixir package.
1. `mix --unpack` to check the package includes the correct files.
1. Publish the release from draft in GitHub.
1. `mix hex.publish` to publish package to
1. `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

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
See the License for the specific language governing permissions and
limitations under the License.