Repository navigation
fix: vllm forwardpass metric for async scheduling - #7537
Conversation
Extend AsyncScheduler instead of Scheduler so the InstrumentedScheduler works correctly with vLLM's default async scheduling mode. Without output placeholders the async engine produces partial batches (e.g. 22/28 split of 50 requests). Additional changes: - Remove schedule() override; emit metrics in update_from_output() using the scheduler_output parameter directly (always correct in both modes). - Measure wall_time as interval between consecutive update_from_output() calls (approximates GPU forward pass time). - Skip empty batches (total_num_scheduled_tokens == 0) and reset wall_time on idle transitions. - Add --save-plot <path.png> to recv_forward_pass_metrics.py for visualizing FPM time-series data. Signed-off-by: hongkuanz <[email protected]>
WalkthroughTwo files updated: one adds optional CLI flag for saving ForwardPassMetrics plots on exit, implementing in-memory metric recording with matplotlib-based visualization; the other refactors instrumented scheduler to use AsyncScheduler base class with revised wall-time computation and simplified metric publishing logic. Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~50 minutes 🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment Tip You can customize the high-level summary generated by CodeRabbit.Configure the |
There was a problem hiding this comment.
Actionable comments posted: 1
🧹 Nitpick comments (1)
components/src/dynamo/common/recv_forward_pass_metrics.py (1)
108-110: MoveFpmEventSubscriberback to module scope.This import is not behind an optional code path, so moving it into
run()only defers failures until execution and violates the repo's import rule. Ifdynamo.llmis intentionally optional here, make that explicit; otherwise import it with the rest of the module imports.As per coding guidelines, keep all import statements at the top of the file; imports inside functions should be flagged unless an explicit optional-dependency exception applies.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@components/src/dynamo/common/recv_forward_pass_metrics.py` around lines 108 - 110, The import of FpmEventSubscriber is moved into run(), which defers import-time failures and violates the module-import rule; move the line "from dynamo.llm import FpmEventSubscriber" back to module scope with the other imports (or, if dynamo.llm truly is optional, add explicit optional-dependency handling and document it), updating the top of the file so FpmEventSubscriber is imported at import time rather than inside the run() function.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@components/src/dynamo/common/recv_forward_pass_metrics.py`:
- Around line 24-32: Move the plotting imports and backend selection into the
lazy helper: remove top-level imports of matplotlib and matplotlib.pyplot and
instead call matplotlib.use("Agg") immediately inside _save_plot() just before
importing matplotlib.pyplot so the backend is set before pyplot is loaded; keep
msgspec and other existing module imports at top. Also move the unconditional
import of FpmEventSubscriber out of run() to the module-level imports (alongside
ForwardPassMetrics and DistributedRuntime) so FpmEventSubscriber is imported at
file top and not inside run(). Ensure references to _save_plot() and
FpmEventSubscriber continue to work after the change.
---
Nitpick comments:
In `@components/src/dynamo/common/recv_forward_pass_metrics.py`:
- Around line 108-110: The import of FpmEventSubscriber is moved into run(),
which defers import-time failures and violates the module-import rule; move the
line "from dynamo.llm import FpmEventSubscriber" back to module scope with the
other imports (or, if dynamo.llm truly is optional, add explicit
optional-dependency handling and document it), updating the top of the file so
FpmEventSubscriber is imported at import time rather than inside the run()
function.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 471a11aa-3661-4f64-b636-49f304588aa0
📒 Files selected for processing (2)
components/src/dynamo/common/recv_forward_pass_metrics.pycomponents/src/dynamo/vllm/instrumented_scheduler.py
Signed-off-by: hongkuanz <[email protected]> Signed-off-by: WenjiaoYue <[email protected]>
Signed-off-by: hongkuanz <[email protected]>

Summary
InstrumentedSchedulerto work correctly with vLLM's default async scheduling mode by extendingAsyncSchedulerinstead ofScheduler.schedule()override, usescheduler_outputparameter directly, measurewall_timeas interval between consecutiveupdate_from_output()calls.--save-plot <path.png>torecv_forward_pass_metrics.pyfor visualizing FPM time-series data.Reviewer guide
Background: sync vs async scheduling in vLLM
vLLM 0.16+ defaults to async scheduling (
async_scheduling=True), where the engine overlaps CPU scheduling with GPU execution viastep_with_batch_queue. This meansschedule()is called twice before the firstupdate_from_output():schedule(N)-> submit to GPU -> return early (don't wait)schedule(N+1)-> submit -> pop batch N -> block for GPU(N) ->update_from_output(N)AsyncSchedulerhandles this by adding output placeholders in_update_after_schedule(), keepingnum_new_tokens == 1for all running requests so the secondschedule()can schedule them again.The bug (before this PR)
InstrumentedSchedulerextendedScheduler(no placeholders). In async mode, the secondschedule()sawnum_new_tokens == 0for all requests advanced by_update_after_schedule, producing partial batches (e.g. 22/28 split of 50 requests). This madenum_decode_requests,sum_decode_kv_tokens, andwall_timeall incorrect.Additionally, the old code saved
_pending_outputinschedule()and read it inupdate_from_output(). In async mode, the secondschedule()overwrote_pending_outputbefore the firstupdate_from_output()could read it (state corruption).The fix
AsyncScheduler— output placeholders ensure all requests are scheduled every step, no partial batches.schedule()override — no pending state to save. Use thescheduler_outputparameter passed toupdate_from_output()directly (always correct, even in async mode).future.result()right before callingupdate_from_output(), so the interval between consecutive calls approximates GPU forward pass time.total_num_scheduled_tokens == 0means no real work; reset_last_update_timeon idle.Files changed
instrumented_scheduler.pyAsyncScheduler, rewriteupdate_from_output(), removeschedule()override, add detailed module docstringrecv_forward_pass_metrics.py--save-plot <path.png>CLI arg for 5-panel time-series visualizationHow to test
After aiperf finishes, Ctrl+C Terminal 2. Check:
num_decode_requestsreaches 50 at steady state (not 22/28 split)wall_time> 0 during active load, 0.0 on first messagefpm_metrics.pngshows the 5-panel plotAlso test with
--no-async-schedulingadded to Terminal 1 to verify sync mode works identically.Made with Cursor
Summary by CodeRabbit
New Features
--save-plotto export metric visualizations as PNG files on process exit.Refactor