Overview
LTV_LRNN is the abstract base class for all Linear Time-Varying (LTV) LRNN models in lrnnx. LTV models have time-varying dynamics where state transition matrices (A, B, C, etc.) can change at each timestep based on the input.
Key characteristics:
- Cannot use FFT-based convolution for training (since kernels vary per timestep)
- Support async/event-driven discretization with variable timesteps
- Must use scan for both training and inference
- More expressive than LTI models but computationally more expensive
Class Hierarchy
Import
Class Signature
Constructor
__init__
Discretization method to use. Can be one of:
"zoh": Zero-order hold discretization"bilinear": Bilinear transform discretization"dirac": Dirac delta discretization"async": Asynchronous/event-driven discretization"no_discretization": No discretization appliedNone: For models that handle discretization internally
Abstract Methods
forward
Input tensor of shape
(B, L, H) where:B= batch sizeL= sequence lengthH= hidden dimension
Timesteps for async/event-driven discretization, shape
(B, L). When provided, enables event-based processing where the time intervals between events may vary. If None, uniform timesteps are assumed. See Event-based State Space Models for more details.Lengths of sequences in the batch, shape
(B,). Required for variable-length sequences or bidirectional models.Cache containing states and pre-computed values for efficient autoregressive generation. If provided during inference, enables incremental processing. Use
allocate_inference_cache() to create.Output tensor of shape
(B, L, H), same shape as input.step
Input at current timestep, shape
(B, 1, H).Cache dictionary containing model states. This is the same format returned by
allocate_inference_cache(). The cache is updated in-place and also returned for convenience.Additional keyword arguments specific to the model implementation.
A tuple containing:
y: Output at current timestep, shape(B, 1, H)inference_cache: Updated cache dictionary
allocate_inference_cache
- Initial hidden state(s)
- Any auxiliary states (e.g., convolution state for Mamba)
- Metadata for tracking sequence position
The batch size for inference.
Maximum sequence length to support.
Data type for allocated tensors. If
None, uses the model’s default dtype.Additional model-specific arguments.
Cache dictionary that can be passed to
forward(). Should contain at minimum:- Model state tensors (e.g.,
"lrnn_state","conv_state") "seqlen_offset": Current position in the sequence
Example Usage
See Also
- Mamba - Selective State Space Model implementation
- RGLRU - Recurrent Gated Linear Recurrent Unit
- S7 - Selective and Simplified State Space Layer
- LRNN Base Class - Parent class for all LRNN models
