ferrotorch-nn
Neural network modules for ferrotorch — layers, losses, hooks, and parameter management.
What it provides
Module<T>trait —forward,parameters/parameters_mut,train/eval,state_dict/load_state_dict#[derive(Module)]proc macro — annotate fields with#[param],#[submodule],#[skip]and parameter collection + train/eval propagation are generated for you
Layers
| Category | Modules |
|---|---|
| Linear | Linear, LazyLinear, Bilinear, LoRALinear |
| Convolution | Conv1d, Conv2d, Conv3d, ConvTranspose1d/2d/3d |
| Pooling | MaxPool1d/2d/3d, AvgPool1d/2d/3d, AdaptiveAvgPool1d/2d/3d, AdaptiveMaxPool* |
| Normalization | BatchNorm1d/2d/3d, LayerNorm, GroupNorm, RMSNorm, InstanceNorm*, LocalResponseNorm |
| Activation | ReLU, LeakyReLU, PReLU, ELU, GELU, SiLU, Mish, Sigmoid, Tanh, Softmax, LogSoftmax, Softplus, Hardswish, Hardsigmoid |
| Recurrent | LSTM, LSTMCell, GRU, GRUCell, RNN, RNNCell |
| Transformer | MultiheadAttention, TransformerEncoderLayer, TransformerDecoderLayer, RotaryPositionEmbedding, KVCache, SwiGLU |
| Embedding | Embedding, EmbeddingBag |
| Dropout | Dropout, Dropout1d/2d/3d, AlphaDropout |
| Container | Sequential, ModuleList, ModuleDict |
| Utility | Flatten, Unflatten, Identity, PixelShuffle, PixelUnshuffle |
Losses
CrossEntropyLoss, NLLLoss, BCELoss, BCEWithLogitsLoss, MSELoss,
L1Loss, HuberLoss, SmoothL1Loss, KLDivLoss, CosineEmbeddingLoss,
MarginRankingLoss, TripletMarginLoss, HingeEmbeddingLoss,
MultiLabelMarginLoss, PoissonNLLLoss, GaussianNLLLoss,
CTCLoss.
Initialization
init::xavier_uniform_, init::xavier_normal_, init::kaiming_uniform_,
init::kaiming_normal_, init::orthogonal_, init::uniform_,
init::normal_, init::constant_, init::zeros_, init::ones_,
with NonLinearity enum for gain selection.
Hooks
ForwardHook, BackwardHook, ForwardPreHook, HookedModule for
inspection, debugging, and gradient surgery.
Quick start
use ;
use ;
let model: = new;
let x = randn?;
let out = model.forward?;
assert_eq!;
With #[derive(Module)]
use ;
Part of ferrotorch
This crate is one component of the ferrotorch workspace. See the workspace README for full documentation.
License
MIT OR Apache-2.0