Skip to content

selective_scan runs a Python for-loop instead of parallel associative scan - defeats the purpose of Mamba #1

Description

@eeshsaxena

In ssm.py, the selective_scan method runs a Python for-loop over the sequence length:

for t in range(length):
h = dA[:, :, :, t] * h + dB[:, :, :, t] * x[:, :, t:t+1]
...
outputs.append(y_t)

For a sequence of length 1024 with batch=8 and d_model=256, this is 1024 iterations of Python-level loop with tensor operations inside each step. It is extremely slow compared to what Mamba is supposed to be.

The whole point of the selective scan is that it should run as a parallel associative scan (like a prefix sum) not as a sequential recurrence. The parallel_scan function is exported in init.py but it is not used here. Either use it or document clearly that this is a reference/educational implementation and not performance-oriented.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions