You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Perf] multimodal: Lazily initialize CUDA VMM feature transport - #45384
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.
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.
@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 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
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.
Motivation
Related to #45345.
While investigating #45345, we found that
CudaVmmFeatureTransporteagerly creates a tokenizer-ownedCudaVmmMemoryPoolas soon ascuda_vmmis 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
_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.self.pool is Nonenow also means “enabled but not initialized”._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:The existing text-only async-bypass test now also asserts that
poolremainsNone, directly coveringcuda_vmmenabled + text-only dispatch → no allocation. Existingobject.__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:--skip-server-warmup, the server reaches READY without eager tokenizer-side VMM allocationSpeed Tests and Profiling
This is primarily a startup/lifecycle memory change rather than a steady-state throughput optimization.
Observed on the GB300 setup above:
--skip-server-warmup: tokenizer workers do not reserve the VMM pool before first multimodal useThe 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
CI States
Latest PR Test (Base): ❌ Run #39538956365
Latest PR Test (Extra): ❌ Run #39538956367
Latest PR Test (AMD ROCm 10): ❌ Run #39538956378