Skip to content
class

LSTM

extendsLSTM]
LSTM(shell: nn.Module)

int8-weight LSTM built from a float lucid.nn.LSTM.

A dynamically quantized recurrent layer: every recurrent weight matrix (weight_ih_l* / weight_hh_l*) is stored int8 (per-row symmetric) while the biases stay float. A float nn.LSTM shell, held outside the module registry so its float weights never enter the state_dict, is the actual compute engine — on each forward its weights are overwritten with the values dequantized from the int8 buffers, so only the int8 form is the persistent, device-tracked state. No calibration is required; the per-timestep activation quantization inside the cell is left to the real low-precision kernel. Build instances with lucid.quantization.quantize_dynamic, the recommended path for LSTM-heavy inference.

Parameters

The float LSTM whose configuration and cell arithmetic are reused; it holds the recurrent weights that from_float quantizes to int8.

Notes

The shell is stored via object.__setattr__ so it stays out of the module registry, keeping the serialized state limited to the int8 weight buffers, the per-row scales, and the float biases.

Used by 1

Class methods

1
cls

from_float

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

Quantize a float recurrent module's weights to int8 (no calibration).

mod must be the float type the layer runs — an nn.LSTM for LSTM, an nn.GRUCell for GRUCell.

Instance methods

2
fn

extra_repr

→strfrom _DynamicRecurrent
extra_repr()

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

fn

forward

→tuple[Tensor | PackedSequence, tuple[Tensor, Tensor]]
forward(input: Tensor | PackedSequence, hx: tuple[Tensor, Tensor] | None = None)

Inject dequantized weights into the shell and run it.

Packed input passes straight through — the shell is a real lucid.nn.LSTM, so it handles it.