Skip to content

[Fix] [NVIDIA] allreduce: Stage VMM graph inputs in CustomAllreduce instead of IPC-registering them - #44448

Open
adi-suresh01 wants to merge 4 commits into
sgl-project:mainfrom
adi-suresh01:fix/custom-ar-vmm-graph-buffers
Open

adi-suresh01 wants to merge 4 commits into
sgl-project:mainfrom
adi-suresh01:fix/custom-ar-vmm-graph-buffers

Conversation

@adi-suresh01

@adi-suresh01 adi-suresh01 commented Oct 15, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

On PCIe-only boxes, CustomAllReduceV2 requires full NVLink, so sglang falls back to the legacy v1 CustomAllreduce. When PYTORCH_CUDA_ALLOC_CONF=expandable_segments:True is set (the Qwen3.8-Flash-Next cookbook recommends it for long contexts), CUDA-graph inputs come from cuMemCreate memory. During capture v1 records those pointers, and register_graph_buffers -> get_graph_buffer_ipc_meta calls cudaIpcGetMemHandle on them, which only accepts cudaMalloc memory. The server dies during graph capture with RuntimeError: invalid argument. This is attempt 1 in #44291.

Reproduced on 2x RTX PRO 6000 Blackwell Server Edition (sm_120, PCIe, no NVLink, P2P OK), lmsysorg/sglang:dev-cu13 at a6a8c56, Qwen/Qwen3-0.6B, --tp-size 2:

Run Result
default allocator boots, v1 registers 2850 + 2052 graph addresses
expandable_segments:True RuntimeError: invalid argument in get_graph_buffer_ipc_meta
expandable_segments:True + SGLANG_ENABLE_PCIE_IPC_ALLREDUCE=1 same failure; v1 still captures alongside PCIe-IPC
expandable_segments:True + this PR boots, same output as the default run at temperature 0

Modifications

  • python/sglang/srt/distributed/device_communicators/custom_all_reduce.py: during capture, an input that is VMM memory (checked with the existing is_vmm_pointer) goes through the staged path, which copies it into v1's pre-registered cudaMalloc IPC buffer. That is the path SGLANG_MEMORY_SAVER_CUDA_GRAPH already uses, so no kernel or sgl-kernel change is needed. Non-VMM inputs keep the registered path exactly as before. The check is per input, so it also covers the memory saver and symmetric-memory pools, and it only runs at capture time.
  • test/registered/kernels/ops/communication/test_custom_all_reduce_v1_vmm.py: new 2-GPU test that runs v1 under expandable_segments, captures 4 all-reduces per graph (inputs from a plain tensor and from the graph's own pool), and compares against NCCL exactly.

Why not zero-copy like v2's VmmGraphInputManager: v1's graph slots only take cudaIpc handles, so zero-copy would need a new AOT op and an sgl-kernel release. Staging reuses a path that is already in production.

Accuracy Tests

  • New test on the PCIe pod: without this PR 1 failed, 1 passed (test_graph_all_reduce_matches_nccl[16-False] raises RuntimeError: invalid argument); with it 9 passed.
  • Server: with expandable_segments + this PR, the smoke request returns the same text as the default allocator at temperature 0.
  • Default path with this PR (registered inputs, default allocator): exact match to NCCL at every size from 2 KB to 8 MB.

Speed Tests and Profiling

Decode with sglang.benchmark.one_batch_server, Qwen/Qwen3-0.6B, TP2, input 256, output 128, steady-state tok/s:

Batch main, default allocator this PR, default allocator this PR, expandable_segments
1 704 705 681
8 3988 3995 3883
32 12261 12310 12030

Default users see no change. expandable_segments users go from a crash at startup to 2-3% below the default allocator.

Per all-reduce, 8 captured per graph, median of 2 runs:

Size v1 registered (default allocator) v1 staged (expandable_segments) pynccl
2 KB 4.58 us 5.38 us 12.39 us
16 KB 5.25 us 6.13 us 14.39 us
1 MB 42.0 us 43.1 us 47.7 us

Staging adds about 0.8 us at decode sizes and stays 2.3-2.7x faster than falling back to pynccl.

Checklist

Refs #44291


CI States

Latest PR Test (Base): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (Extra): ⊘ Skipped -- a maintainer comments /tag-and-rerun-ci to run CI tests.
Latest PR Test (AMD ROCm 10): ⚠️ Run #47166305823

Tip

Base CI only covers the core cases, and its workload may not exercise your change. Use /rerun-test to run the tests your change touches, or copy this prompt for an agent:

Find the registered tests this PR affects and run them with /rerun-test, following https://github.com/sgl-project/sglang/blob/main/.agents/skills/rerun-test/SKILL.md

@adi-suresh01

Copy link
Copy Markdown
Contributor Author

@ch-wan this is the custom all-reduce half of #44291: with expandable_segments on a PCIe-only box, v1 hands VMM pointers to cudaIpcGetMemHandle during graph capture and the server dies with invalid argument. The fix stages those inputs through v1's existing registered buffer, the same path the CUDA-graph memory saver uses, so no sgl-kernel change. Could you take a look, or point me to whoever owns custom all-reduce? CI needs the run-ci label too.

detain added a commit to detain/sglang that referenced this pull request Oct 20, 2026
…/deferred/avoid map

- 3A [24-35]: NVFP4 MoE boot sgl-project#39807/sgl-project#40173, block-FP8 TP refine sgl-project#42566, k-pool indexer split sgl-project#43619,
  SM120 skinny GEMM sgl-project#42865/sgl-project#42867, DeepGEMM warmup guards sgl-project#32686/sgl-project#43712, autotune sgl-project#43363/sgl-project#40420,
  mHC overlap sgl-project#42985, FP8-einsum precompile sgl-project#42821.
- 3B [36-43]: PCIe CustomAllreduce VMM sgl-project#44448, EP local expert ids sgl-project#44480, shm TP broadcast sgl-project#44202,
  PCIe-IPC all-gather sgl-project#42863 + multicast guard sgl-project#41888, TP-sampling consistency sgl-project#41916/sgl-project#38565,
  draft embed/lm_head VRAM sgl-project#37155.
- sgl-project#39807 toolchain commit verified safe against our CUDA_HOME=12.9 pin (cu13 fallback needs CUDA_HOME unset AND glibc>=2.41; we are 2.39).
- stack_want.txt: execution-status banner. Branch tip 5dd6ec7.
detain added a commit to detain/sglang that referenced this pull request Oct 20, 2026
…rt, DeepGEMM warmup recipe key, MoE disagg bag)

Individually-passing PRs collided when merged on deepseek-41-flash-1017-stack:

- sgl-project#44448: test_custom_all_reduce_v1_vmm.py imported register_comm_cleanup
  from sglang.kernels.ops.communication.mp (does not exist); the real home
  is sglang.srt.distributed.comm_cleanup. Fixing the import unblocked
  collection. Also added the repo-idiomatic module-level
  skipif(not torch.cuda.is_available()) so the torchrun-only GPU tests skip
  cleanly when pytest is invoked directly without GPUs.
- sgl-project#43712: _INITIALIZATION_DICT is keyed by the 5-tuple
  (kernel_type, n, k, num_groups, recipe) (compile_utils.py:163); the
  blockwise FP8 gemm_nt_f8f8bf16 path calls the hook without a recipe, so
  test_warmup_state now builds 5-tuple keys with recipe=None, matching the
  implementation exactly.
- sgl-project#39807: the flashinfer_cutlass fp4 fallback calls
  _cutlass_moe_tune_max_num_tokens -> get_disagg(); the sm120 nvfp4
  placement test called _run_flashinfer_cutlass outside any publish scope,
  so 'config namespace disagg not published'. Publish the bags with the
  file's existing idiom, get_context().override_server_args(model_path=
  "dummy"), the same way test_flashinfer_cutlass_swiglu_params.py exercises
  the disagg bag.

CPU verification (CUDA_VISIBLE_DEVICES=9): 13 passed, 9 skipped (GPU-only
VMM subtests), 0 failed.
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…s in CustomAllreduce instead of IPC-registering them

cudaIpcGetMemHandle accepts only cudaMalloc memory; a CUDA-graph input
that lives in cuMemCreate memory (expandable_segments, the memory saver,
symmetric-memory pools) made v1's register_graph_buffers path die with
RuntimeError: invalid argument during capture. Decide registration per
input at capture time and stage VMM inputs through the pre-registered
IPC buffer instead.

Fork union with entry 75 (a89d298): is_vmm_pointer is added to the
existing cuda_vmm_utils import line, and the shipped test skips (rather
than raises) when v1 is init-disabled by the fork's VMM-allocator guard
-- upstream's raise would make the test dead-on-arrival on this tree.
The capture-time staging keeps the fork byte-aligned with upstream for
the residual reachable case (VMM inputs despite a non-VMM init probe).

(cherry picked from commit ad19c6a)
(cherry picked from commit 044ac078bed291e2bc1d14c2d96c11ddbcfefad2)
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…(entries 255-256)

Batch 1 of the 2026-10-28 second wave. Two open-PR ports landed
clean (zero conflicts) onto 56f97a7 -- code tip 0df18e9:
a13e98b sgl-project#44448 (VMM graph-input staging in CustomAllreduce v1,
defense-in-depth behind the entry-75 init refusal) and 0df18e9
sgl-project#39605 (host-staged + LL TP2 all-reduce transports, both opt-in,
LL/PCIe-IPC COLLISION documented at the dispatch site).

FAM-A6a marked LANDED in wanted_stack.txt; sgl-project#44342's parallel_state.py
hold explicitly RELEASED for its later FAM-A3b wave.

Verified at the landed tip (prod venv, CVD=9): comm named set
114P/1S/30sub (exact worker match), whole unit/distributed dir
120P/1S/35sub 0F, the three new test files collect 18 (9 registered
multi-GPU + 9 test/manual). NOTHING PUSHED.
detain added a commit to detain/sglang that referenced this pull request Oct 29, 2026
…n cleanup)

no upstream PR; fork debt from entry 256.

Entry 256 ported sgl-project#39605 keeping upstream's raw os.environ.get sites --
deliberate at port time ("PR as-is, not normalized"), but the fork's own
sgl-project#44448-era convention is environ.py registration, and the flagged consequence
is real: an environ-only grep of the tree missed all three of these switches.
This closes the deviation for the three named gates. SGLANG_ENABLE_PCIE_IPC_-
ALLREDUCE is already registered (environ.py, "Deterministic inference and
all-reduce"), which is why the LLGUARD guard could read PCIe-IPC's state via
envs through eligible_group.

Registered (append-only, next to the PCIe-IPC pair):
  SGLANG_LL_ALLREDUCE = EnvBool(False)
  SGLANG_LL_ALLREDUCE_MAX_BYTES = EnvInt(64 << 10)  -- verified against the
      raw fallback str(64 << 10) in ll_allreduce.py: identical 65536.
  SGLANG_HOST_STAGED_ALLREDUCE = EnvBool(False)
Migrated: the two construction gates in parallel_state (host-staged inline,
LL via _build_ll_allreduce) and LLAllReduce.__init__'s max-bytes read.

ACCEPTANCE SEMANTICS DELTA, STATED (this is NOT byte-identical, and the safer
superset was chosen): the raw gates were `== "1"`; EnvBool.parse also honors
"true"/"yes"/"y" case-insensitively and maps junk to the default-off with a
warning. Every value the raw check accepted ("1") still arms; the widening
only makes an operator who wrote =true get the transport they clearly meant.
Under the LLGUARD guard this is collision-safe for every spelling. The
MAX_BYTES move is strictly more forgiving: the raw int() raised on garbage
and took the coordinator __init__ down with it; EnvInt.get warns and uses
65536. The raw == "1" pin from commit LLGUARD was replaced by the new
acceptance table, not deleted.

Out of scope, deliberately left raw (entry 256's two secondary knobs, named
by neither task nor audit): SGLANG_HOST_STAGED_ALLREDUCE_MIN_BYTES and
..._PIECE in host_staged_allreduce.py -- _PIECE is a module-import-time read,
registration would need a callable-default discussion of its own.

Tests: test_parallel_state.py +test_ll_env_acceptance_is_env_bool (8-value
table through the real gate) and +test_comm_envs_are_registered_not_raw
(defaults: False/65536/False; source pins that the sites read the handles,
per the repo's mocks-cannot-catch precedent). Battery CVD=9:
test/registered/unit/distributed/ = 133P/1S/35sub 0F (commit-1 state 132P,
base 120P/1S/35sub). Manual GPU tests unaffected (env names in docstrings
only; envs.get reads live os.environ, so a setenv-driven boot behaves the
same).
@adi-suresh01
adi-suresh01 force-pushed the fix/custom-ar-vmm-graph-buffers branch from ad19c6a to f38f473 Compare December 3, 2026 17:46
@adi-suresh01

Copy link
Copy Markdown
Contributor Author

@ch-wan rebased onto current main. The only conflict was #36088's enable_register_for_capturing, so capture now registers the input only when that flag is on and the input isn't VMM, which is the same behavior as before at the default. The test import also moved to sglang.srt.distributed.comm_cleanup after #45112. Ready for CI whenever you have a minute.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants