#37·mamba

Error during backprop when bias=True in Mamba block

Author: dwromeroCreated Dec 8, 2023Updated Sep 29, 2026

Hi Albert & Tri,

Awesome work! Thank you for sharing!

I noticed a bug when using bias=True in a Mamba block. For example, using:

layer = Mamba(
        # This module uses roughly 3 * expand * d_model^2 parameters
        d_model=512, # Model dimension d_model
        d_state=16,  # SSM state expansion factor
        d_conv=4,    # Local convolution width
        expand=2,    # Block expansion factor
    ).to("cuda")

works perfectly fine, but if I do:

layer = Mamba(
        # This module uses roughly 3 * expand * d_model^2 parameters
        d_model=512, # Model dimension d_model
        d_state=16,  # SSM state expansion factor
        d_conv=4,    # Local convolution width
        expand=2,    # Block expansion factor
       bias=True,
    ).to("cuda")

I get the error:

Traceback (most recent call last):
  File "/home/dromerog/Projects/meshgen/train.py", line 79, in <module>
    main()
  File "/home/dromerog/Projects/meshgen/train.py", line 71, in main
    trainer.train_loop()
  File "/home/dromerog/Projects/meshgen/meshgen/trainers/autoregressive_mamba.py", line 94, in train_loop
    loss['total'].backward()
  File "/home/dromerog/anaconda3/envs/meshgen/lib/python3.10/site-packages/torch/_tensor.py", line 492, in backward
    torch.autograd.backward(
  File "/home/dromerog/anaconda3/envs/meshgen/lib/python3.10/site-packages/torch/autograd/__init__.py", line 251, in backward
    Variable._execution_engine.run_backward(  # Calls into the C++ engine to run the backward pass
RuntimeError: Function MambaInnerFnBackward returned an invalid gradient at index 6 - got [] but expected shape compatible with [512]

Hopes this helps! :)

Best, David