Repository navigation
[AutoSP] Align cross entropy targets after an in-model causal label shift - #8811
Conversation
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 6f7c57b9a6
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
6f7c57b to
b166cd8
Compare
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 496a3dbaeb
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 3372a81487
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
tohtana
left a comment
There was a problem hiding this comment.
Hi @jinyouzhi,
Could you address comments from Codex bot? I don't see any other issues. Some P2s seem important to me. If you think we could ignore, please let me know.
3372a81 to
b686c90
Compare
…odel label shift Keep the labels whole on every rank so that any shift the model applies to them, such as the Hugging Face F.pad(labels, (0, 1), value=-100)[..., 1:], runs on the full sequence. For each cross entropy on the labels, remove static sequence slices between the sharded logits and the loss (e.g. logits[..., :-1, :]), pad the full target to the global positions those slices covered, and hand the loss this rank's shard of the padded target. Only rank-preserving casts, reshapes after the slices, and static sequence slices are allowed between the logits and the cross entropy, and the labels may only flow into cross entropy targets. Any other pattern raises instead of silently pairing logits with the wrong targets. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Reject AutoSP without DeepCompile, read the boolean ZeRO config form, give the ranks of an SP group the same samples from the generated dataloader, reject reordered or explicitly resized sliced logits, give each cross entropy its own copy of a shared target transform, pad wide shifts without narrowing the target, and keep FP64 loss sums in FP64. Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
Signed-off-by: Jin, Youzhi <youzhi.jin@intel.com>
tohtana
left a comment
There was a problem hiding this comment.
Thank you for addressing all the comments! This looks good now.
Thank you for your reviewing, Could you trigger the CI workflow if no other todo. Thanks |
Addresses #8457 (comment) (in-model causal label shift under AutoSP).
Problem
AutoSP shards the labels the same way as
input_ids. A causal LM that shifts its labels inside the model (Hugging FaceForCausalLMLosspads and shifts,labels = F.pad(labels, (0, 1), value=-100)[..., 1:]; Megatron-style code sliceslogits[..., :-1, :]/labels[..., 1:]) then shifts each shard on its own. Each rank pairs the last token of its shard with the wrong target, and the loss is silently wrong. #8457 documents pre-shifted labels as the workaround; this PR makes the in-model shift itself correct.Approach
F.cross_entropywhose target derives from the labels:logits[..., :-1, :]) are removed, because each rank must keep its whole shard of logits. Their offsets give the window[start, S + stop)of global positions the CE input covered.ignore_indexback to the global positions of that window, then hand the CE this rank's shard[r*S/sp, (r+1)*S/sp). This needs no communication because the labels are replicated.S + stop - start.torch.catof shifted logits slices may go undetected; the docs say so):contiguous,view/reshape/flatten(after any slices) and static sequence slices are allowed between the logits and the CE.input_ids, or returned from the module.narrow+full_like+catinstead ofF.pad/constant_pad_nd, which specialize the symbolic sequence length during fake-tensor propagation.Validation (8× Intel Arc Pro B70, torch 2.14.0.dev+xpu)
TestAutoSPCausalLosscompares the loss and the parameters after two optimizer steps against single-device training on the full sequence, over 4 ranks (sp=2, dp=2). New cases:slice(logits[..., :-1, :]/labels[..., 1:])pad(HF style)sum/mean, an explicit mesh, and an empty shardtest_rejects_labels_it_cannot_aligncovers a strided logits slice and labels masked byinput_ids.test_compile_autosp.py: 45 sequential and 20 non-sequential tests pass.TestAutoSPCompileandTestAutoSPEngineBackwardwere excluded because they fail on this machine for environmental reasons (dynamo tracing ofsynchronize(); the XPU C++20 op build, fixed in Use C++20 for XPU op builders on torch 2.12+ #8803), identically on the base branch.Tiny HF
LlamaForCausalLM(transformers 5.17), unshiftedlabels, sp=2, also checked withdynamic=True+attention_mask:Notes
shift_labels) remain supported and are still the simplest path.Contribution checklist
Related work. This PR is stacked on #8457 and addresses its review thread linked above. A search for "AutoSP label shift" found no other PR.
Sibling paths checked. AutoSP exists only as a DeepCompile pass, so there is no eager variant to fix. #8457 rejects ZeRO-2/3, and the label-shift handling here inherits that restriction.
Commands and results. Hardware and software: 4× Intel Arc Pro B70 (XPU, XCCL), Level Zero driver 1.15.39122 (compute runtime 26.27.39122.11), torch 2.14.0.dev20260804+xpu, transformers 5.17.0.
Results are listed under Validation above.
Numerics, performance, memory.
[B, S]integer ids per rank, negligible next to the logits.Compatibility matrix.
TestAutoSPCompilewas excluded, see above)AI assistance. This PR was developed with AI assistance (GitHub Copilot CLI). I reviewed every changed line and ran the tests above.