BalancedTernaryEngine. Runtime
(balanced_ternary_engine v0.1.0-dev)
Copy Markdown
Minimal runtime for executing a converted .tbin model.
Supports layer chaining, softmax, layer normalization, multi-head attention with a KV cache, and prefill/decode phases.
Summary
Functions
Multi-head attention with a KV cache.
Decode: run a single new token, reusing the cache.
Run the model (layer chaining) on an input tensor.
Layer normalization (RMSNorm-style) over the last axis.
Load a .tbin model and an optional config map.
Create a runtime from already-loaded layers and a config map.
Prefill: run a full sequence through the model, populating the cache.
Reset the runtime cache without reloading the model.
Softmax over the last axis.
Validate a runtime instance.
Validate a runtime configuration map.
Types
Functions
@spec attention(Nx.Tensor.t(), Nx.Tensor.t(), Nx.Tensor.t(), map(), integer()) :: {Nx.Tensor.t(), map()}
Multi-head attention with a KV cache.
q, k, v are {seq, hidden} tensors. Returns {out, new_cache}.
@spec decode(t(), Nx.Tensor.t()) :: {Nx.Tensor.t(), t()}
Decode: run a single new token, reusing the cache.
@spec forward(t(), Nx.Tensor.t()) :: Nx.Tensor.t()
Run the model (layer chaining) on an input tensor.
@spec layer_norm(Nx.Tensor.t(), float()) :: Nx.Tensor.t()
Layer normalization (RMSNorm-style) over the last axis.
Load a .tbin model and an optional config map.
Create a runtime from already-loaded layers and a config map.
@spec prefill(t(), Nx.Tensor.t()) :: {Nx.Tensor.t(), t()}
Prefill: run a full sequence through the model, populating the cache.
Reset the runtime cache without reloading the model.
@spec softmax(Nx.Tensor.t()) :: Nx.Tensor.t()
Softmax over the last axis.
Validate a runtime instance.
Validate a runtime configuration map.
Returns {:ok, config} when every supplied value is valid, or
{:error, reason} otherwise. Unknown keys are allowed so callers can
carry application-specific settings.