Skip to content
class

Linear

extendsModule
Linear(in_features: int, out_features: int, bias: bool = True)

Implementing kernel

C++ engine symbols that back this Python API.

int8-weight linear with per-forward dynamic activation quantization.

Dynamic quantization keeps the weight permanently in int8 (per-output-channel symmetric) while the activation grid is derived from the live input on every forward — the input's min/max are measured, it is fake-quantized to a per-tensor affine grid, and the ordinary linear op then runs in float with the dequantized weight. Because no representative data is needed to fix the activation range, this layer needs no calibration pass, which makes it the standard choice for Transformer / Linear-heavy inference (BERT and friends). Instances are produced by lucid.quantization.quantize_dynamic, not constructed directly.

Parameters

in_featuresint
Size of each input sample — the weight's input dimension.
out_featuresint
Size of each output sample — the weight's output dimension.
biasbool= True
If True, keep a learned float bias buffer; otherwise no bias is added.

Notes

The weight lives in the weight_int8 buffer alongside per-channel weight_scale / weight_zero_point; only the int8 form is the persistent, device-tracked state, and the float weight is reconstructed on demand.

Used by 1

Constructors

1
dunder

__init__

→None
__init__(in_features: int, out_features: int, bias: bool = True)

Class methods

1
cls

from_float

→Linear
from_float(mod: nn.Module, dtype: QDtype = qint8)

Quantize a float lucid.nn.Linear's weight (no calibration).

Instance methods

2
fn

extra_repr

→str
extra_repr()

Override to add extra repr info (e.g. Linear shows in_features, etc.).

fn

forward

→Tensor
forward(x: Tensor)

Dynamically quantize the input, then run linear with the int8 weight.