Skip to content

torch_to_nnef.op.custom_extractors.mamba2

Mamba-2 selective state-space recurrence export.

HF's Mamba-2 mixers compute the SSD core either per token or by chunks of the sequence, with Python loops that unroll at the traced length. Calling :class:Mamba2RecurrentReified instead keeps the graph S-generic: the extractor emits one tract_transformers_mamba2_recurrent op, which runs the recurrence sequentially for any S.

Op contract (must match tract transformers/src/ops/mamba2_recurrent.rs): x [b, S, H, P] already scaled by dt b / c [b, S, G, N] head h reads group h // (H / G) log_decay [b, S, H] dt * A initial_state [b, H, P, N] -> y [b, S, H, P] (x dtype), final_state (initial_state dtype) The D skip connection and the z gate stay outside the op.

Classes:

Name Description
Mamba2RecurrentExtractor

Emit tract_transformers_mamba2_recurrent for the reified core.

Mamba2RecurrentReified

Mamba-2 recurrence, exported as one tract op (see module doc).

Mamba2RecurrentExtractor

Mamba2RecurrentExtractor()

Bases: ModuleInfoExtractor

Emit tract_transformers_mamba2_recurrent for the reified core.

Mamba2RecurrentReified

Bases: Module

Mamba-2 recurrence, exported as one tract op (see module doc).

The eager forward computes in f32 like the op. Its first statement uses the five inputs in signature order: b and c share a shape, so the extractor tells them apart by that order only.