Transformer & LoRA
SwiGLU & FeedForward
Transformer MLP blocks implementing SwiGLU and standard GELU FeedForward networks in Rust.
ochreml.nn provides both the gated SwiGLU feed-forward block used in LLaMA-style LLMs (down(silu(gate(x)) * up(x))) and the standard Transformer FeedForward block (fc2(gelu(fc1(x)))).
Import & Signatures
import ochreml.nn as nn
swiglu = nn.SwiGLU(
d_model,
hidden_dim,
bias=False,
dtype="float32",
device=None,
seed=42,
)
ffn = nn.FeedForward(
d_model,
d_ff,
bias=True,
dtype="float32",
device=None,
seed=42,
)Parameters
| Class | Parameter | Type | Default | Description |
|---|---|---|---|---|
SwiGLU | d_model, hidden_dim | int, int | required | Input/output width and gated intermediate width. |
SwiGLU | bias | bool | False | Include bias terms in gate, up, and down projections. |
FeedForward | d_model, d_ff | int, int | required | Input/output width and inner GELU projection width. |
FeedForward | bias | bool | True | Include bias terms in fc1 and fc2. |
Usage Example
import ochreml.nn as nn
x = nn.Tensor.randn([2, 16, 64])
y_swiglu = nn.SwiGLU(d_model=64, hidden_dim=192)(x)
y_ffn = nn.FeedForward(d_model=64, d_ff=256)(x)