Add.generate() function with KV cache support for Nemotron v3#1332
Draft
Add.generate() function with KV cache support for Nemotron v3#1332
.generate() function with KV cache support for Nemotron v3#1332Conversation
Adds GenerationMixin to NemotronHForCausalLM so the model exposes the standard HuggingFace .generate() API (greedy, beam search, sampling, etc.). Key changes: - Inherit from transformers.generation.GenerationMixin - Set _is_stateful=True to prevent DynamicCache creation (hybrid Mamba2/Attention architecture cannot use a standard KV cache) - Add device property required by GenerationMixin - Initialize self.generation_config in __init__ - Update forward() to return CausalLMOutputWithPast (logits, optional loss, past_key_values=None) and accept all standard CausalLM params (inputs_embeds, labels, use_cache, cache_position, position_ids, logits_to_keep) - Override prepare_inputs_for_generation() to pass the full accumulated sequence each step (no cache slicing; correct but O(n) per token) - Update tests to use output.logits instead of raw tensor return value - Add 7 new tests covering GenerationMixin integration and .generate() Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…orCausalLM Add NemotronHybridCache managing attention KV cache and Mamba2 conv/SSM state, enabling efficient autoregressive generation. Mamba2 mixer now supports three code paths: fused training, unfused prefill with cache init, and single-step decode with state update. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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.
What does this PR do ?
Add
.generate()function with KV cache support for Nemotron v3.Changelog
.generate()function with KV cache support for Nemotron v3Before your PR is "Ready for review"
Pre checks:
If you haven't finished some of the above items you can still open "Draft" PR.
Additional Information