Skip to content

Add a v1 multi-rank CPU suite (manual dispatch first) - #8926

Merged
delock merged 7 commits into
deepspeedai:masterfrom
delock:ci/cpu-v1-multirank
Oct 29, 2026
Merged

delock merged 7 commits into
deepspeedai:masterfrom
delock:ci/cpu-v1-multirank

Conversation

@delock

@delock delock commented Oct 27, 2026 •

Copy link
Copy Markdown
Collaborator

What

Adds cpu-torch-latest-v1-multirank, a CPU suite for the tests/unit/v1 multi-rank tests — the one gap left between the existing CPU workflows:

Workflow Covers
cpu-torch-latest all of unit/ at world_size == 1 (the device gate skips higher ranks)
cpu-torch-multi-latest (nightly) multi-rank for the non-v1 half + the sequential marker
cpu-torch-latest-v1-multirank (this PR) v1 multi-rank (world_size 2-4)

Mechanically it is the same recipe the nightly suite uses: LOCAL_SIZE=4 lets the per-device gate admit the multi-rank tests, and DS_MULTIRANK_ONLY=1 deselects everything else, so the job spends its time on v1 multi-rank tests only.

Selection

Test selection reuses the existing Modal diff-based picker (ci/tests_fetcher.py): the new WORKFLOWS entry scopes the suite to tests/unit/v1, so a PR only runs the v1 files it could affect. The collect-tests job writes ci/.test_selection/test_list.txt and the test job consumes it; mode=none skips the run entirely. No test lists are maintained by hand.

Rollout: manual dispatch first

The trigger is workflow_dispatch only, deliberately. This suite has never run in CI, and putting an unvalidated ~1 h suite in front of every pull request (or into branch protection) before it has a green run would block PRs. Once it is green across a few real PRs, pull_request: goes back into the on: block and the check can be registered.

Harness changes this suite needs (included here)

The v1 multi-rank tests rely on two fixes that used to live on the work-in-progress #8381 branch; they are part of this PR so the first run can be green:

  • tests/unit/v1/zero/test_zero_autocast.py: the DDP device_ids capability probe — without it, all 24 DDP autocast variants fail on CPU with ValueError: DistributedDataParallel device_ids and output_device arguments .... The fp16 parity variants are skipped when the accelerator reports no fp16 support (is_fp16_supported() false) rather than widening the tolerance, so no assertion is relaxed.
  • tests/unit/common.py: shm-segment key isolation/cleanup, JIT warm-up with stale-baton cleanup, per-rank faulthandler, and master-port uniquification — without them, concurrent pools share shm segments and can corrupt data or wedge.

Verified on CPU, 2 ranks: bf16 ZeRO-3 passes, fp16 variants skip when fp16 is unavailable, and no /dev/shm segments are left behind.

Validation

  • python3 ci/test_tests_fetcher.py: 27/27 (adds a registry test for the new WORKFLOWS entry)
  • ci/tests_fetcher.py --workflow cpu-torch-latest-v1-multirank: mode=all (-> tests/unit/v1) with no base, mode=none with no impacted tests; ci/torch_latest.py validate-selection passes
  • Both files pass pre-commit (yapf, flake8, yaml, license)

AI assistance

Prepared with AI assistance (DeepSeek Harness agent) under human review; the submitter has read every changed line.

Signed-off-by: Ma, Guokai [email protected]

tests/unit/v1 holds multi-rank cases that no current workflow executes on
CPU: cpu-torch-latest advertises one device and skips world_size > 1, and
the nightly cpu-torch-multi-latest covers multi-rank only for the non-v1
half plus the sequential marker. This adds cpu-torch-latest-v1-multirank: a
manual workflow that runs the v1 multi-rank tests with LOCAL_SIZE=4 and
DS_MULTIRANK_ONLY=1. It deliberately starts on workflow_dispatch only -
an unvalidated ~1h suite should not sit in front of every pull request;
once the run is green across a few real PRs, `pull_request:` goes back
into the trigger block and the check can be registered.

Selection reuses the Modal diff-based picker (ci/tests_fetcher.py), so a
PR only runs the v1 files it could affect, and the job spends its budget
on world_size 2-4 tests. The workflow registers a new WORKFLOWS entry
with the same v1 scope as modal-torch-latest, pre-builds the JIT ops and
pre-downloads bert-base-uncased the same way the other CPU suites do.

Verified: python3 ci/test_tests_fetcher.py passes (27/27, including a new
registry test); ci/tests_fetcher.py run with --workflow
cpu-torch-latest-v1-multirank produces mode=all -> tests/unit/v1 for an
empty base, mode=none with no impacted tests, and passes validate-selection;
both workflow files parse and pre-commit passes.

Signed-off-by: Ma, Guokai <[email protected]>
fi

case "$selected_preset" in
'2.10.0-cpu')

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there value in testing 2.10.*

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My concern is about maintaining multiple versions of fast-changing dependencies like transformers. As we are seeing transformers==5+ is not BC-friendly.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me remove 2.10 line. Agree that support one pytorch version is enough and will help reduce flakiness.

Multi-rank pools on one host share the shm all-reduce segments, whose
names are keyed by MASTER_PORT; every pool probing the same first-free
port meant concurrent pools could corrupt each other's collectives or
hang. Offset the port per process and per pool, remove the segments
once a pool is gone, and warm the JIT-built comm op before launching so
rank workers do not race torch's file-based build lock (which has no
stale-lock handling and deadlocks every later load after a killed
process). A per-rank faulthandler timer dumps the stack of a wedged
rank instead of letting it block its pool worker forever.

Signed-off-by: Ma, Guokai <[email protected]>
The autocast parity test asserts that the ZeRO engine and a DDP baseline
produce the same loss under autocast. On a CPU-only host the engine
reduces gradients in fp16 while the DDP baseline reduces in fp32, and
gloo round-trips the fp16 payload through fp32, so the two losses differ
by ulp-level noise that a GPU-style tolerance would hide without
validating anything. Skip the fp16 variants when the accelerator reports
no fp16 support instead of relaxing the assertion; bf16 and fp32 keep
the default tolerance.

The DDP baseline also passed device_ids/output_device unconditionally,
which the accelerators that map every rank onto one shared device
(cpu, hpu) reject. Probe whether the accelerator exposes per-device
handles instead of naming the device type.

Verified on CPU with 2 ranks: bf16 ZeRO-3 and fp16 ZeRO-0/3 variants
pass, and the fp16 variants skip when fp16 is unavailable.

Signed-off-by: Ma, Guokai <[email protected]>
@delock
delock marked this pull request as ready for review October 28, 2026 02:02
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 28, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-28T02:12:05.221203Z fd9402c Draft marked ready
ℹ️ About Codex in GitHub

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.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: fd9402cda2

ℹ️ 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".

Comment thread tests/unit/common.py Outdated
pool.starmap(self._dist_destroy, [() for _ in range(num_procs)])
pool.close()
pool.join()
self._remove_shm_segments(num_procs)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Persist shm keys until cached pools are torn down

In the checked cpu-torch-latest.yml and new v1 workflow, pytest --forked can run classes with reuse_dist_env=True (for example TestMuonPartialModelTraining); _close_pool(..., force=False) skips this block, and the forked test process exits without calling _remove_shm_segments, while a forced close uses a fresh instance with no _master_port. Because get_master_port now gives each forked item a different shm key, every such item leaves a new ~66 MiB file per rank instead of reusing the prior name, so long CPU suites can exhaust /dev/shm; persist the port with the cached pool and remove it when that pool is actually terminated, or disable reuse under --forked.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

Comment thread tests/unit/common.py Outdated
def _dist_run(self, local_rank, num_procs, master_port, init_method, skip_msg=""):
# A wedged rank would otherwise block its pool worker forever and take
# the whole xdist session down with it; dump the stack and exit instead.
faulthandler.dump_traceback_later(self.exec_timeout, exit=True)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge Cancel rank watchdogs after successful runs

In non-forked xdist runs such as the checked amd-mi200.yml, a reuse_dist_env=True worker returns to _pool_cache after _dist_run, but this process-global timer remains armed. If that pool is idle for exec_timeout (600 seconds by default) while other tests run, exit=True kills a healthy rank; multiprocessing.Pool can replace it with an uninitialized process, and the next cache hit supplies master_port=None, causing the reused distributed test to fail or hang. Cancel the watchdog in a finally block before a successful worker is returned to the pool.

AGENTS.md reference: AGENTS.md:L19-L19

Useful? React with 👍 / 👎.

@delock delock Oct 28, 2026 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right, given the impact of this change. I'll remove watchdog and leave it to separate work.

Comment thread ci/test_tests_fetcher.py
raise SystemExit(main())


def test_registered_workflows_select_from_the_v1_scope() -> None:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Define the registry test before invoking the runner

The checked formatting and Modal self-test jobs invoke python ci/test_tests_fetcher.py, but direct execution reaches raise SystemExit(main()) before this function is defined, so _all_test_functions() never includes the new registry assertion. I confirmed the standalone command reports 27/27 while importing the module exposes 28 tests, meaning CI does not validate the added workflow configuration; move this definition above the __main__ block.

Useful? React with 👍 / 👎.

@delock
delock enabled auto-merge October 28, 2026 08:34
@delock
delock disabled auto-merge October 28, 2026 08:35
The per-fork shm-op JIT warm-up serializes on torch's FileBaton under
pytest --forked; forked children exit without releasing the baton, so
stale locks wedge one xdist worker after another until the job times
out (observed in run 40622344676). Master runs green without these
changes; bring common.py back to master and reintroduce the shm fixes
separately once the v1 suite itself is validated.

Signed-off-by: Ma, Guokai <[email protected]>
@delock
delock added this pull request to the merge queue Oct 29, 2026
Merged via the queue into deepspeedai:master with commit 8f9db2c Oct 29, 2026
15 checks passed
@delock
delock deleted the ci/cpu-v1-multirank branch October 29, 2026 01:06
@delock

delock commented Oct 29, 2026 •

Copy link
Copy Markdown
Collaborator Author

This workflow merged. Next:

  • manually run 3 times on master for correctness and stability (3 of 3 run passed)
  • Set as CI test.

banxingmjj pushed a commit to openanolis/DeepSpeed that referenced this pull request Nov 6, 2026
Follow-up to deepspeedai#8926 per its rollout plan.

The `cpu-torch-latest-v1-multirank` suite has been green on repeated
manual dispatch runs against master, so:

- `pull_request:` is added back to the `on:` block; diff-based selection
(`collect-tests` + `ci/tests_fetcher.py`) keeps unrelated PRs at
`mode=none`, so the ~1h suite only runs for PRs that touch the
`tests/unit/v1` dependency graph.
- `merge_group:` is included so the merge queue can satisfy the check
once it is registered as required in branch protection (a merge_group
event has no PR base, so it runs the full v1 scope).
- The header comment now records the rollout state instead of the plan.

Required-check registration in branch protection is a repo-settings step
for maintainers and is not part of this diff.

AI assistance: prepared with AI assistance (DeepSeek Harness agent)
under human review; the submitter has read every changed line.

Signed-off-by: Ma, Guokai <[email protected]>

---------

Signed-off-by: Ma, Guokai <[email protected]>
Signed-off-by: aden <[email protected]>
Co-authored-by: aden <[email protected]>
@auto-pr-labeler-with-jev auto-pr-labeler-with-jev Bot added the skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU. label Nov 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip-gpu-test Requires positive evidence that every changed behavior can be validated without a GPU.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants