Python wrappers
Public Python APIs implemented by this engine symbols.- py
lucid.nn.Linearclass - py
lucid.nn.qat.Linearclass - py
lucid.nn.quantized.dynamic.Linearclass - py
lucid.nn.quantized.Linearclass - py
lucid.peft.tuners.adamss.Linearclass - py
lucid.peft.tuners.beft.Linearclass - py
lucid.peft.tuners.boft.Linearclass - py
lucid.peft.tuners.bone.Linearclass - py
lucid.peft.tuners.c3a.Linearclass - py
lucid.peft.tuners.deft.Linearclass - py
lucid.peft.tuners.delora.Linearclass - py
lucid.peft.tuners.fourierft.Linearclass - py
lucid.peft.tuners.frod.Linearclass - py
lucid.peft.tuners.glora.Linearclass - py
lucid.peft.tuners.gralora.Linearclass - py
lucid.peft.tuners.hira.Linearclass - py
lucid.peft.tuners.hra.Linearclass - py
lucid.peft.tuners.ia3.Linearclass - py
lucid.peft.tuners.lily.Linearclass - py
lucid.peft.tuners.loha.Linearclass - py
lucid.peft.tuners.lokr.Linearclass - py
lucid.peft.tuners.lora.Linearclass - py
lucid.peft.tuners.miss.Linearclass - py
lucid.peft.tuners.oft.Linearclass - py
lucid.peft.tuners.osf.Linearclass - py
lucid.peft.tuners.peanut.Linearclass - py
lucid.peft.tuners.poly.Linearclass - py
lucid.peft.tuners.psoft.Linearclass - py
lucid.peft.tuners.pvera.Linearclass - py
lucid.peft.tuners.randlora.Linearclass - py
lucid.peft.tuners.road.Linearclass - py
lucid.peft.tuners.shira.Linearclass - py
lucid.peft.tuners.supertuning.Linearclass - py
lucid.peft.tuners.tinylora.Linearclass - py
lucid.peft.tuners.trainable_tokens.Linearclass - py
lucid.peft.tuners.unilora.Linearclass - py
lucid.peft.tuners.vblora.Linearclass - py
lucid.peft.tuners.vera.Linearclass - py
lucid.peft.tuners.waveft.Linearclass - py
lucid.nn.functional.linearfunction
Autograd node for the linear (fully-connected) transformation .
Inherits FuncOp<LinearBackward, 3> which wires three saved-input
slots (x, W, b) and records each operand's shape so that
apply can reconstruct the three gradients during backward.
The forward dispatches to IBackend::linear (BNNS / Accelerate on
CPU, MLX on Metal); the backward delegates to
IBackend::linear_backward which returns {dx, dW, db} in one
fused call.
Attributes
schema_ v1OpSchema"linear", version 1, AmpPolicy::Promote). Promote means the op participates in autocast and its operands are cast to the current autocast target dtype — F16 on GPU and F32 on CPU per the Accelerate-no-F16 carve-out.Notes
The bias slot is mandatory at the C++ level. When the Python
Linear(bias=False) form is requested, the binding layer passes
a zero-length tensor (shape (0,)) and the GEMM contribution from
b evaluates to zero. Thread safety: instances are created once
during forward and consumed once during backward — no concurrent
access is expected.
Static methods
1Run the forward pass and, when grad mode is on, register this as the grad_fn of the returned output.
The forward flattens all leading dimensions of x into an
M-row batch (),
dispatches the GEMM through backend::Dispatcher, and
reports 2 * M * N * K FLOPs to the profiler scope. Under an
active AutocastGuard, the three operands are cast to the
effective dtype using astype_op (which preserves autograd)
before the kernel call so the matmul takes the native F16 fast
path on Metal.
Math
Shape
- Input
x: - Weight
W: - Bias
b: - Output :
Parameters
xTensorImplPtrK = in_features. Must be at least 1-D.WTensorImplPtr(N, K). Treated as at the math level: the kernel multiplies x by W^T.bTensorImplPtr(N,). Pass an empty 1-D tensor when the Python module is constructed with bias=False.Returns
TensorImplPtrOutput tensor of shape , matching x's leading dimensions with the last axis replaced by N = out_features.
Raises
ShapeMismatchW.shape[1] != x.last_dim or b.shape[0] != W.shape[0].DeviceMismatchx, W, and b do not all live on the same device.Methods
2Compute the three gradients from the incoming grad_out.
Delegates to IBackend::linear_backward which produces
, , and
in a single backend call using the
shapes recorded in input_shapes_. The closed-form is
Parameters
grad_ outStorageReturns
std::vector<Storage>Three-element vector {dx, dW, db} matching the saved-input ordering (x, W, b).
Same three gradients, built from ops instead of one fused backend call, so that each stays differentiable.
What apply returns are Storages, which carry no autograd
history — enough for one backward pass and nothing beyond it. Any
second derivative through a dense layer goes through here instead:
a gradient penalty, a meta-learning inner step, a Hessian-vector
product, or the divergence of a continuous flow's vector field.
Parameters
grad_ outconst TensorImplPtr&grad_fn.Returns
std::vector<TensorImplPtr>Three-element vector {dx, dW, db} in saved-input order.