zyx-nn
Neural network modules for the zyx machine learning library.
This crate provides a collection of common neural network building blocks implemented as reusable Module traits, designed to work seamlessly with zyx's kernel fusion and autograd system.
Features
Linear & Normalization
Linear— Dense fully-connected layerLayerNorm— Layer normalizationBatchNorm— Batch normalizationGroupNorm— Group normalizationRMSNorm— Root mean square normalization
Recurrent Layers
RNNCell— Simple recurrent cellGRUCell— Gated recurrent unitLSTMCell— Long short-term memory
Attention Mechanisms
CausalSelfAttention— Causal self-attention for transformersMultiheadAttention— Multi-head attention with configurable heads
Embeddings & Convolution
Embedding— Learnable embedding lookupConv2d— 2D convolution
Transformers
TransformerEncoderLayer— Single transformer encoder blockTransformerDecoderLayer— Single transformer decoder blockPositionalEncoding— Sinusoidal positional embeddings
Python Bindings
pyfeature enables Python interoperability viapyo3
Usage
use ;
use ;
let linear = new.unwrap;
let x = randn.unwrap;
let y = linear.forward.unwrap;
let norm = new.unwrap;
let z = norm.forward.unwrap;
API
All modules implement the Module trait from zyx-derive, which provides:
forward(x: impl Into<Tensor>) -> Result<Tensor, ZyxError>— Forward pass
Autograd
zyx uses GradientTape for automatic differentiation. The tape must be created before the forward pass to capture the computation graph.
use ;
use Linear;
let mut linear = new.unwrap;
let x = randn.unwrap;
let target = randn.unwrap;
// Create gradient tape BEFORE forward pass
let tape = new;
let y = linear.forward.unwrap;
let loss = y.mse_loss?;
// Compute gradients w.r.t. model parameters
let grads = tape.gradient;
# Ok::
Features
py— Enable Python bindings via pyo3
Documentation
License
LGPL-3.0-only