Add L2NormHook and use it in megatron.py#599
Merged
danielkorzekwa merged 19 commits intofeature/compressfrom Nov 26, 2025
Merged
Add L2NormHook and use it in megatron.py#599danielkorzekwa merged 19 commits intofeature/compressfrom
danielkorzekwa merged 19 commits intofeature/compressfrom
Conversation
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## feature/compress #599 +/- ##
=================================================
Coverage 74.37% 74.37%
=================================================
Files 182 182
Lines 18219 18219
=================================================
Hits 13550 13550
Misses 4669 4669 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
AAnoosheh
reviewed
Nov 24, 2025
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
AAnoosheh
approved these changes
Nov 25, 2025
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.com>
| max_size = num_heads_per_group_max * num_query_groups_max * self.config.kv_channels | ||
| activation_hook = L2NormHook(max_size=max_size) | ||
| self._register_temp_attribute("_activation_hook", activation_hook) | ||
| # TODO: confusion: why hook_handle is removed manually in export() and not using _register_temp_attribute? |
Collaborator
There was a problem hiding this comment.
even if we register hook_handle as temp attribute, we still need to call hook_handle.remove() to remove the hook so there's no change. Temp attribute will be remove from model i.e. self.hook_handle reference will be dropped but that still doesnt remove the actuall pytorch hook added to the forward
Contributor
Author
There was a problem hiding this comment.
I understand now.
Co-authored-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Signed-off-by: Daniel Korzekwa <daniel.korzekwa@gmail.com>
Co-authored-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Signed-off-by: Daniel Korzekwa <daniel.korzekwa@gmail.com>
Co-authored-by: Keval Morabia <28916987+kevalmorabia97@users.noreply.github.com> Signed-off-by: Daniel Korzekwa <daniel.korzekwa@gmail.com>
Signed-off-by: Daniel Korzekwa <dkorzekwa@nvidia.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?
This is the first step towards reusing activation scores logic across Minitron and Puzzle. Next steps:
Questions: