Dala.ML.Nx (dala v0.0.3)

Copy Markdown View Source

Nx integration helpers for Dala on iOS.

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

Summary

Functions

Returns the default backend for the current iOS platform.

Checks if EMLX is available.

Example: Simple neural network layer using Axon on iOS.

Runs inference with a model using the best available backend.

Initializes Nx with the best available backend for iOS.

Loads a pre-trained model for inference on iOS.

Creates a tensor on iOS with platform-appropriate backend.

Functions

default_backend()

Returns the default backend for the current iOS platform.

emlx_available?()

Checks if EMLX is available.

example_dense_layer()

Example: Simple neural network layer using Axon on iOS.

Note: Axon is pure Elixir and works on any platform with Nx. This is just an example - Axon needs to be added as a dependency.

inference(model, input_data)

Runs inference with a model using the best available backend.

init_for_ios()

Initializes Nx with the best available backend for iOS.

Priority:

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

load_model(model_path)

Loads a pre-trained model for inference on iOS.

Note: This is a placeholder. In practice, you would:

  1. Train or download a pre-trained model
  2. Serialize it (Axon supports serialization)
  3. Load it here for inference

tensor(data, opts \\ [])

Creates a tensor on iOS with platform-appropriate backend.