Skip to content

fix(qwen3-vl): bound CUDA graph caches - #125

Merged
LiangSu8899 merged 4 commits into
flashrt-project:mainfrom
heiheiha798:fix/qwen3-vl-graph-cache-management
Jul 1, 2026
Merged

LiangSu8899 merged 4 commits into
flashrt-project:mainfrom
heiheiha798:fix/qwen3-vl-graph-cache-management

Conversation

@heiheiha798

@heiheiha798 heiheiha798 commented Jul 1, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #122.

This PR adds bounded CUDA Graph cache management for all current Qwen3-VL frontends in the repo:

  • Qwen3VlTorchFrontendRtx (SM120/NVFP4 multimodal path)
  • Qwen3VlTorchFrontendRtxBF16 (Orin SM87 BF16 multimodal path)
  • Qwen3VlFp8Sm89TextFrontend (SM89 FP8 text path)
  • Qwen3VlFp8Sm89Frontend (SM89 FP8 multimodal wrapper)

The change replaces unbounded process-local graph dictionaries with LRU-bounded OrderedDict caches, adds public clear_graphs() APIs, and exposes lightweight graph_cache_stats() bucket diagnostics. Prefill graph eviction also drops the corresponding staged/static input buffers so graph entries and buffer residency stay in sync.

Decode graph caches that bake a prompt-dependent RoPE position now key by (cache_pos, rope_pos), avoiding reuse of a graph captured for a different MRoPE continuation position.

The default cap is 256 entries per cache. It can be overridden with:

  • FLASHRT_QWEN3_VL_PREFILL_GRAPH_CACHE_MAX
  • FLASHRT_QWEN3_VL_DECODE_GRAPH_CACHE_MAX

Values <= 0 preserve legacy unbounded behavior for callers that intentionally want it.

Scope

Runtime graph-cache bookkeeping only. This does not change model numerics, kernels, dtype policy, dispatch policy, graph-capture bodies, launch parameters, CMake, or pybind bindings.

Validation

Environment:

  • Python test environment with FlashRT dependencies installed
  • Python tests only; no real checkpoint required for the graph-cache regression coverage

Commands:

PYTHONPATH=. PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 pytest -q \
  tests/test_qwen3_vl_graph_cache.py \
  tests/test_qwen3_vl_rtx_bf16.py \
  tests/test_qwen3_vl_fp8_sm89.py \
  tests/test_qwen3_vl_fp8_sm89_2b.py \
  tests/test_qwen3_vl_smoke.py
python -m compileall -q \
  flash_rt/frontends/torch/qwen3_vl_rtx.py \
  flash_rt/frontends/torch/qwen3_vl_rtx_bf16.py \
  flash_rt/frontends/torch/qwen3_vl_fp8_sm89.py \
  flash_rt/frontends/torch/qwen3_vl_fp8_sm89_multimodal.py \
  tests/test_qwen3_vl_graph_cache.py \
  tests/test_qwen3_vl_rtx_bf16.py \
  tests/test_qwen3_vl_fp8_sm89.py \
  tests/test_qwen3_vl_fp8_sm89_2b.py \
  tests/test_qwen3_vl_smoke.py
git diff --check
rg -n "_decode_graphs\\s*:\\s*dict|_prefill_graphs\\s*:\\s*dict|_pg_buffers\\s*:\\s*dict|_decode_graphs\\s*=\\s*\\{\\}|_prefill_graphs\\s*=\\s*\\{\\}|_pg_buffers\\s*=\\s*\\{\\}" flash_rt/frontends/torch/qwen3_vl*.py tests/test_qwen3_vl_graph_cache.py

Results:

  • Qwen3-VL Python tests above: 31 passed, 1 skipped
  • compileall: passed
  • git diff --check: passed
  • Plain unbounded Qwen3-VL graph-cache dict declaration scan: no matches

Not Run

  • Real-checkpoint SM87 BF16 Qwen3-VL smoke.
  • Real-checkpoint SM89 Qwen3-VL smoke.
  • Real-checkpoint SM120/NVFP4 Qwen3-VL smoke.

Those are useful integration checks for CUDA Graph capture/replay on hardware, but the regression tests in this PR intentionally isolate the cache-management bug without requiring checkpoints or real CUDA Graph capture.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds bounded (LRU) CUDA Graph cache management to the Qwen3-VL Torch frontends to prevent unbounded graph growth in long-running processes, aligning Qwen3-VL behavior with existing bounded-cache patterns elsewhere in FlashRT.

Changes:

  • Replace unbounded decode/prefill graph dictionaries with OrderedDict-backed LRU caches, with configurable caps via env vars / constructor params.
  • Add public clear_graphs() and graph_cache_stats() APIs to aid operational control and debugging.
  • Add CI-friendly regression tests that validate LRU eviction and buffer/graph cache synchronization.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_qwen3_vl_graph_cache.py New regression tests covering LRU eviction, buffer eviction coupling, stats, and clear behavior.
tests/test_qwen3_vl_fp8_sm89.py Extends import/signature smoke checks to cover new graph-cache parameters and APIs.
flash_rt/frontends/torch/qwen3_vl_rtx.py Implements bounded prefill/decode graph caches, adds clear_graphs() and graph_cache_stats(), and keeps staged buffers in sync on eviction.
flash_rt/frontends/torch/qwen3_vl_fp8_sm89.py Adds bounded decode graph cache + stats/clear APIs and a new max_decode_graphs constructor parameter.
flash_rt/frontends/torch/qwen3_vl_fp8_sm89_multimodal.py Adds bounded prefill/decode graph caches for the multimodal wrapper, plus clear/stats APIs (including delegating to text frontend).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +156 to +158
import torch
monkeypatch.setattr(torch.cuda, "current_stream",
lambda: _FakeStream(), raising=False)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Fixed in the latest push by monkeypatching torch.cuda.synchronize to a no-op in this CI-friendly test, matching the other mocked CUDA surface.

@heiheiha798
heiheiha798 force-pushed the fix/qwen3-vl-graph-cache-management branch from f8d0403 to 94a16b2 Compare July 1, 2026 15:49
@LiangSu8899
LiangSu8899 merged commit 94465a5 into flashrt-project:main Jul 1, 2026
@heiheiha798
heiheiha798 deleted the fix/qwen3-vl-graph-cache-management branch July 2, 2026 03:32
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.

Add CUDA Graph cache management to Qwen3-VL frontends

3 participants