[codex] Fix tensor-parallel label smoothing#5522
Open
ilml wants to merge 1 commit into
Open
Conversation
Signed-off-by: Tom Long <tolong@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.
Summary
Root cause
The label-smoothing path treated each rank's vocabulary partition size as the full vocabulary size and averaged log-probabilities only within the local shard. That made losses rank-dependent and subtracted
alpha / (partition_vocab_size - 1)from non-target gradients instead ofalpha / (global_vocab_size - 1).The path also took
log()after exponentiation and normalization. Large but finite logit gaps can underflow those probabilities to zero, producing an infinite smoothed loss.Impact
For
TP > 1withlabel_smoothing > 0, every training step could use incorrect loss values and gradients. The defaultlabel_smoothing=0path does not perform the new sum or collective and is unchanged.Validation
Passed locally:
python3 -m py_compile megatron/core/tensor_parallel/cross_entropy.py tests/unit_tests/tensor_parallel/test_cross_entropy.pygit diff --checkNot run locally:
uv run python -m torch.distributed.run --nproc-per-node 8 -m pytest -q tests/unit_tests/tensor_parallel/test_cross_entropy.py::test_vocab_parallel_cross_entropy_label_smoothingtools/autoformat.shblackFixes #737