Skip to content

[Perf] multimodal: Lazily initialize CUDA VMM feature transport - #45384

Open
Phoenix3334 wants to merge 4 commits into
sgl-project:mainfrom
Phoenix3334:perf/cuda-vmm-lazy-init
Open

Phoenix3334 wants to merge 4 commits into
sgl-project:mainfrom
Phoenix3334:perf/cuda-vmm-lazy-init

Conversation

@Phoenix3334

@Phoenix3334 Phoenix3334 commented Oct 20, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

Related to #45345.

While investigating #45345, we found that CudaVmmFeatureTransport eagerly creates a tokenizer-owned CudaVmmMemoryPool as soon as cuda_vmm is selected, before any multimodal feature dispatch occurs. Text-only workloads on multimodal-capable models therefore pay per-worker CUDA/VMM initialization and HBM reservation even if the transport is never used.

This PR defers that allocation until the first non-empty multimodal dispatch.

Modifications

  • Keep the existing per-worker pool budget unchanged, but save the pool construction arguments during transport initialization instead of allocating immediately.
  • Add _ensure_pool() with a lock, double-check, and shutdown veto so the pool is created exactly once on first non-empty multimodal dispatch from the publisher thread.
  • Track transport enablement explicitly because self.pool is None now also means “enabled but not initialized”.
  • Preserve the eager CPU-only single-thread publisher executor.
  • Preserve existing cancellation and rollback behavior.
  • On shutdown, set _closing, drain the publisher executor, then shut down the pool if it was created. The pool reference is intentionally retained to preserve the existing idempotent/retry shutdown contract.

Unit tests

Coverage is added to the existing CPU-registered test/registered/unit/multimodal/test_gpu_feature_transport.py.

The new TestCudaVmmLazyInit(CustomTestCase) is intentionally kept small and covers four lifecycle invariants:

  • startup allocates no pool; first non-empty MM dispatch creates it and subsequent use reuses it
  • concurrent first use creates exactly one pool
  • shutdown before first use prevents late pool creation
  • if initialization wins the race, shutdown waits and releases the created pool

The existing text-only async-bypass test now also asserts that pool remains None, directly covering cuda_vmm enabled + text-only dispatch → no allocation. Existing object.__new__ fixtures are updated only for the newly explicit lifecycle state. The pre-existing disabled-transport test continues to cover the no-op path, so no duplicate lazy-init test is added for it.

Whole-file validation after the final test refinements: 43 passed + 2 subtests. The production diff is unchanged by the test-only refinements.

Accuracy Tests

No model computation or output path is changed; this only changes when the transport pool is initialized.

End-to-end correctness check on 2 nodes × 4 GB300, cuda_vmm, 32 tokenizer workers, MF=0.90:

  • with --skip-server-warmup, the server reaches READY without eager tokenizer-side VMM allocation
  • the first real image creates the CUDA VMM allocation on demand and succeeds
  • shutdown is clean

Speed Tests and Profiling

This is primarily a startup/lifecycle memory change rather than a steady-state throughput optimization.

Observed on the GB300 setup above:

  • startup with --skip-server-warmup: tokenizer workers do not reserve the VMM pool before first multimodal use
  • first real image: tokenizer-side aggregate CUDA VMM allocation on GPU0 reaches ~0.9 GiB on demand

The default 448×448 Kimi-K3 multimodal startup warmup still OOMs on the #45345 reproduction. Free memory falls from ~24.1 GiB to ~6.0 GiB before failure, with ~0.32 GiB free reported at OOM.

A follow-up source review shows an important distinction for multi-tokenizer mode: each tokenizer worker starts its own general server warmup, so with 32 tokenizer workers the 448×448 VLM warmup can be issued concurrently from many worker processes. In that path, lazy initialization is immediately exercised by the warmup itself, so it cannot avoid the startup-time transport allocation; concurrent multimodal preprocessing / transport work can also amplify the peak.

The N=1/2/4/8/16/32 scaling profile and N=32 concurrent/serialized A/B have now been collected in #45345. The sweep observed exactly N warmups, READY through N=16, and OOM at N=32. Serializing all 32 per-worker warmups reduced recorded peak GPU0 usage from 282,299 MiB (OOM) to 263,275 MiB (READY), with all 32 serialized warmups completed. #45584 proposes the separate general-warmup serialization fix while preserving each worker's warmup and post-warmup/GC lifecycle.

Those hardware results were collected in the investigation's v0.5.22-based environment with lazy initialization. They do not constitute a hardware rerun of #45584's current-main commit or establish that serialization alone on an eager-init baseline is sufficient. This PR remains scoped to lazy CUDA VMM transport initialization.

Therefore this PR does not claim to fix #45345. It addresses the narrower lifecycle inefficiency: CUDA VMM transport resources should not be allocated before the transport is actually used. The duplicated/concurrent multi-tokenizer warmup behavior is being tracked separately in #45345 and is intentionally out of scope here.

Checklist

  • Format code according to pre-commit.
  • Add unit tests according to the contribution guide.
  • Documentation update is not required for this internal lifecycle change.
  • Accuracy / functional validation results are provided above.
  • Follow the SGLang code style guidance.

CI States

Latest PR Test (Base): ❌ Run #39538956365
Latest PR Test (Extra): ❌ Run #39538956367
Latest PR Test (AMD ROCm 10): ❌ Run #39538956378

Copy link
Copy Markdown
Contributor Author

@HaiShaw @yhyang201 @mickqian — could you take a look when convenient, and could someone with CI permission add the required run-ci label?

This PR came out of #45345 and is intentionally scoped to the CUDA VMM transport lifecycle: it defers tokenizer-owned CudaVmmMemoryPool allocation until the first actual multimodal publication while preserving the existing pool budget, cancellation behavior, and retry/idempotent shutdown semantics.

The matched GB300 controls are now available: 1 tokenizer worker + cuda_vmm reaches READY; 32 workers + cuda_vmm still OOMs during the default multimodal warmup; 32 workers + explicit CPU feature transport reaches READY and serves a real image. With lazy init plus --skip-server-warmup, 32 tokenizer workers reach READY without eager VMM allocation, and the first real image then creates the allocation on demand and succeeds. The PR therefore does not claim to fix the broader warmup OOM in #45345.

Local whole-file CPU validation passed (43 passed + 2 subtests passed). The currently red Arm64 / Extra AMD workflows are stopping at the expected Require run-ci label gate rather than a test failure. Thanks.

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.

[Bug] Startup OOM with 32 tokenizer workers and auto-selected CUDA VMM transport on multi-node GB300

1 participant