Skip to Content
OchreML
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

ParameterTypeDefaultDescription
in_featuresintrequiredSize of each input sample (last dimension).
out_featuresintrequiredSize of each output sample.
biasboolTrueIf True, adds a learnable bias vector of shape (out_features,).
dtypestr"float32""float32", "bfloat16", or "float16".
devicestr | NoneNoneTarget device (None uses default device).
seedint42Deterministic weight initialization seed.

Attributes

  • weight: Parameter of shape (out_features, in_features)
  • bias: Parameter of shape (out_features,) or None

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)

On this page