Dala.Ml.Nx (dala v0.3.2)

Copy Markdown View Source

Nx integration helpers for Dala.

Nx itself is pure Elixir and works on any platform. This module provides backend selection logic and inference helpers.

Summary

Functions

Checks if Axon is available.

Returns the default backend for the current platform.

Checks if EMLX is available.

Runs inference with an Axon model using the best available backend.

Initializes Nx with the best available backend for the current platform.

Creates a tensor with the platform-appropriate backend.

Functions

axon_available?()

@spec axon_available?() :: boolean()

Checks if Axon is available.

default_backend()

@spec default_backend() :: module() | tuple()

Returns the default backend for the current platform.

emlx_available?()

@spec emlx_available?() :: boolean()

Checks if EMLX is available.

inference(model, params, input_data)

@spec inference(term(), term(), term()) :: {:ok, term()} | {:error, term()}

Runs inference with an Axon model using the best available backend.

init()

@spec init() :: :emlx | :nx_binary

Initializes Nx with the best available backend for the current platform.

Priority:

  1. EMLX (if available) - best for Apple Silicon
  2. Nx.BinaryBackend (pure Elixir fallback)

tensor(data, opts \\ [])

@spec tensor(
  term(),
  keyword()
) :: Nx.Tensor.t()

Creates a tensor with the platform-appropriate backend.