Skip to content

perf(multimodal): NVTX ranges + encoder cache hit/miss metrics - #3

Draft
furionw wants to merge 2 commits into
mainfrom
qiwa/nvtx
Draft

perf(multimodal): NVTX ranges + encoder cache hit/miss metrics#3
furionw wants to merge 2 commits into
mainfrom
qiwa/nvtx

Conversation

@furionw

@furionw furionw commented May 2, 2026

Copy link
Copy Markdown
Owner

Why

We profile multimodal serving with nsys but the rep had no way to separate
per-stage cost: hashing, HF processor, cache lookup, encoder forward, and
ec_connector load/save all collapsed into one opaque region. Independently,
mm_caching_metrics only covered the host-side processor cache, so we had
no way to verify the GPU encoder cache (post-ViT embedding residency) was
working under sweep load. This PR adds NVTX ranges across the multimodal
pipeline and adds scheduler-level encoder-cache accounting so both surfaces
show up in nsys and in our metrics/log lines. Misses are recorded only
after allocate(), so inputs deferred by the encoder-compute budget don't
pollute the miss count.

Effect

LoggingStatLogger line, before / after:

... MM cache hit rate: 75.0%
... MM cache hits=300/400 (75.0%), Encoder cache hits=12/40 (30.0%)

New Prometheus counters: vllm:encoder_cache_queries, vllm:encoder_cache_hits.

What Change

  • NVTX ranges across hash branches, processor stages, vit_forward, and ec_connector load/save.
  • EncoderCacheStats + record_miss() on the encoder cache manager; scheduler emits per step.
  • New VLLM_MM_CACHE_PROBE env for per-invocation HIT/MISS probe logging.

Test Plan

  • Scheduler unit tests assert hit/miss counters increment correctly.
  • nsys profile of a dynamo_serve sweep — confirm mm:*, gpu_model_runner: vit_forward, ec_connector: * ranges visible.

@furionw
furionw changed the base branch from qiwa/v0.20.0 to releases/v0.20.1 May 2, 2026 23:21
Add NVTX ranges across the multimodal pipeline (hash branches,
processor stages, gpu_model_runner vit_forward, ec_connector load/save)
so per-stage cost is visible in nsys reps. Add scheduler-level encoder
cache hit/miss accounting via a new EncoderCacheStats aggregate, with
misses recorded only after allocate() so budget-deferred inputs don't
pollute the miss count. Surfaces through LoggingStatLogger and
Prometheus (vllm:encoder_cache_queries, vllm:encoder_cache_hits).
Adds VLLM_MM_CACHE_PROBE env for per-invocation HIT/MISS probe logging.
@furionw furionw changed the title Add NVTX and encoder cache accounting updates (v0.20) perf(multimodal): NVTX ranges + encoder cache hit/miss metrics May 5, 2026
@furionw
furionw changed the base branch from releases/v0.20.1 to main May 5, 2026 20:56
…_meta

The previous vit_forward NVTX range wrapped the entire _execute_mm_encoder
call, which meant the per-cold-miss save loop (maybe_save_ec_to_connector
-> save_d2h) was nested inside it. In nsys analysis the marker reported
real_ViT + save_d2h, requiring manual subtraction to see the cache-hit
benefit.

Split the markers so they are disjoint siblings under preprocess:

  preprocess
  |- ec_connector: load (incl. load_h2d)
  |- vit_forward            <-- now ONLY the encoder GPU work
  |- ec_connector: save (incl. save_d2h)
  |- gather_mm_embeddings   <-- NEW marker
  |- embed_input_ids / _prepare_mm_inputs

Side effect: vit_forward count drops from "every step" to "only steps
that ran the encoder" (no-mm-input and all-cache-hit steps no longer
emit the marker). This is the desired semantics; analysis scripts that
assumed count == step count need updating.

Also add per-step token telemetry to correlate forward duration with
prefill/decode batch shape:

- Python log line: 'step_tokens step=N prefill=P decode=D total=T num_reqs=R'
  emitted at DEBUG every step, INFO every 50 steps.
- Zero-duration NVTX range 'step_meta: prefill=P decode=D total=T reqs=R'
  joinable with the forward marker by globalTid + timestamp.

Mechanism mirrors the existing prefill-detection pattern in this file
(num_computed_tokens_cpu < num_prompt_tokens_cpu); no change to scheduler
or model behavior.

Co-authored-by: Claude
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