fix(autotp): broadcast CPU copies in the TP input consistency check #9179
<!-- codex-pull-request-review-summary -->
<!-- codex-review-state:v1 {"code_review":{"commit_sha":"3d4d6385c0dd51ef864a125d9a1d3a6bfc6cb364","has_any_findings":false,"has_unresolved_findings":false,"status":"completed"},"security_review":{"commit_sha":null,"has_any_findings":null,"has_unresolved_findings":null,"status":null}} -->
<details>
<summary><strong>Codex Review Summary</strong>: ✅ Completed</summary>
This comment shows the latest Codex review activity on this pull request.
| Review | Status | Commit | Review trigger |
| --- | --- | --- | --- |
| 📝 Code Review | ✅ Completed <relative-time datetime="2026-11-27T09:19:19.302834Z">2026-11-27T09:19:19.302834Z</relative-time> | 3d4d638 | PR opened |
<details> <summary>ℹ️ About Codex in GitHub</summary>
<br/>
Your 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.
</details>
</details>
DeepSpeedStaticCache is a pytree leaf, so an initialized cache passed as past_key_values still sends its device-resident keys, values, and write position unchanged. Unpickling those tensors recreates the sender-device allocation and possible hang this change is meant to avoid. Replace cache leaves with tensor-free type descriptors in the check-only representation, preserving the same-type comparison and original forward inputs.
The existing TestTpDataloaderCorrectness checks only matching/mismatching positional tensor values, so it passes with the original sender-device deserialization bug as well. Please extend that distributed integration test to cover keyword tensors and assert that the received tensor payloads are CPU-resident, while the model still receives its original local-device inputs. This would catch removal or bypass of the conversion rather than merely rechecking equality.
<!-- ccr-overview-v2 -->
🟡 Changes recommended
Cache leaves still transmit device-resident tensors, preserving the allocation and hang risk, and distributed tests do not verify CPU-resident keyword payloads or preservation of original model inputs.
<details open>
<summary><strong>2 open issues</strong></summary>
</details>
<details>
<summary><strong>What changed in this PR</strong></summary>
This PR updates AutoTP’s one-time input consistency check to broadcast CPU tensor copies, avoiding restoration onto the sender’s accelerator device on other ranks.
Changes:
| File | Description |
| ---- | ----------- |
| deepspeed/runtime/utils.py | Aligns remote tensors with the local tensor’s device for comparison. |
| deepspeed/runtime/engine.py | Creates CPU tensor copies for the TP input-check broadcast. |
</details>
<sub>Review effort: Balanced</sub>
Hi @GuCarpenter , can you take a look at codex comments? Thanks!
@GuCarpenter please fix formatting. Also for new fixes, stack new commits instead of forced push to minimize review amount.
@delock Sorry, I'd follow next time. I have included cache in new commit. Please check it. Thx.
Approved these changes.
Approved these changes.
delock
GuCarpenter
The one-off check that validates the dataloader inputs are identical across tensor-parallel ranks broadcast the inputs as-is, including device-resident tensors. A pickled device tensor keeps the device index of the sender process, so every other rank restored it onto the sender's device: one extra cross-device copy per tensor, which is a waste and can even cause deadlock on some accelerators.
Send CPU copies instead, and compare each pair on the device the local side lives on, so the check needs no device copy at all.