Skip to content

perf: fix overlap scheduling and all-reduce fusion for NVIDIA Confidential Computing(CC) on Blackwell - #31447

Open
elvischenv wants to merge 2 commits into
sgl-project:mainfrom
elvischenv:cc-fixes-rebased
Open

perf: fix overlap scheduling and all-reduce fusion for NVIDIA Confidential Computing(CC) on Blackwell#31447
elvischenv wants to merge 2 commits into
sgl-project:mainfrom
elvischenv:cc-fixes-rebased

Conversation

@elvischenv

@elvischenv elvischenv commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

Motivation

Two fixes so SGLang runs efficiently under NVIDIA Confidential Computing (CC), where the GPU operates behind a bounce buffer:

  1. Per-step D2H result readback stalls the scheduler. Under CC, cudaMemcpyAsync (D2H) is forced synchronous — it blocks at issue — so the per-step readback of next_token_ids / logprobs serializes onto the scheduler's critical path and kills decode overlap.
  2. FlashInfer AR+RMSNorm fusion disables itself. create_allreduce_fusion_workspace allocates a symmetric-memory (cuMulticast) workspace whose preflight fails under CC, so the fusion silently falls back off — even though the fusion kernels themselves are multicast-free.

Both paths are gated on is_confidential_compute() (NVML, overridable via SGLANG_CONFIDENTIAL_COMPUTE); off-CC behavior is unchanged.

Modifications

cc: async device->host result-readback worker

  • New python/sglang/srt/managers/async_d2h_copy_worker.py (AsyncD2HCopyWorker): runs the per-step D2H copy on a dedicated thread with its own CUDA stream, off the scheduler's critical path, so overlap is preserved. Wired into scheduler.py / managers/utils.py; only routed through the worker when CC is detected.
  • Adds is_confidential_compute() to srt/utils/common.py.

cc(fix): enable FlashInfer AR+RMSNorm fusion under Confidential Computing (layers/flashinfer_comm_fusion.py)

  • FlashInfer now auto-selects a multicast-free IPC workspace under CC, so SGLang reuses the normal off-CC fusion path: _resolve_backend forces the trtllm backend under CC (SM100 "auto" defaults to mnnvl, which needs NVLink multicast), the symmetric-memory preflight is skipped, and the workspace stays a normal AllReduceFusionWorkspace. Enabled by default whenever CC is detected.

Accuracy Tests

With CC on:

|Tasks|Version|     Filter     |n-shot|  Metric   |   |Value |   |Stderr|
|-----|------:|----------------|-----:|-----------|---|-----:|---|-----:|
|gsm8k|      3|flexible-extract|     5|exact_match|↑  |0.9348|±  |0.0068|
|     |       |strict-match    |     5|exact_match|↑  |0.9606|±  |0.0054|

Checklist

  • Format code with pre-commit (all hooks pass).
  • Added unit tests (test/registered/core/test_async_d2h_copy_worker.py).
  • Documentation update — n/a.
  • Accuracy/speed benchmark — n/a (no output change; CC-hardware benchmark pending).
  • Follow the SGLang code style guidance.

🤖 Generated with Claude Code


CI States

Latest PR Test (Base): ❌ Run #31763733100
Latest PR Test (Extra): ❌ Run #31763732864

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces support for NVIDIA Confidential Computing (CC) in SGLang. It implements an AsyncD2HCopyWorker to offload device-to-host copies to a dedicated background thread, preventing scheduler thread stalls caused by synchronous bounce-buffer copies under CC. It also configures FlashInfer allreduce fusion to force the multicast-free trtllm backend and disables symmetric-memory preflight checks when CC is enabled. The review feedback suggests unconditionally initializing enable_async_d2h_copy and async_d2h_worker in init_overlap to prevent potential AttributeErrors when overlap scheduling is disabled.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread python/sglang/srt/managers/scheduler.py
@elvischenv elvischenv changed the title cc: support NVIDIA Confidential Computing — FlashInfer AR fusion + async D2H readback perf: fix overlap scheduling and all-reduce fusion for NVIDIA Confidential Computing(CC) on Blackwell Jul 16, 2026
@elvischenv
elvischenv marked this pull request as ready for review July 28, 2026 03:03
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

@nvpohanh

nvpohanh commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

/tag-and-rerun-ci

elvischenv and others added 2 commits August 13, 2026 19:25
…er CC

Under NVIDIA Confidential Computing (bounce-buffer CC) a device-to-host
cudaMemcpyAsync is forced synchronous and blocks at issue. The overlap
scheduler's per-step result readback (next_token_ids, logprobs, hidden
states, ...) then stalls the scheduler thread for ~a full copy every step,
serializing decode and collapsing overlap.

Detect CC once via NVML (is_confidential_compute, env-overridable with
SGLANG_CONFIDENTIAL_COMPUTE) and, when overlap is enabled, offload the
blocking readback to a dedicated daemon thread (AsyncD2HCopyWorker) that
owns a private CUDA stream. Mirrors the TensorRT-LLM pattern
(NVIDIA/TensorRT-LLM#8463):

  - submit() records a readiness event on the caller's current stream and
    hands the copy to the worker; the worker event-syncs on it (event-sync,
    not a stream wait, so the blocking copy never stalls the scheduler's
    CUDA API calls), runs the copy on its private stream, and signals it;
  - submit() returns a HostCopyDone -- a host-thread-backed drop-in for the
    copy_done CUDA event (same record()/synchronize() surface) -- which the
    scheduler stores in result.copy_done. Every existing
    copy_done.synchronize() consumer then waits on the worker unchanged, so
    no result-processing code changes;
  - synchronize() re-raises if the copy failed, so a readback error aborts
    the step instead of consuming invalid host tensors.

The stream is created and owned by the worker so nothing else can enqueue
onto it (sharing it would recouple copy-completion to the next forward and
defeat the overlap). Only GenerationBatchResult is offloaded -- its
copy_done is pre-created, so the swap survives copy_to_cpu; embedding is
one-shot with no decode overlap to preserve and is copied inline.

Co-authored-by: spethe <spethe@nvidia.com>
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
…ting

The trtllm AR+RMSNorm fusion runs off-CC, but under CC it disabled itself:
create_allreduce_fusion_workspace allocated a symmetric-memory (cuMulticast)
workspace whose preflight fails under CC. The fusion kernels are themselves
multicast-free (one-shot Lamport and two-shot sync; 0 multimem in
trtllm_allreduce_fusion.cuh) -- only the workspace allocator wanted multicast.

FlashInfer now auto-selects a multicast-free IPC workspace under CC, so sglang
reuses the normal off-CC fusion path:

  - _resolve_backend forces the trtllm backend under CC (the SM100 "auto"
    default is mnnvl, which needs NVLink multicast and is unavailable under CC)
    and raises on an explicit mnnvl request or multi-node;
  - skip the symmetric-memory preflight under CC (its fabric / cuMemCreate
    probe is exactly what CC blocks);
  - the workspace stays a normal AllReduceFusionWorkspace object, so
    is_buffer_size_sufficient / cleanup / allreduce_fusion use the standard
    object path -- no cc-specific IPC field, helper, or branch.

Enabled by default whenever CC is detected (is_confidential_compute()); no env
var needed, and off-CC behavior is unchanged. Requires the matching FlashInfer
CC auto-detection change (validated CC-on for both the one-shot and two-shot
kernels).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants