Fix MTP recompute padding mask forwarding#4963
Open
BestJuly wants to merge 3 commits into
Open
Conversation
|
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
ko3n1g
approved these changes
May 26, 2026
Contributor
|
@BestJuly could you also re-enable the tests like I did here https://github.com/NVIDIA/Megatron-LM/pull/4983/changes#diff-aacc823c21e05a0581eda86d881c4ea79ca36e6339efc02e79e72764a8f8581b? |
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>
Contributor
|
/ok to test 4a8785b |
1 similar comment
Contributor
|
/ok to test 4a8785b |
Contributor
|
/ok to test c89ec01 |
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
Fixes #4933.
Validation
PYTHONPATH=.venv/lib/python3.12/site-packages:$PYTHONPATH /usr/bin/python3.12 -m torch.distributed.run --standalone --nproc-per-node 8 -m pytest -q --tb=short --capture=fd tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[1-1-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[1-2-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[1-4-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[2-1-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[2-2-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[2-4-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[4-1-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_forward_backward[4-2-True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_fp8_support[True] tests/unit_tests/transformer/test_multi_token_prediction.py::TestMultiTokenPrediction::test_packed_sequences_with_full_recomputePYTHONPATH=.venv/lib/python3.12/site-packages:$PYTHONPATH /usr/bin/python3.12 -m torch.distributed.run --standalone --nproc-per-node 8 -m pytest -q --tb=short --capture=fd tests/unit_tests/distributed/megatron_fsdp/test_mcore_fully_sharded_data_parallel.py::TestMegatronFSDPE2E::test_compatible_with_nd_parallel[optim_grads_params_double_buffer-TP2]PYTHONPATH=.venv/lib/python3.12/site-packages:$PYTHONPATH /usr/bin/python3.12 -m torch.distributed.run --standalone --nproc-per-node 8 -m pytest -q --tb=short --capture=fd tests/unit_tests/distributed/megatron_fsdp/test_mcore_fully_sharded_data_parallel.py::TestMegatronFSDPE2E::test_compatible_with_nd_parallel[optim_grads_params_double_buffer-EP2_ETP2] tests/unit_tests/distributed/megatron_fsdp/test_mcore_fully_sharded_data_parallel.py::TestMegatronFSDPE2E::test_compatible_with_nd_parallel[optim_grads_params_double_buffer-OUTER_DP2_EP2]Dev branch
Checked latest
origin/dev(56481b050) and this issue is not present there:megatron/core/transformer/multi_token_prediction.pycontains nopadding_maskusage, so there is no_checkpointed_forward/padding_masksignature mismatch to fix. No dev PR is needed.