Repository navigation
Add a v1 multi-rank CPU suite (manual dispatch first) - #8926
Conversation
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') |
There was a problem hiding this comment.
Is there value in testing 2.10.*
There was a problem hiding this comment.
My concern is about maintaining multiple versions of fast-changing dependencies like transformers. As we are seeing transformers==5+ is not BC-friendly.
There was a problem hiding this comment.
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]>
Codex Review SummaryThis 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: 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".
| pool.starmap(self._dist_destroy, [() for _ in range(num_procs)]) | ||
| pool.close() | ||
| pool.join() | ||
| self._remove_shm_segments(num_procs) |
There was a problem hiding this comment.
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 👍 / 👎.
| 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) |
There was a problem hiding this comment.
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 👍 / 👎.
There was a problem hiding this comment.
that's right, given the impact of this change. I'll remove watchdog and leave it to separate work.
| raise SystemExit(main()) | ||
|
|
||
|
|
||
| def test_registered_workflows_select_from_the_v1_scope() -> None: |
There was a problem hiding this comment.
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 👍 / 👎.
Signed-off-by: Ma, Guokai <[email protected]>
Signed-off-by: Ma, Guokai <[email protected]>
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]>
|
This workflow merged. Next:
|
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]>
What
Adds
cpu-torch-latest-v1-multirank, a CPU suite for thetests/unit/v1multi-rank tests — the one gap left between the existing CPU workflows:cpu-torch-latestunit/atworld_size == 1(the device gate skips higher ranks)cpu-torch-multi-latest(nightly)sequentialmarkercpu-torch-latest-v1-multirank(this PR)world_size2-4)Mechanically it is the same recipe the nightly suite uses:
LOCAL_SIZE=4lets the per-device gate admit the multi-rank tests, andDS_MULTIRANK_ONLY=1deselects 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 newWORKFLOWSentry scopes the suite totests/unit/v1, so a PR only runs the v1 files it could affect. Thecollect-testsjob writesci/.test_selection/test_list.txtand the test job consumes it;mode=noneskips the run entirely. No test lists are maintained by hand.Rollout: manual dispatch first
The trigger is
workflow_dispatchonly, 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 theon: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 DDPdevice_idscapability probe — without it, all 24 DDP autocast variants fail on CPU withValueError: 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/shmsegments are left behind.Validation
python3 ci/test_tests_fetcher.py: 27/27 (adds a registry test for the newWORKFLOWSentry)ci/tests_fetcher.py --workflow cpu-torch-latest-v1-multirank:mode=all(->tests/unit/v1) with no base,mode=nonewith no impacted tests;ci/torch_latest.py validate-selectionpassesAI 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]