Conversation
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
Freeze
QSAIndexerparameters after construction so they are excluded fromoptimizer groups and Megatron DDP gradient buckets.
Problem
All QSA selection paths run under
torch.no_grad()and produce discrete booleanmasks or integer token indices. There is currently no auxiliary QSA indexer loss,
so
index_qk_proj,q_layernorm, andk_layernormcannot receive gradients fromthe language-model loss.
Despite that, these parameters default to
requires_grad=True. Megatron DDP thenadds them to gradient buckets and installs backward hooks that never fire. With
overlapped gradient reduction enabled, the next
zero_grad_buffer()fails becausethe bucket ready count is incomplete.
A two-node reproduction reported exactly these missing parameters:
Fix
Call
self.requires_grad_(False)after allQSAIndexerparameters are created.This preserves checkpoint loading and forward selection while keeping the
forward-only parameters out of optimizer state and DDP gradient buckets.
This is preferable to synthesizing zero gradients or disabling
overlap_grad_reduce, because neither workaround changes the fact that thecurrent QSA indexer has no gradient path.
Tests
requires_grad=Falseandgrad is None.state_dict().