Skip to content

Extract shared realtime acceleration helpers#389

Open
jarcherNV wants to merge 8 commits into
dev/jarcher/realtime-presentationfrom
dev/jarcher/realtime-acceleration
Open

Extract shared realtime acceleration helpers#389
jarcherNV wants to merge 8 commits into
dev/jarcher/realtime-presentationfrom
dev/jarcher/realtime-acceleration

Conversation

@jarcherNV

@jarcherNV jarcherNV commented Jul 19, 2026

Copy link
Copy Markdown
Collaborator

Extract shared realtime acceleration helpers

Summary

This PR extracts reusable realtime acceleration helpers from demo-specific code
and migrates the existing demos/integrations to use the shared implementations.

It builds on the shared realtime serving, timing, and presentation work by
adding common infrastructure for frame prefetching, CUDA graph dispatch policy,
prewarm execution, overlapped work, and one-shot encoder lifecycle management.

Changes

  • Add shared frame prefetch helpers for CUDA host prefetch, lazy CUDA-frame
    materialization, and generic prefetch dispatch.
  • Keep the previous cuda_host_prefetch import path as a compatibility shim.
  • Add shared CUDA graph dispatch policy helpers.
  • Add shared prewarm helpers and migrate existing warmup/prewarm paths.
  • Add shared overlap runners for synchronous, host-thread, and CUDA-stream
    execution.
  • Add shared one-shot encoder lifecycle helpers for setup, reuse, CPU result
    materialization, release, and CUDA memory cleanup.
  • Migrate the relevant OmniDreams, Wan, and FlashVSR paths onto the shared
    acceleration utilities.
  • Add focused CPU tests for the new shared helper modules.

Validation

  • Existing CPU CI is expected to cover the new helper-level tests.
  • Manual GPU smoke testing covered LingBot, OmniDreams WebRTC, and
    interactive-drive flows.
  • Observed demo behavior and steady-state timings are comparable to the
    pre-refactor phase 5 baseline.

Add infra.acceleration.frame_prefetch with CUDA host prefetch, lazy CUDA-frame
materialization, and generic prefetch dispatch helpers. Migrate the OmniDreams
raster and world-model lazy frame paths to share the implementation while
keeping the old cuda_host_prefetch import path as a compatibility shim.
@greptile-apps

greptile-apps Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR extracts reusable acceleration helpers (frame prefetch, CUDA graph dispatch, prewarm, overlap runners, encoder lifecycle) from demo-specific code into a shared flashdreams.infra.acceleration package, then migrates OmniDreams, Wan, FlashVSR, and LingBot onto those shared utilities.

  • New shared modules: frame_prefetch.py, cuda_graph_dispatch.py, prewarm.py, overlap.py, encoder_lifecycle.py — each backed by CPU-only tests in flashdreams/tests/.
  • gRPC finalization race fix: WorldModelService replaces the threading.Event dual-wait/clear/start pattern with HostThreadOverlap gated by @_synchronized_method("_finalization_lock"), fully serializing render_video_chunk to prevent concurrent callers from racing into submit().
  • Consolidation: All three transformer variants (CosmosTransformer, Wan21Transformer, TemplateTransformer) and their integrations now share CUDAGraphDispatch.select()/reset() instead of duplicating the drain-vs-replay logic inline; _network_call/_network_call_uncond are kept as compatibility aliases for external diagnostic hooks.

Confidence Score: 5/5

Safe to merge; all previously flagged issues (prefetch exception recovery, copy=False protocol, control-flow inversion, gRPC finalization race) are addressed and the shared helpers are well-tested.

The extraction is clean: each new module centralises one responsibility, existing callers are migrated faithfully, and the CPU test suite covers the new helpers. Remaining notes are minor redundancies and an error-message regression, none of which affect runtime behaviour.

integrations/omnidreams/omnidreams/grpc/server.py — confirm the full-render serialisation matches the intended multi-session concurrency contract. flashdreams/flashdreams/recipes/template/transformer/init.py — diagnostic error message is less specific after the migration.

Important Files Changed

Filename Overview
flashdreams/flashdreams/infra/acceleration/overlap.py New SynchronousOverlap, HostThreadOverlap, and CudaStreamOverlap runners; HostThreadOverlap correctly uses a lock + Event pair; CudaStreamOverlap.submit() does a non-blocking 0 s check before starting new work.
integrations/omnidreams/omnidreams/grpc/server.py Replaces threading.Event finalization gate with HostThreadOverlap; adds @_synchronized_method to render_video_chunk, serializing all concurrent session renders — a correct fix for the previously-flagged race but with potential multi-session throughput implications.
flashdreams/flashdreams/infra/acceleration/frame_prefetch.py Shared CudaHostPrefetch and LazyCudaFrame with fixed exception-recovery path, correct NumPy 2.0 copy=False protocol, and a synchronize_source_event_on_host_copy option for rasterizer paths.
flashdreams/flashdreams/infra/acceleration/cuda_graph_dispatch.py New CUDAGraphDispatch consolidates drain-vs-replay selection across all transformer variants; reset() handles the build=False (TemplateTransformer) case correctly.
flashdreams/flashdreams/infra/acceleration/encoder_lifecycle.py Clean encoder lifecycle helpers; run_one_shot_encoder_stage correctly calls release() in a finally block so encoders are freed even on exception.
integrations/omnidreams/omnidreams/interactive_drive/world_model/flashdreams_adapter.py Control-flow priority in warmup_model correctly flipped; _LazyRGBFrame now subclasses the shared LazyCudaFrame.
flashdreams/flashdreams/infra/acceleration/prewarm.py Well-structured prewarm helpers with PrewarmDeadline tracking; deadlines checked before and after each step in run_prewarm_sequence.
integrations/omnidreams/omnidreams_singleview/python/optimized_dit.py Adds cuda_graph_dispatch.disable(fn=shape_ops) before nulling out the _network_call aliases.
integrations/omnidreams/omnidreams/pipeline.py Migrates release_text_and_image_encoders and precompute_embeddings to shared lifecycle helpers.
flashdreams/flashdreams/recipes/template/transformer/init.py Migrates to CUDAGraphDispatch with build=False; error message when _select_network is called before initialize_autoregressive_cache is now generic rather than context-specific.
flashdreams/flashdreams/recipes/wan/pipeline.py Migrates encoder setup/release to shared helpers; ensure_one_shot_encoder is called with a known-None first arg inside guards, which is redundant but harmless.

Reviews (8): Last reviewed commit: "Address realtime acceleration review fee..." | Re-trigger Greptile

Comment thread flashdreams/flashdreams/infra/acceleration/frame_prefetch.py
Comment thread flashdreams/flashdreams/infra/acceleration/frame_prefetch.py
Comment thread integrations/omnidreams/omnidreams/interactive_drive/presenter.py
Add an acceleration helper for CUDA-graph capture thresholds and
conditional/unconditional CUDAGraphWrapper dispatch. Migrate Wan, Cosmos,
Template, OmniDreams, and LingBot reset/dispatch paths to use the helper
while preserving existing compatibility attributes.

Also clear helper-owned graph wrappers when OmniDreams native FP8 releases
the PyTorch network so the previous memory-release behavior is preserved.
@jarcherNV

Copy link
Copy Markdown
Collaborator Author

/ok to test 338fb9e

@jarcherNV jarcherNV self-assigned this Jul 20, 2026
@jarcherNV

Copy link
Copy Markdown
Collaborator Author

/ok to test 338fb9e

Add shared acceleration helpers for timed model prewarm steps, CUDA graph
prewarm sequence counts, prewarm deadlines, and warmup-index exclusion.

Migrate OmniDreams interactive-drive model/session warmup timing and FlashVSR
distributed compile prewarm loops onto the shared helpers while keeping WebRTC
transport warmup separate.
Preserve the pipeline_factory warmup path when offload_text_encoder is enabled.
Only defer model construction for the non-factory offload path, matching the
original warmup semantics.
Add shared acceleration helpers for synchronous, host-thread, and CUDA-stream
overlap work. Migrate OmniDreams gRPC KV-cache finalization to the host-thread
runner while preserving the existing wait-before-next-request semantics.
Narrow the fake CUDA event before accessing test-only methods so the overlap
tests pass ty in the CPU CI lint job.
Add shared acceleration helpers for config-backed one-shot encoder setup,
tensor-to-CPU precompute results, and encoder release with CUDA cache cleanup.
Migrate Wan and OmniDreams encoder release paths plus the OmniDreams
interactive-drive offload path onto the shared helper.
@jarcherNV jarcherNV changed the title Extract shared frame prefetch acceleration helpers Extract shared realtime acceleration helpers Jul 20, 2026
Recover from failed lazy-frame prefetch materialization, expose the shared
frame-prefetch helpers from the acceleration package, and serialize the gRPC
render/finalization scheduling path to avoid concurrent overlap submissions.
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.

1 participant