TorchLean API

NN.API.Models.Mamba

Mamba Models #

Configuration and a language-model constructor for selective Mamba-1 sequence models.

The recurrent core uses causal depthwise convolution, input-dependent time steps and B/C vectors, learned negative state rates, and a gated readout. It is built from generic differentiable operations shared by CPU and CUDA execution.

Configuration for the trainable one-hot-token Mamba language model.

  • vocabularySize :

    Number of token categories accepted and predicted at each sequence position.

  • modelWidth :

    Output feature width of the Mamba block, before the vocabulary projection.

  • expansion :

    Expanded channels per model feature in the convolution and recurrent path.

  • stateWidth :

    Diagonal recurrent states per expanded channel.

  • kernelWidth :

    Newest-first taps in the causal depthwise convolution.

Instances For

    Internal Mamba dimensions passed unchanged to the trainable layer.

    Instances For

      Validate model dimensions before allocating recurrent or projection parameters.

      Instances For
        @[reducible, inline]
        abbrev TorchLean.nn.models.Mamba.Config.inputShape (config : Config) (sequenceLength : ) (batchShape : Shape := []) :

        One-hot input shape batchShape × sequenceLength × vocabularySize.

        Instances For
          @[reducible, inline]
          abbrev TorchLean.nn.models.Mamba.Config.outputShape (config : Config) (sequenceLength : ) (batchShape : Shape := []) :

          Logit output shape batchShape × sequenceLength × vocabularySize.

          Instances For
            def TorchLean.nn.models.Mamba.languageModel (config : Config) (sequenceLength : ) (batchShape : Shape := []) :
            Builder (Sequential (config.inputShape sequenceLength batchShape) (config.outputShape sequenceLength batchShape))

            Trainable selective Mamba-1 language model over one-hot token inputs.

            The block maps each vocabularySize-wide token to modelWidth features, and a final affine map produces vocabulary logits at every position. Its internal width is expansion * modelWidth. Every sequence starts with zero hidden state and empty convolution history; each batch element has its own recurrence while sharing the eleven Mamba tensors and vocabulary projection.

            The time-step projection is a dense matrix, matching Models.SelectiveMambaBlockSpec. The usual low-rank Mamba checkpoint stores two factors instead; their product matches a forward map here, but training a dense matrix gives a different parameterization. Model.Mamba.runArray exposes explicit state and convolution history for streaming computations.

            Instances For