feat: TP-aware KDLoss with distributed softmax and T² scaling#1499
Merged
feat: TP-aware KDLoss with distributed softmax and T² scaling#1499
Conversation
Add tensor-parallel support to KDLoss via two new module-level helpers: - _infer_tp_group_from_dtensor: extracts the TP ProcessGroup from a vocab-sharded DTensor logit, avoiding an explicit tp_group argument in most cases. - _kl_forward_tp: computes per-token KL using numerically stable global softmax/log-softmax over all_reduce, keeping logits on local shards to avoid gathering the full vocabulary. KDLoss.forward gains a tp_group parameter (default None, backward- compatible) and auto-detects a TP group from DTensor student_logits. T² loss scaling (Hinton et al., 2015) is applied when temperature != 1 so that gradient magnitudes stay independent of the chosen temperature. Tests extended with single-process gloo-backed fixtures that verify the TP path matches the non-TP path at world_size=1, plus dedicated tests for T² scaling and _infer_tp_group_from_dtensor. Signed-off-by: Sepehr Sameni <ssameni@nvidia.com>
Contributor
Author
|
@akoumpa for visibility |
3 tasks
Contributor
|
/ok to test 8ffe1e7 |
akoumpa
approved these changes
Mar 9, 2026
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.
Add tensor-parallel support to KDLoss via two new module-level helpers:
KDLoss.forward gains a tp_group parameter (default None, backward- compatible) and auto-detects a TP group from DTensor student_logits. T² loss scaling (Hinton et al., 2015) is applied when temperature != 1 so that gradient magnitudes stay independent of the chosen temperature.
Tests extended with single-process gloo-backed fixtures that verify the TP path matches the non-TP path at world_size=1, plus dedicated tests for T² scaling and _infer_tp_group_from_dtensor.