← Back to Pull requests

fix(autotp): broadcast CPU copies in the TP input consistency check #9179

Open
GuCarpenter opened this pull request with 118 lines diff across 4 files
View on GitHub
GuCarpenter GuCarpenter commented on Nov 27, 2026 09:14 UTC
Author

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.

Diff: 118 lines (+113 / -5) across 4 files Reviewer: delock Review duration: 8072m
All Vouch review confidence checks passed
Residual risk 0.08 = Change Risk (0.36) × (1 − Review Confidence (0.79)). Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.36 · 118 lines diff across 4 files
0.36
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.68 · 5 substantive comment(s)
0.68
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 50%
79%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size diff_size
0.286
Real PR Conversation Timeline
10 items
chatgpt-codex-connector[bot] chatgpt-codex-connector[bot] commented on Nov 27, 2026 09:14 UTC
Bot

<!-- 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

  • Open a pull request for review

  • Mark a draft as ready

  • Comment "@codex review" or "@codex security review".
  • 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>

    Copilot Copilot commented on code on Nov 27, 2026 19:40 UTC
    Code Review
    deepspeed/runtime/engine.py:1
    @@ -1022,12 +1023,14 @@ def _configure_tensor_parallel_states(self, model):
     
             self.first_dataloader_check = None
     
    +        # Send CPU copies: a pickled device tensor is restored on the sender's device.
             def check_dataloader_inputs_same_across_ranks(module, args, kwargs):
     
                 def broadcast_and_check(args, bcast_rank, bcast_group):
                     if isinstance(args, tuple):
                         args = list(args)
                     if len(args) > 0:
    +                    args = tree_map_only(torch.Tensor, lambda t: t.detach().cpu(), args)

    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.

    Copilot Copilot commented on code on Nov 27, 2026 19:40 UTC
    Code Review
    deepspeed/runtime/engine.py:1
    @@ -1022,12 +1023,14 @@ def _configure_tensor_parallel_states(self, model):
     
             self.first_dataloader_check = None
     
    +        # Send CPU copies: a pickled device tensor is restored on the sender's device.
             def check_dataloader_inputs_same_across_ranks(module, args, kwargs):
     
                 def broadcast_and_check(args, bcast_rank, bcast_group):
                     if isinstance(args, tuple):
                         args = list(args)
                     if len(args) > 0:
    +                    args = tree_map_only(torch.Tensor, lambda t: t.detach().cpu(), args)

    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.

    copilot-pull-request-reviewer[bot] copilot-pull-request-reviewer[bot] commented on Nov 27, 2026 19:40 UTC
    Reviewer

    <!-- 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>

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/high-v2-light.png" alt="High severity" width="62" height="18" align="texttop"></picture> Replace cache leaves with tensor-free descriptors during device checks · New

  • <picture><source media="(prefers-color-scheme: dark)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-dark.svg"><source media="(prefers-color-scheme: light)" srcset="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.svg"><img src="https://github.githubassets.com/static/images/icons/copilot-code-review/medium-v2-light.png" alt="Medium severity" width="62" height="18" align="texttop"></picture> Test CPU-resident keyword payloads in distributed dataloader checks · New

  • </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:

  • Converts tensor leaves in positional and keyword inputs to detached CPU copies before broadcasting.

  • Updates list and dictionary comparisons to move only the remote tensor when devices differ.
  • | 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>

    delock delock commented on Nov 30, 2026 08:37 UTC
    Contributor

    Hi @GuCarpenter , can you take a look at codex comments? Thanks!

    delock delock commented on Dec 01, 2026 09:00 UTC
    Contributor

    @GuCarpenter please fix formatting. Also for new fixes, stack new commits instead of forced push to minimize review amount.

    GuCarpenter GuCarpenter commented on Dec 01, 2026 09:15 UTC
    Author

    @delock Sorry, I'd follow next time. I have included cache in new commit. Please check it. Thx.

    delock delock approved these changes on Dec 01, 2026 14:25 UTC
    Approved Reviewer

    Approved these changes.

    PKUWZP PKUWZP approved these changes on Dec 02, 2026 15:06 UTC
    Approved Reviewer

    Approved these changes.

    Reviewers
    Assignees
    GuCarpenter GuCarpenter
    Labels
    risk: low confidence: 79.1% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 36.0% (MEDIUM) · Higher = larger blast radius
    36.0%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 79.1% · Lower = rushed or shallow review
    79.1%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 7.5% · Safe to merge
    7.5%