Layers & Activations
Activations
Stateless activation modules ReLU, Sigmoid, Tanh, GELU, and SiLU backed by N2 and N8 Rust kernels.
ochreml.nn provides five stateless activation Module wrappers usable inside Sequential or custom Module classes. Each activation is also available directly as a method on Tensor (e.g., x.gelu(), x.silu()).
Available Activations
| Module | Tensor Method | Formula / Behavior | Backend Primitive |
|---|---|---|---|
nn.ReLU() | x.relu() | max(0, x) | N2 |
nn.Sigmoid() | x.sigmoid() | 1 / (1 + exp(-x)) | N2 |
nn.Tanh() | x.tanh() | Hyperbolic tangent tanh(x) | N2 |
nn.GELU() | x.gelu() | Gaussian Error Linear Unit (standard Transformer FFN activation) | N8 |
nn.SiLU() | x.silu() | Sigmoid Linear Unit x * sigmoid(x) (Swish / SwiGLU activation) | N8 |
Usage Example
import ochreml.nn as nn
model = nn.Sequential(
nn.Linear(32, 64),
nn.GELU(),
nn.Linear(64, 64),
nn.SiLU(),
nn.Linear(64, 1),
nn.Sigmoid(),
)
x = nn.Tensor.randn([4, 32])
probs = model(x) # shape: (4, 1), values in (0, 1)