← Back to Pull requests

Fix checkpoint and broadcast tests to use the accelerator backend #9054

Closed
unknown closed this pull request without merging on Nov 15, 2026 16:14 UTC
View on GitHub
unknown unknown commented on Nov 11, 2026 08:42 UTC
Author

Summary

While preparing the Ascend NPU runner for upstream DeepSpeed CI, we are working through the upstream tests/unit suite and fixing device-specific failures group by group. This PR covers the gloo group.

Four test files hard-code the gloo backend while DeepSpeed places the model on the active accelerator. Gloo has no transport for NPU tensors, so _broadcast_model() fails before the test body runs:

RuntimeError: No backend type associated with device type npu

The tests now use the accelerator's communication backend. No engine or runtime code changes.

Problem

On an Ascend host, deepspeed.initialize() selects the NPU device, but these tests explicitly initialize gloo:

  • deepspeed.init_distributed(dist_backend="gloo", ...)

  • backend = "gloo" on DistributedTest subclasses
  • The model parameters are therefore NPU tensors while the process group is gloo. The first model broadcast fails in [engine._broadcast_model]:

    deepspeed/runtime/engine.py  _broadcast_model
      -> deepspeed.comm.broadcast
      -> RuntimeError: No backend type associated with device type npu
    

    In the NPU CI run of the upstream suite this accounts for 11 cases across the misc and runtime shards: 8 failures + 3 setup errors (the 3 errors come from the module-scoped, 2-process checkpoint fixture in test_fp32_master_only.py).

    The tests were written as CPU/gloo tests, but they do not force the CPU accelerator. On an accelerator host, DeepSpeed uses the accelerator device; the backend must match it.

    Fix

  • Remove the hard-coded gloo backend from the four test files and use the accelerator's communication backend (get_accelerator().communication_backend_name(): CPU → gloo, NPU → hccl, CUDA → nccl).

  • In test_fp32_master_only.py, select the device before init_distributed() and skip the 2-process fixture when the accelerator has fewer than 2 devices (CPU is unaffected).

  • In TestRealCheckpointUniversalConversionTPxPP, keep the existing CPU path (gloo + forkserver daemonic processes); on accelerators, use the standard DistributedTest launcher, which skips when fewer than 4 devices are available.
  • On CPU the tests still use gloo and the original execution path, so existing CPU coverage is unchanged.

    Files changed

    | File | Why it changes | Diff |
    |---|---|---|
    | tests/unit/checkpoint/test_autotp_uc_checkpoint.py | The 4-rank TPxPP test hard-codes gloo while the engine places parameters on the accelerator. Use the accelerator backend; keep the CPU/forkserver path; use the standard launcher on accelerators and skip when fewer than 4 devices are present. | +16/-11 |
    | tests/unit/checkpoint/test_fp32_master_only.py | Direct init_distributed(dist_backend="gloo") and a gloo DistributedTest put NPU tensors on a gloo group. Select the device before init, use the accelerator backend, and skip the 2-process fixture when fewer than 2 accelerator devices are available. | +9/-2 |
    | tests/unit/checkpoint/test_fp32_master_stage3_bf16.py | Drop the hard-coded gloo backend; the parameters live on the accelerator. | +2/-1 |
    | tests/unit/runtime/test_scalar_parameter_broadcast.py | Drop the hard-coded gloo backend; the scalar parameter lives on the accelerator and is broadcast during engine init. | +2/-1 |

    Testing

    Environment

  • NPU: 4×Ascend 910B4, CANN 8.5.1, torch 2.10.0+cpu, torch_npu 2.10.0.post7+git51c843b

  • CUDA: 4×A100-SXM4-80GB (GPUs 3/4/6/7), torch 2.14.1+cu126

  • CPU: same host, DS_ACCELERATOR=cpu, torch 2.10.0+cpu
  • NPU

    cd tests/unit
    PYTHONPATH=$(git rev-parse --show-toplevel) HCCL_NPU_SOCKET_PORT_RANGE=auto \
    python -m pytest -q --forked \
      checkpoint/test_fp32_master_stage3_bf16.py \
      checkpoint/test_fp32_master_only.py \
      runtime/test_scalar_parameter_broadcast.py \
      checkpoint/test_autotp_uc_checkpoint.py::TestRealCheckpointUniversalConversionTPxPP::test
    

    Result: 13 passed (about 5 minutes). The 13 include all 11 previously failing cases plus the other tests in the same files.

    CUDA/A100

    The four files were also run in full on 4×A100-SXM4-80GB:

    cd tests/unit
    CUDA_VISIBLE_DEVICES=3,4,6,7 \
    /home/tangzizhao/miniconda3/envs/cuda/bin/python -m pytest --forked -q \
      checkpoint/test_autotp_uc_checkpoint.py \
      checkpoint/test_fp32_master_only.py \
      checkpoint/test_fp32_master_stage3_bf16.py \
      runtime/test_scalar_parameter_broadcast.py
    

    | Test file | Result | Time |
    |---|---:|---:|
    | tests/unit/checkpoint/test_autotp_uc_checkpoint.py | 45 passed | 195.20s |
    | tests/unit/checkpoint/test_fp32_master_only.py | 8 passed | 69.52s |
    | tests/unit/checkpoint/test_fp32_master_stage3_bf16.py | 2 passed | 58.89s (combined with scalar) |
    | tests/unit/runtime/test_scalar_parameter_broadcast.py | 2 passed | same run |
    | Total | 57 passed, 0 failed | |

    TestRealCheckpointUniversalConversionTPxPP (4 ranks, TP=2×PP=2) ran separately in 13.15s and passed, confirming it used the accelerator launcher and NCCL rather than the CPU/gloo path. The directly spawned fixture in test_fp32_master_only.py also completed NCCL initialization on GPU (8/8).

    Pure CPU

    cd tests/unit
    DS_ACCELERATOR=cpu LOCAL_SIZE=4 \
    PYTHONPATH=$(git rev-parse --show-toplevel) \
    python -m pytest -q --forked \
      checkpoint/test_fp32_master_stage3_bf16.py \
      checkpoint/test_fp32_master_only.py \
      runtime/test_scalar_parameter_broadcast.py \
      checkpoint/test_autotp_uc_checkpoint.py::TestRealCheckpointUniversalConversionTPxPP::test
    

    Result: 13 passed (about 4m36s).

    LOCAL_SIZE=4 is needed because the CPU accelerator derives device_count() from the NUMA topology and reports 1 on this host; the 2-rank and 4-rank cases would otherwise be skipped by the existing device-count guard.

    CPU/gloo path

    The preserved CPU/gloo path was also checked without LOCAL_SIZE=4:

  • TestRealCheckpointUniversalConversionTPxPP ran 4 ranks on CPU/gloo and passed in 54.32s, confirming that the CPU/forkserver path is unchanged.

  • test_scalar_parameter_broadcast is skipped on this host because CPU device_count() is 1, below the 2 ranks the test needs. This is the existing DistributedTest launcher gate, not a regression from this change; with LOCAL_SIZE=4 the test runs and passes as part of the 13-passed run above.
  • Before / after

    | Check | master | this branch |
    |---|---|---|
    | Affected 11 cases, 4×910B4 | 8 failed + 3 setup errors, No backend type associated with device type npu | 13 passed in the same files |
    | Four affected files, 4×A100-SXM4-80GB | not run | 57 passed |
    | Same tests, pure CPU | not run | 13 passed |

    Not tested

  • The full tests/unit suite; only the four affected files/test cases were run.

  • Other accelerators (ROCm, XPU, HPU, etc.).
  • Notes for review

  • This is a test-side fix. engine._broadcast_model() already broadcasts on the accelerator device, so the process-group backend must match that device; changing the engine would hide the mismatch rather than fix it.

  • The tests still run on CPU with gloo; the accelerator path is additive and skips when the required device count is unavailable.

  • No production code, config, checkpoint, or public API changes.

  • No upstream issue is linked; this was found while bringing the upstream unit-test suite up on the Ascend NPU runner.

  • AI assistance: the change was drafted with Claude Code; the author reviewed the diff and ran the NPU, CPU, and CUDA/A100 validation above.
  • Checklist

  • NPU validation (4×910B4)

  • CPU validation

  • CUDA validation (4×A100-SXM4-80GB)

  • pre-commit (YAPF and all other hooks pass; the local flake8 hook fails with a pyflakes/ast.Str incompatibility unrelated to this diff)
  • Diff: 650 lines (+487 / -163) across 8 files Reviewer: delock Review duration: 6212m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    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.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #9054"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 52% (MEDIUM) · Higher = larger blast radius
    52%
    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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 20.5% · Safe to merge
    20.5%