Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Mamba Export Compatible with ONNX #36403

Open
AyoubMDL opened this issue Feb 25, 2025 · 2 comments
Open

Make Mamba Export Compatible with ONNX #36403

AyoubMDL opened this issue Feb 25, 2025 · 2 comments
Labels
Feature request Request for a new feature

Comments

@AyoubMDL
Copy link

Feature request

When exporting Mamba to ONNX while using the cache, an if-else statement prevents proper inference and alignment with the Hugging Face model. Specifically, the issue arises due to the condition at this line and the alternative execution path at this line.

A potential solution is to ignore the cache position and modify the update_conv_state method in Mamba’s cache. Instead of the current implementation at this line, always update the last position with the new state after the roll:

conv_state[:, :, [-1]] = new_conv_state.to(device=conv_state.device, dtype=conv_state.dtype)

This ensures that the else branch is always taken in Mamba’s forward pass, making the model exportable and inference-compatible. Notably, this approach is already used in Mamba2Cache, as seen in this implementation.

Would it be possible to align Mamba’s behavior with Mamba2Cache to support ONNX export properly?

Motivation

Mamba’s current conv state update prevents proper ONNX export due to an if-else condition that disrupts inference consistency.

Your contribution

Proposed a fix that updates the conv state without using the cache position.

@AyoubMDL AyoubMDL added the Feature request Request for a new feature label Feb 25, 2025
@Rocketknight1
Copy link
Member

cc @SunMarc @MekkCyber

@SunMarc
Copy link
Member

SunMarc commented Feb 26, 2025

cc @gante

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature request Request for a new feature
Projects
None yet
Development

No branches or pull requests

3 participants