[Enhancement] Add cache-dit force_refresh support for Helios and GLM-Image#2
[Enhancement] Add cache-dit force_refresh support for Helios and GLM-Image#2SamitHuang wants to merge 24 commits into
Conversation
Signed-off-by: samithuang <285365963@qq.com>
Signed-off-by: samithuang <285365963@qq.com>
Two optimizations that eliminate ~6.5s of IPC serialization overhead for single-stage diffusion pipelines (e.g. Wan2.2 I2V/T2V) in online serving mode: Phase 1 – Inline diffusion (eliminate Hop3): When there is exactly one diffusion stage in async mode, initialize OmniDiffusion directly in the orchestrator process instead of spawning a stage worker subprocess. This removes the entire Hop3 serialization path (pickle + mp.Queue/SHM) between the stage worker and orchestrator. GPU workers for tensor parallelism are still spawned by DiffusionExecutor. Phase 2 – SHM tensor transfer (optimize Hop1): Replace pickle-based serialization of large tensors through MessageQueue with POSIX shared memory. The worker copies tensor data into a named SHM segment and enqueues only lightweight metadata; the scheduler reconstructs the tensor from SHM. This reduces Hop1 overhead from ~3.4s to ~1.5s. Measured on Wan2.2-I2V-A14B (TP=2, 1280x720, 5s@16fps, 1 step): Before: e2e = 37.5s Phase 1: e2e = 33.1s (−4.4s) Phase 2: e2e = 31.0s (−2.1s) Total: e2e = 31.0s (−6.5s, −17.5%) Made-with: Cursor Signed-off-by: samithuang <285365963@qq.com>
…17.5%) perf: reduce IPC overhead for single-stage diffusion serving (~6.5s, 17.5%)
Signed-off-by: Samit <285365963@qq.com>
Signed-off-by: samithuang <285365963@qq.com>
Signed-off-by: samithuang <285365963@qq.com>
Signed-off-by: Samit <285365963@qq.com>
Signed-off-by: samithuang <285365963@qq.com>
Upgrade cache-dit dependency to the latest release (1.3.0). All existing imports and APIs remain compatible. Verified with Qwen-Image offline inference showing ~2x speedup with cache-dit acceleration. Signed-off-by: yx <yx@users.noreply.github.com> Made-with: Cursor Signed-off-by: samithuang <285365963@qq.com>
…Image Add force_refresh_step_hint and force_refresh_step_policy to DiffusionCacheConfig and wire them through to DBCacheConfig. Register custom cache-dit enablers for HeliosPipeline, HeliosPyramidPipeline, and GlmImagePipeline. - Helios: multi-chunk denoise loop requires cache reset between chunks, so force_refresh_step_hint defaults to num_inference_steps and force_refresh_step_policy defaults to "repeat". - GLM-Image: editing mode preprocesses input image in one extra transformer call; force_refresh_step_hint=1 discards stale state. Signed-off-by: yx <yx@users.noreply.github.com> Made-with: Cursor Signed-off-by: samithuang <285365963@qq.com>
Summary of ChangesHello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request focuses on enhancing the capabilities and performance of vLLM-Omni. It introduces cache management improvements for diffusion models, expands the functionality of the ComfyUI extension with video generation support, and adds comprehensive benchmarking for Qwen3-TTS. Additionally, it refactors and improves the CI/CD pipeline. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request adds support for force_refresh in cache-dit for Helios and GLM-Image models, which is a valuable enhancement. The changes to DiffusionCacheConfig and the new model-specific enablers are well-aligned with the goal.
However, I've identified a critical bug in both new enabler functions (enable_cache_for_helios and enable_cache_for_glm_image). When creating a refreshed cache context, the code incorrectly uses DBCacheConfig().reset() instead of basing the new configuration on the existing one. This causes all original cache settings (like Fn_compute_blocks, max_warmup_steps, etc.) to be lost and reset to defaults, which will lead to incorrect caching behavior. I've provided suggestions to fix this.
Additionally, there's an opportunity to refactor duplicated code between the two new enabler functions to improve maintainability.
| hint = cache_config.force_refresh_step_hint | ||
| if hint is None: | ||
| hint = num_inference_steps | ||
| policy = cache_config.force_refresh_step_policy | ||
| if policy == "once": | ||
| policy = "repeat" | ||
| if cache_config.scm_steps_mask_policy is None: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| force_refresh_step_hint=hint, | ||
| force_refresh_step_policy=policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) | ||
| else: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| force_refresh_step_hint=hint, | ||
| force_refresh_step_policy=policy, | ||
| steps_computation_mask=cache_dit.steps_mask( | ||
| mask_policy=cache_config.scm_steps_mask_policy, | ||
| total_steps=num_inference_steps, | ||
| ), | ||
| steps_computation_policy=cache_config.scm_steps_policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) | ||
|
|
There was a problem hiding this comment.
There's a critical issue in refresh_cache_context. Using DBCacheConfig().reset(...) creates a new configuration from defaults, which causes all the original cache settings (like Fn_compute_blocks, max_warmup_steps, etc.) from db_cache_config to be lost. This will lead to incorrect and inefficient caching behavior.
The fix is to use db_cache_config.reset(...) to ensure the refreshed configuration is based on the original settings. I've also refactored the logic slightly to remove duplication within the function.
hint = cache_config.force_refresh_step_hint
if hint is None:
hint = num_inference_steps
policy = cache_config.force_refresh_step_policy
if policy == "once":
policy = "repeat"
reset_kwargs = {
"num_inference_steps": num_inference_steps,
"force_refresh_step_hint": hint,
"force_refresh_step_policy": policy,
}
if cache_config.scm_steps_mask_policy is not None:
reset_kwargs["steps_computation_mask"] = cache_dit.steps_mask(
mask_policy=cache_config.scm_steps_mask_policy,
total_steps=num_inference_steps,
)
reset_kwargs["steps_computation_policy"] = cache_config.scm_steps_policy
# Use db_cache_config.reset to preserve the original cache settings
# when creating the refreshed configuration.
refreshed_config = db_cache_config.reset(**reset_kwargs)
cache_dit.refresh_context(
pipeline.transformer,
cache_config=refreshed_config,
verbose=verbose,
)| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| steps_computation_mask=cache_dit.steps_mask( | ||
| mask_policy=cache_config.scm_steps_mask_policy, | ||
| total_steps=num_inference_steps, | ||
| ), | ||
| steps_computation_policy=cache_config.scm_steps_policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) |
There was a problem hiding this comment.
Similar to the issue in the Helios enabler, this else block has a critical bug. By using DBCacheConfig().reset(...), you are creating a new cache configuration from defaults whenever SCM is enabled. This discards all the original settings from db_cache_config, including Fn_compute_blocks, max_warmup_steps, and the force_refresh_step_hint that is crucial for GLM-Image.
The fix is to base the refreshed configuration on the existing db_cache_config by using db_cache_config.reset(...).
else:
# Use db_cache_config.reset to preserve original settings
refreshed_config = db_cache_config.reset(
num_inference_steps=num_inference_steps,
steps_computation_mask=cache_dit.steps_mask(
mask_policy=cache_config.scm_steps_mask_policy,
total_steps=num_inference_steps,
),
steps_computation_policy=cache_config.scm_steps_policy,
)
cache_dit.refresh_context(
pipeline.transformer,
cache_config=refreshed_config,
verbose=verbose,
)| def enable_cache_for_helios(pipeline: Any, cache_config: Any) -> Callable[[int], None]: | ||
| """Enable cache-dit for Helios pipeline (multi-chunk denoise loop). | ||
|
|
||
| Helios splits num_frames into multiple chunks and runs multiple passes of the | ||
| transformer denoise loop. The cache context must be refreshed at the end of each | ||
| loop to prevent stale cache from the previous chunk leaking into the next one. | ||
| This is achieved by setting force_refresh_step_hint = num_inference_steps with | ||
| force_refresh_step_policy = "repeat". | ||
| """ | ||
| db_cache_config = _build_db_cache_config(cache_config) | ||
|
|
||
| calibrator_config = None | ||
| if cache_config.enable_taylorseer: | ||
| calibrator_config = TaylorSeerCalibratorConfig(taylorseer_order=cache_config.taylorseer_order) | ||
| logger.info(f"TaylorSeer enabled with order={cache_config.taylorseer_order}") | ||
|
|
||
| logger.info( | ||
| f"Enabling cache-dit on Helios transformer: " | ||
| f"Fn={db_cache_config.Fn_compute_blocks}, " | ||
| f"Bn={db_cache_config.Bn_compute_blocks}, " | ||
| f"W={db_cache_config.max_warmup_steps}, " | ||
| f"force_refresh_step_policy={db_cache_config.force_refresh_step_policy}, " | ||
| ) | ||
|
|
||
| cache_dit.enable_cache( | ||
| pipeline.transformer, | ||
| cache_config=db_cache_config, | ||
| calibrator_config=calibrator_config, | ||
| ) | ||
|
|
||
| def refresh_cache_context(pipeline: Any, num_inference_steps: int, verbose: bool = True) -> None: | ||
| hint = cache_config.force_refresh_step_hint | ||
| if hint is None: | ||
| hint = num_inference_steps | ||
| policy = cache_config.force_refresh_step_policy | ||
| if policy == "once": | ||
| policy = "repeat" | ||
| if cache_config.scm_steps_mask_policy is None: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| force_refresh_step_hint=hint, | ||
| force_refresh_step_policy=policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) | ||
| else: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| force_refresh_step_hint=hint, | ||
| force_refresh_step_policy=policy, | ||
| steps_computation_mask=cache_dit.steps_mask( | ||
| mask_policy=cache_config.scm_steps_mask_policy, | ||
| total_steps=num_inference_steps, | ||
| ), | ||
| steps_computation_policy=cache_config.scm_steps_policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) | ||
|
|
||
| return refresh_cache_context | ||
|
|
||
|
|
||
| def enable_cache_for_glm_image(pipeline: Any, cache_config: Any) -> Callable[[int], None]: | ||
| """Enable cache-dit for GLM-Image pipeline. | ||
|
|
||
| GLM-Image processes prompt and image by calling the transformer before the | ||
| denoising loop. When an input image is provided (editing mode), the cache must | ||
| be force-refreshed after the preprocessing step so stale hidden states are | ||
| discarded. Set force_refresh_step_hint = 1 for editing, None for text-to-image. | ||
| """ | ||
| db_cache_config = _build_db_cache_config(cache_config) | ||
|
|
||
| calibrator_config = None | ||
| if cache_config.enable_taylorseer: | ||
| calibrator_config = TaylorSeerCalibratorConfig(taylorseer_order=cache_config.taylorseer_order) | ||
| logger.info(f"TaylorSeer enabled with order={cache_config.taylorseer_order}") | ||
|
|
||
| logger.info( | ||
| f"Enabling cache-dit on GLM-Image transformer: " | ||
| f"Fn={db_cache_config.Fn_compute_blocks}, " | ||
| f"Bn={db_cache_config.Bn_compute_blocks}, " | ||
| f"W={db_cache_config.max_warmup_steps}, " | ||
| f"force_refresh_step_hint={db_cache_config.force_refresh_step_hint}, " | ||
| ) | ||
|
|
||
| cache_dit.enable_cache( | ||
| pipeline.transformer, | ||
| cache_config=db_cache_config, | ||
| calibrator_config=calibrator_config, | ||
| ) | ||
|
|
||
| def refresh_cache_context(pipeline: Any, num_inference_steps: int, verbose: bool = True) -> None: | ||
| if cache_config.scm_steps_mask_policy is None: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| num_inference_steps=num_inference_steps, | ||
| verbose=verbose, | ||
| ) | ||
| else: | ||
| cache_dit.refresh_context( | ||
| pipeline.transformer, | ||
| cache_config=DBCacheConfig().reset( | ||
| num_inference_steps=num_inference_steps, | ||
| steps_computation_mask=cache_dit.steps_mask( | ||
| mask_policy=cache_config.scm_steps_mask_policy, | ||
| total_steps=num_inference_steps, | ||
| ), | ||
| steps_computation_policy=cache_config.scm_steps_policy, | ||
| ), | ||
| verbose=verbose, | ||
| ) | ||
|
|
||
| return refresh_cache_context | ||
|
|
There was a problem hiding this comment.
There is significant code duplication between enable_cache_for_helios and enable_cache_for_glm_image. The logic for building db_cache_config, setting up calibrator_config, logging, and calling cache_dit.enable_cache is nearly identical.
To improve maintainability and reduce redundancy, consider extracting this common setup logic into a shared helper function. This would make the code easier to manage and prevent potential inconsistencies in the future.
Add --cache-backend and --enable-cache-dit-summary CLI arguments to the GLM-Image offline inference example, enabling cache-dit acceleration for the diffusion stage. Signed-off-by: yx <yx@users.noreply.github.com> Made-with: Cursor Signed-off-by: samithuang <285365963@qq.com>
Made-with: Cursor Signed-off-by: samithuang <285365963@qq.com>
Signed-off-by: Samit <285365963@qq.com>
Signed-off-by: Didan Deng <33117903+wtomin@users.noreply.github.com>
Purpose
Add
force_refresh_step_hintandforce_refresh_step_policysupport fromcache-dit1.3.0 for Helios and GLM-Image models, aligning with the cache-dit example usage. Also adds--cache-backendCLI support to the GLM-Image end2end example script.Why these models need special handling
Helios (HeliosPipeline, HeliosPyramidPipeline): Uses a multi-chunk denoise loop where num_frames are split into overlapping chunks. Each chunk goes through the full denoising step loop. Without force-refresh, stale cache from the previous chunk leaks into the next. The fix sets
force_refresh_step_hint = num_inference_stepswithforce_refresh_step_policy = "repeat"so the cache is reset at the boundary of each chunk.GLM-Image (GlmImagePipeline): In editing mode, the transformer is called once to process the input image before the denoising loop begins. Setting
force_refresh_step_hint = 1ensures the cache is force-refreshed after this preprocessing call, discarding stale hidden states before actual denoising. For text-to-image mode,force_refresh_step_hint = None(no force refresh needed).Changes
vllm_omni/diffusion/data.py: Addedforce_refresh_step_hintandforce_refresh_step_policyfields toDiffusionCacheConfigvllm_omni/diffusion/cache/cache_dit_backend.py:_build_db_cache_config()toDBCacheConfigenable_cache_for_helios()custom enablerenable_cache_for_glm_image()custom enablerCUSTOM_DIT_ENABLERSexamples/offline_inference/glm_image/end2end.py: Added--cache-backendand--enable-cache-dit-summaryCLI argumentsDependency
This PR depends on vllm-project/vllm-omni#1834 (cache-dit 1.3.0 upgrade) being merged first.
Test Plan
Test Commands (GLM-Image)
Test Result
Benchmark on dual NVIDIA H800 GPUs (AR on GPU 1, Diffusion on GPU 6), GLM-Image T2I, 1024x1024, 50 steps:
Cache-dit DBCache config:
F1B0_W4_threshold=0.24_MC3Note: The total generation time is dominated by the AR stage (~27s), so the diffusion-stage speedup (~3x) translates to a more modest ~1.28x end-to-end speedup. For workloads with longer diffusion steps or batch processing, the speedup would be more pronounced.
Cache-dit summary (from the accelerated run):
Essential Elements of an Effective PR Description Checklist