fix: forward padding_mask through MTP recompute path#4983
Closed
ko3n1g wants to merge 1 commit into
Closed
Conversation
MultiTokenPredictionLayer.forward calls self._checkpointed_forward(
padding_mask=padding_mask, ...) (multi_token_prediction.py:1305), but
_checkpointed_forward and its inner custom_forward never accepted
padding_mask. With recompute_granularity == 'full' and self.training,
this raised:
TypeError: MultiTokenPredictionLayer._checkpointed_forward() got
an unexpected keyword argument 'padding_mask'
at multi_token_prediction.py:1301. The kwarg was introduced in NVIDIA#2645
on the call site; the _checkpointed_forward refactor in NVIDIA#4593 dropped
padding_mask from the recompute path.
Add padding_mask:
* to _checkpointed_forward's signature
* to custom_forward's signature so it flows into _proj_and_transformer_layer
* positionally to te_checkpoint and tensor_parallel.checkpoint, matching the
other tensor / None args (padding_mask is a rolled tensor, not a non-tensor
closure-captured arg like attention_bias)
* to the recompute_method == 'block' fallback that also calls
_proj_and_transformer_layer directly
Also remove the @pytest.mark.flaky_in_dev markers from
test_forward_backward, test_fp8_support, and test_packed_sequences_with_full_recompute,
which were added in NVIDIA#4931 to mask this exact failure.
Closes NVIDIA#4933
Signed-off-by: oliver könig <okoenig@nvidia.com>
|
Auto-sync is disabled for draft pull requests in this repository. Workflows must be run manually. Contributors can view more details about this message here. |
Contributor
Author
|
/ok to test b216826 |
Contributor
Author
|
close in favor of #4963 |
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.
Claude summary
Fixes #4933.
Bug
MultiTokenPredictionLayer.forwardcallsself._checkpointed_forward(..., padding_mask=padding_mask, ...)atmegatron/core/transformer/multi_token_prediction.py:1305, but_checkpointed_forward(and its innercustom_forward) never acceptedpadding_mask. Withrecompute_granularity == 'full'andself.training, this raised:Two commits that don't compose:
2d1fa8d372([main] feat(moe): Support packed sequence for gated delta net (GDN) #2645, 2026-05-14) addedpadding_mask=padding_maskto the call site.2b77d32b1e(Fix MTP recompute crash with packed sequences #4593, 2026-05-21) refactored_checkpointed_forwardwithout apadding_maskparameter.The failure surfaced across
TestMultiTokenPrediction::test_forward_backward[*-*-True](9 combos),test_fp8_support[True], andtest_packed_sequences_with_full_recompute. It also broke three Megatron-FSDP nodes intest_compatible_with_nd_parallel.Fix
Forward
padding_maskthrough the recompute path:padding_mask: Optional[Tensor] = Noneto_checkpointed_forward's signature.padding_masktocustom_forward's signature so it reaches_proj_and_transformer_layer(which already accepts it).padding_maskpositionally to bothte_checkpointandtensor_parallel.checkpoint. It's a tensor (rolled in_get_embeddings), so it follows the same positional-arg pattern asattention_maskrather than being captured via closure like non-tensor args (attention_bias,inference_params,packed_seq_params).padding_maskin therecompute_method == 'block'fallback path which calls_proj_and_transformer_layerdirectly.Test cleanup
Removed
@pytest.mark.flaky_in_devfrom three tests that were marked in #4931 specifically to mask this failure:TestMultiTokenPrediction::test_forward_backwardTestMultiTokenPrediction::test_fp8_supportTestMultiTokenPrediction::test_packed_sequences_with_full_recomputeRepro