Purpose
This repository is the official implementation and experiment collection for structured state space sequence models (S4) and related models (HiPPO, LSSL, SaShiMi, DSS, HTTYH, S4D, S4ND), mainly used for research and training in sequence modeling.
Main Capabilities
- Provides self-contained layer implementations of S4 and its variants (located in models/s4/), making it easy to integrate into external codebases.
- Includes efficient kernel operations: Cauchy and Vandermonde kernels, with support for automatically detecting and invoking optimized kernels (manually compiled kernels or via the pykeops library).
- Provides a complete training framework based on PyTorch-Lightning and the Hydra configuration system, supporting automatic download and loading of multiple datasets (MNIST, CIFAR, Speech Commands, etc.).
- Supports autoregressive generation, allowing generation via checkpoint paths or experiment paths using the generate.py script.
- Provides predefined configurations to reproduce the end-to-end experiments in the paper.
- Supports different optimizer hyperparameter settings, especially special handling of the optimizer parameters for the SSM kernel parameters (A, B, Delta).
Usage
Environment requirements are Python 3.9+ and PyTorch 1.10+ (tested up to 1.13.1), with other dependencies listed in requirements.txt. Installation example:
pip install -r requirements.txt
Basic training command:
python -m train
This will train an S4 model on the Permuted MNIST dataset, reaching about 90% accuracy in about 1-3 minutes. External usage example: example.py is a self-contained training script that, under default settings, reaches 88% accuracy on sequential CIFAR with an S4D model of about 200k parameters. Autoregressive generation:
- Option 1: Generate via a checkpoint path, for example:
python -m generate --ckpt_path=<path_to_checkpoint>
- Option 2: Generate via an experiment path, for example:
python -m generate experiment=<experiment_path> ckpt=<checkpoint_name>
For specific examples, refer to the language and audio generation examples in the repository.
Applicable Scenarios
Suitable for research in sequence modeling, including but not limited to time series analysis, language modeling, audio generation, etc.
Limitations
- A suitable GPU environment is required for training, and some efficient kernels require manual compilation or additional installation of pykeops.
- Some library versions may have compatibility issues, especially among torch/torchvision/torchaudio/torchtext.
- This repository is mainly intended for research purposes and does not provide information on commercial use or pricing.