Skip to content

Fix Nemotron-H SSM state with padded batches - #2100

Draft
Knightkolla wants to merge 1 commit into
ml-explore:mainfrom
Knightkolla:fix-nemotron-h-ssm-lengths
Draft

Knightkolla wants to merge 1 commit into
ml-explore:mainfrom
Knightkolla:fix-nemotron-h-ssm-lengths

Conversation

@Knightkolla

Copy link
Copy Markdown
Contributor

Nemotron-H was not passing cache.lengths to ssm_update which lead to wrong SSM states during batching of prompts of different lengths.

This PR makes ssm_update take cache.lengths into account, like Mamba2 and GraniteMoeHybrid do.

I added a regression test that checks equality of generation done with and without batching for prompts of lengths 12, 3, and 5.
The regression test fails in the main branch with maximum error 0.2163 but succeeds with this change under a 1e-4 threshold. Tests related to Nemotron-H, GraniteMoeHybrid, Mamba2, Mamba, and the prompt cache succeed. The test suite succeeds with MLX_ENABLE_TF32=0 as in main, while the new regression test also succeeds. If TF32 is enabled, then this new test fails at roughly 2e-3 on this machine similarly as other TF32-dependent tests do.
Closes #2099.

AI disclosure: AI assisted with the implementation and regression test.

  • ☑️ I understand it is strictly prohibited to use AI to write PR description
  • AI usage disclosure:

Signed-off-by: Kartikeya Dhavala <kartikeyadhavala2468@gmail.com>

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

nemotron_h: Incorrect outputs with left-padded batches

1 participant