Repository navigation
Guard the shm inference all-reduce on the host ISA - #8701
Merged
Merged
Conversation
The shm comm op's bf16/fp16 reduce kernels are compiled with
target("avx512bw") and use _mm512_* conversions (the fp32 kernels only
use 256-bit AVX). Executing them on a host without the ISA faults, and
because the reduce synchronizes through shm flags, the fault surfaces
downstream as a permanent hang of the peers instead of an error - on
the multi-rank CPU run it froze an xdist worker for two hours until the
phase timeout.
Export a vector_kernel_level() probe from the op (2 = avx512bw, 1 =
avx2, 0 = neither; non-x86 hosts report 2 since their kernels are
JIT-built for the host ISA) and gate the dispatch in
inference_all_reduce: fall back to the process-group all_reduce when
the tensor dtype needs a level the host lacks.
Verified on an avx2-only host: fp32 keeps the shm op, bf16/fp16 now
fall back and all three dtype parametrizations of
TestDistInferenceAllReduce pass (they previously segfaulted/hung); a
standalone 4-rank repro that crashed before returns correct sums.
Signed-off-by: Guokai Ma <guokai.ma@intel.com>
delock
force-pushed
the
fix/shm-isa-guard
branch
from
September 29, 2026 09:37
28aafbe to
0962aa2
Compare
Contributor
There was a problem hiding this comment.
Copilot review overview
🟡 Changes recommended
The probe can still enable kernels compiled for unsupported x86, AArch64, or RISC-V instruction sets and lacks deterministic dispatch tests.
Review effort: Balanced
Findings: 2
Open (3)
What changed in this PR
Adds host-ISA guarding for shared-memory inference all-reduce to prevent illegal-instruction faults and peer hangs.
Changes:
- Exposes shared-memory kernel ISA capability levels.
- Falls back to process-group all-reduce when the host lacks the required ISA.
| File | Description |
|---|---|
deepspeed/comm/torch.py |
Selects shared-memory or process-group reduction by dtype and ISA level. |
csrc/cpu/comm/shm_interface.cpp |
Adds and exports host ISA-level detection. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
The non-x86 branch of vector_kernel_level() kept the pre-guard behavior of always enabling the kernels, but its comment wrongly claimed they are JIT-compiled for the host ISA. State the real situation instead and defer runtime probes for optional extensions (e.g. riscv +v/+zvfh) to the ports' maintainers. TestInferenceAllReduceDispatch pins the dtype x ISA-level routing matrix with stubbed collective sinks so the dispatch is covered on any runner instead of whichever path the host CPU happens to enable. Signed-off-by: Guokai Ma <guokai.ma@intel.com>
monkeypatch.setattr defaults to raising=True, which requires the target attribute to already exist. On non-Linux hosts (e.g. the macOS CI runner) the Linux-only shm op is never built, so torch.ops.deepspeed.inference_all_reduce_ is absent and every dispatch case failed at the stub line. Use raising=False: the stub is installed when missing and removed again on teardown. Signed-off-by: Guokai Ma <guokai.ma@intel.com>
sfc-gh-truwase
approved these changes
Oct 9, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Oct 10, 2026
banxingmjj
pushed a commit
to openanolis/DeepSpeed
that referenced
this pull request
Oct 10, 2026
## Problem Since deepspeedai#8680 landed, `modal-torch-latest / DeepSpeedAI CI` has failed for every merge-queue entry that runs this test on Modal's L40S runners (deepspeedai#8794, deepspeedai#8701, deepspeedai#8670). Example: [run 38009529440](https://github.com/deepspeedai/DeepSpeed/actions/runs/38009529440/job/114086150257). ``` FAILED tests/unit/v1/autotp/test_autotp_training.py::TestTiedRowParallelOutputHeadTraining::test_training_matches_unsharded_reference[35-3-False-0] FAILED tests/unit/v1/autotp/test_autotp_training.py::TestTiedRowParallelOutputHeadTraining::test_training_matches_unsharded_reference[35-3-True-0] Mismatched elements: 1 / 670 (0.1%) Greatest absolute difference: 1.1173542588949203e-06 at index (1, 1, 45) (up to 1e-06 allowed) ``` deepspeedai#8680's own merge-queue run and the next nightly run both used the AWS fallback, where the test passes, so the failure wasn't caught there. ## Root cause The row-parallel head (`LinearAllreduceWithReplicatedInput`) slices the hidden vector, computes a partial matmul on each rank, and all-reduces the partial logits. The reference is one unsharded fp32 matmul, and the two summation orders round differently. The tied head uses the embedding's N(0,1) weights, so logits reach about 14, where one fp32 ulp is about 1e-6. Logits that are near zero through cancellation can therefore differ by more than `atol=1e-6`. Even the fp32 reference differs from a float64 ground truth by up to 2.2e-6. ## Fix Use torch.testing's default fp32 tolerance (`atol=1e-5`, `rtol=1.3e-6`) for every fp32 `assert_close` in `test_autotp_training.py`. That covers 17 checks, including both row-parallel logits checks, and matches the 19 fp32 checks in the file that already use the default. The half-precision tolerances in `run_tp_layer_fwd_bwd` are unchanged. The default is enough for what these tests check: - The sharding bugs they target (wrong shard offset, missing all-reduce, dropped tied-gradient contribution, tied weights drifting apart) move values by 0.1 to 10. - A simulated precision regression (all-reduce inputs rounded to bf16) still fails every check it failed under the old tolerances. The one exception is the SGD-update check, which can't detect it under either tolerance. - The custom values were tighter than the default only for values below about 1, and looser for larger ones such as the losses. ## Evidence (2x H200) - In a sweep of 40 init seeds, every parametrization of the tied test has seeds that fail the old logits check (worst ratio to the allowed tolerance: 1.19). Under the default, the worst case uses under 30% of the limit. - Changing only the seed to 8199 reproduces the CI failure: `[35-3-False-0]` and `[35-3-True-0]` fail with `1 / 670` mismatched and `1.25e-06 (up to 1e-06 allowed)`. - Every other changed check stays under 3% of the default limit, recorded per call across the 4 affected test classes. ## Testing Hardware: 2x NVIDIA H200, torch 2.12.0+cu130, Python 3.12. - `pytest tests/unit/v1/autotp/test_autotp_training.py -k "TestRowParallelOutputHeadTraining or TestTiedRowParallelOutputHeadTraining"`: 8 passed. - `pytest tests/unit/v1/autotp/test_autotp_training.py -m sequential -k "TestTiedEmbeddingAliasesAndFallback or TestTiedVocabParallelLMHead"`: 30 passed. - Seed-8199 reproduction, which fails before this change: passes with the default logits tolerance. - `pre-commit run --files tests/unit/v1/autotp/test_autotp_training.py`: passed. No L40S is available locally. This PR's merge-queue run selects this test file, so it will check the fix on Modal's L40S runners unless the run falls back to AWS. --------- Signed-off-by: Hongwei Chen <hongweichen@microsoft.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
banxingmjj
pushed a commit
to openanolis/DeepSpeed
that referenced
this pull request
Oct 16, 2026
## What Adds the `world_size` axis to CI, which the current suite does not cover: | File | Purpose | |---|---| | `.github/workflows/cpu-torch-multi-latest.yml` | Nightly + manual dispatch: runs the multi-rank CPU tests on a 4-vCPU runner | | `.github/workflows/cpu-multi-triage.yml` | Routes its outcome through the existing `ci/nightly_classify.sh` / `ci/nightly_report.sh` protocol | | `tests/conftest.py` | The `DS_MULTIRANK_ONLY` collection hook the workflow selects with (required) | | `.github/workflows/TEST_SELECTION.md` | Registration of the new nightly | ## Why `cpu-torch-latest` advertises a single device, so the per-device gate in `tests/unit/common.py` skips **every `world_size > 1` test** on that runner. The multi-rank path is therefore only exercised on GPU machines, and issues that show up there only in a multi-rank configuration go unnoticed. A recent example: PR deepspeedai#8638 changed the overflow semantics so that non-finite group norms force an optimizer step to be skipped, bypassing `bf16.check_grad_overflow: False`. `TestZeROBFloat16::test_ignore_grad_overflow` is `world_size = 2`, so it is collected and *skipped* by the CPU CI and by any run with one device; it fails as soon as two ranks execute. Reported as issue deepspeedai#8805. ## Why a nightly rather than a pre-merge check The selection is cheap to state and expensive to run (measured in deepspeedai#8381, 4-vCPU runner): | Run | Wall time | |---|---| | This suite: non-v1 multi-rank half | 68-89 min | | This suite: `sequential`-marked phase | 13-16 min | | Longest current pre-merge job (`cpu-torch-latest`) | 39-43 min | | Longest merge-queue job (`modal-torch-latest`) | 64-71 min | Putting it in the pre-merge path would roughly triple the critical path of every PR, and a single wedged rank would block the merge queue (the suite's known hang — the shm op segfaulting on hosts without AVX512 — is fixed by deepspeedai#8701, but the suite is the most expensive one to re-run). ## What it runs - `LOCAL_SIZE=4` so the gate admits `world_size <= 4`; `DS_MULTIRANK_ONLY=1` deselects the single-rank tests that `cpu-torch-latest` already guards. - Non-v1 half, `timeout 120m`, plus a `sequential`-marked phase, `timeout 25m` (the parallel phase deselects those by default, so they would otherwise never run here). - Same preset/install/HF-predownload steps as `cpu-torch-latest`, so both runs agree on the environment. - On failure the last step prints `DS_CI_FAILURE_CLASS=timeout|test` for triage; a run that dies before that step is reported as unclassified rather than guessed. Triage is a separate workflow with its own issue titles and its own `nightly-cpu-multi-last-green` tag, so `nightly-last-green` keeps meaning "the last revision the full GPU suite verified" and the modal issue dedupe is untouched. ## Validation - Workflow YAML parses; `pre-commit` clean. - Timings above come from the real runs of this configuration in deepspeedai#8381. - Not yet run as `cpu-torch-multi-latest`: GitHub only exposes `workflow_dispatch` for workflows present on the default branch, so the first manual dispatch has to happen after this merges. Happy to run it then and follow up with the numbers. --------- Signed-off-by: Guokai Ma <guokai.ma@intel.com> Signed-off-by: Ma, Guokai <guokai.ma@intel.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.


Problem
The shm comm op's bf16/fp16 reduce kernels are compiled with
target("avx512bw")and use_mm512_*conversions; the fp32 kernels use 256-bit AVX. Executing them on a host without the ISA faults, and because the reduce synchronizes through shm flags, the fault surfaces downstream as a permanent hang of the peers instead of an error — on the multi-rank CPU CI this froze an xdist worker until the phase timeout.Change
vector_kernel_level()from the op:2= avx512bw,1= avx2,0= neither; non-x86 hosts report2(their kernels are JIT-built for the host ISA).inference_all_reduce: fall back to the process-groupall_reducewhen the tensor dtype needs a level the host lacks (fp32 requires level 1, bf16/fp16 require level 2).Validation
TestDistInferenceAllReducepass (previously segfaulted/hung), and a standalone 4-rank repro that crashed before returns correct sums.vector_kernel_level()reports 2 and every dtype still dispatches to the original shm kernels — the guard is a pure init-time probe with no change to the kernel code, so behavior on AVX512 machines is unchanged.inference_all_reduceresults remain numerically equivalent to the process-groupall_reduceacross fp32/bf16/fp16 and small through large message sizes (crossing the 1MB distributed-path threshold), and the shm latency advantage over gloo is preserved (microsecond-scale small messages).