Layers & Activations
Linear
Fully connected affine projection y = x @ W^T + b backed by Rust GEMM kernels.
ochreml.nn.Linear applies a dense affine transformation y = x @ W^T + b over the last dimension of an input Tensor, dispatched via OchreML's E1/E2 GEMM backend (CPU AVX2+FMA+Rayon, CUDA/cuBLAS, wgpu, or TPU StableHLO).
Import & Signature
import ochreml.nn as nn
layer = nn.Linear(
in_features,
out_features,
bias=True,
dtype="float32",
device=None,
seed=42,
)Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
in_features | int | required | Size of each input sample (last dimension). |
out_features | int | required | Size of each output sample. |
bias | bool | True | If True, adds a learnable bias vector of shape (out_features,). |
dtype | str | "float32" | "float32", "bfloat16", or "float16". |
device | str | None | None | Target device (None uses default device). |
seed | int | 42 | Deterministic weight initialization seed. |
Attributes
weight:Parameterof shape(out_features, in_features)bias:Parameterof shape(out_features,)orNone
Usage Example
import ochreml.nn as nn
fc = nn.Linear(64, 10, bias=True)
x = nn.Tensor.randn([8, 64])
logits = fc(x) # shape: (8, 10)