Refactor Mamba2 to use standardized output tracing#44087
Open
huyxdang wants to merge 2 commits intohuggingface:mainfrom
Open
Refactor Mamba2 to use standardized output tracing#44087huyxdang wants to merge 2 commits intohuggingface:mainfrom
huyxdang wants to merge 2 commits intohuggingface:mainfrom
Conversation
Migrate Mamba2Model and Mamba2ForCausalLM to use the PreTrainedModel output tracing decorators (@capture_outputs and @can_return_tuple). This removes manual boilerplate for collecting hidden states and packing return tuples, aligning the implementation with the library standard. Also fix a crash in hub_kernels.py where integer version numbers in the kernel mapping caused a TypeError during loading. Fixes huggingface#43979
Contributor
|
[For maintainers] Suggested jobs to run (before merge) run-slow: mamba2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Refactors the Mamba2 model to use the standardized output collection interface as part of #43979.
Changes
_can_record_outputstoMamba2PreTrainedModelmappinghidden_states→Mamba2Block.@capture_outputsand@merge_with_config_defaultsdecorators toMamba2Model.forward.@can_return_tupledecorator toMamba2ForCausalLM.forwardto handle automated tuple/dict packaging.output_hidden_statesandreturn_dictparameter resolution and manual collection loops in bothMamba2ModelandMamba2ForCausalLM.Mamba2Block.forwardto returnhidden_statesdirectly as a single tensor.TypeErrorinsrc/transformers/integrations/hub_kernels.pywhere integer version numbers in the kernel mapping caused a crash during loading.Technical Context
Unlike traditional Transformer models which utilize attention mechanisms, Mamba2 is a State Space Model (SSM). It doesn't generate attention weights and thus the refractor focuses only on capturing
hidden_states.