fix(trainer): support selective logits with sequence parallel - #10039
Open
zjn20030811 wants to merge 1 commit into
Open
fix(trainer): support selective logits with sequence parallel#10039zjn20030811 wants to merge 1 commit into
zjn20030811 wants to merge 1 commit into
Conversation
zjn20030811
force-pushed
the
feat/sp-logits-to-keep
branch
from
September 4, 2026 06:45
5dd2d2d to
94c6759
Compare
Author
|
Validation update: the focused sequence-parallel suite covers masked rows, packed boundaries, gradient/loss equivalence, all-ignored shards, accuracy reconstruction, and the non-SFT capability guard. The branch is ready for review. |
| # SP keeps a local boolean mask while position_ids still contains | ||
| # the complete packed sequence. Gather the mask first so compact | ||
| # boundaries are computed in the global frame. | ||
| if (getattr(getattr(self, 'template', None), 'sequence_parallel_size', 1) > 1 and logits_to_keep.ndim == 1 |
Collaborator
There was a problem hiding this comment.
When will this code be used?
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 #9765 by enabling
use_logits_to_keepwith sequence parallel SFT.GatherLoss, preserving SP/ring ordering and normalization;Validation
py -3.12 -m pytest -q tests/test_align/test_sp_logits_to_keep.py tests/test_align/test_rlhf_loss.pypy -3.12 -m pre_commit run --files swift/trainers/mixin.py swift/trainers/seq2seq_trainer.py swift/trainers/utils.py tests/test_align/test_sp_logits_to_keep.pypy -3.12 -m compileall -q swift/trainers tests/test_align/test_sp_logits_to_keep.pyThe focused regression suite covers single-row masks, batched suffix selection, loss/gradient equivalence, all-ignored local shards, packed sequence boundaries, accuracy reconstruction, and the non-SFT capability guard.