Skip to content

Collect model input after cadence pacing - #573

Open
ZenAlexa wants to merge 18 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/543-api-cleanup-investigate-the-large-input-to-model-step
Open

ZenAlexa wants to merge 18 commits into
NVIDIA:mainfrom
ZenAlexa:contrib/543-api-cleanup-investigate-the-large-input-to-model-step

Conversation

@ZenAlexa

@ZenAlexa ZenAlexa commented Sep 3, 2026 •

Copy link
Copy Markdown

November 16 mainline integration

Merged main@5b23817a1edd into 85439c3d3ae8 through a normal merge. The three contribution source and test files retain their previous contents. The eight existing skill metadata checks passed. Runtime, GPU and end-to-end latency checks were not rerun for this documentation-only mainline delta. Earlier runtime measurements remain tied to their recorded revisions.

Why

Input that arrives during cadence pacing should reach the upcoming model step. A reset during that wait should also select the new generation before the step starts. Addresses #543.

Changes

  • Keep the existing message batch before pacing. Refresh user input afterward through the same event-reader cursor.
  • Use the existing rank-zero input broadcast and readiness agreements so every model rank enters the same step or stops together.
  • Preserve receipt timestamps from both reads for IProfiler. Discard buffered timing and input samples when the final synchronized generation changes.
  • Keep a stop after final admission at the next boundary, allowing every rank to finish the committed step. Update the existing stop-injection fixture to that final admission point.

Merged main 1448d5a1 into c073b056. The profiler callbacks follow the interface added in #634. Shutdown settlement remains outside this change.

Current validation (2026-11-01)

Revision 130b4c016211 already contains main 9d98934d9652, so no additional merge or code change was needed. The post-pacing read, reset generation and distributed readiness agreements retain their existing behavior.

On macOS arm64 with Python 3.12.14, PyTorch 2.9.1, NumPy 2.4.6, pytest 9.2.0, aiortc 1.15.0 and aiohttp 3.14.5, the actual V2 runtime and profiler suite passed 546 tests with four tests outside the ci_cpu selection. No selected cases failed or skipped. The separate existing step-agreement suite passed 19 tests, including two-process Gloo execution. This environment satisfies the exercised dependencies' declared version ranges and differs from the complete Linux lockfile matrix. Scoped Ruff 0.12.7 import-order and formatting checks, Python syntax and contribution whitespace checks passed.

GPU generation, native presentation, browser display and end-to-end latency were not rerun. Earlier performance and device evidence retain their recorded revisions.

Earlier validation

On c073b056, macOS arm64 with Python 3.12.14 and PyTorch 2.14.1:

  • 394 CPU tests passed with four deselected across the v2 runtime, profiler and step-agreement suites. All 66 profiler cases ran with the null-model and red-screen integrations available.
  • Six separate two-process Gloo scenarios passed for fresh input, reset, close, one-rank reset failure, one-rank pacing failure and a stop after admission. Each model step used a real all_reduce.
  • A separate profiler scenario checked fresh input during pacing and a reset after buffered output. Current main misses both fresh inputs. This revision consumes them in the upcoming step and drops the previous generation's buffered sample.
  • Ruff 0.12.7 import and formatting checks and git diff --check passed.
uv run pytest -m ci_cpu flashdreams/test_v2 flashdreams/tests/test_profiler.py tests/test_step_agreement.py

Earlier isolated CPU measurements

The earlier comparison against main fd52f1a1 used three fresh-process pairs. These measurements were not rerun for the profiler merge.

measurement main earlier patch
protocol-loop time per step, median after 50 warmup and 2,000 measured steps 311.8 µs 563.7 µs
event timestamp to rank-zero model-step entry, median at 30 hz with input 10 ms into pacing 58.119 ms 22.085 ms
step receiving the event, counting from zero 2 1

The extra broadcast and readiness reduction cost about 252 µs per step in that isolated CPU run. The fresh read removes one 33.3 ms scheduling interval from the event path. Multi-rank GPU generation and model end-to-end latency remain unmeasured.

Earlier main integration (2026-10-23)

Merged main cb4f8527 into 4acae025, retaining the 0.2 release and packaging changes. The contribution implementation is unchanged.

On macOS arm64 with Python 3.12.14 and PyTorch 2.9.1, the V2, profiler and two-process Gloo suite completed with 511 passed, one failed and four deselected. The failed step-failure scenario could not write its rank result because the local disk was full, then reached its process deadline. After freeing space, the same scenario passed in 10.16 seconds. The independent source-loaded cadence/reset scenario also consumed the new input at the next step and discarded the old generation’s buffered timing.

GPU generation, native presentation, browser display and end-to-end latency were not rerun. Earlier performance measurements retain their recorded revisions. Contribution whitespace checks passed.

Project CI: Please run the current-head multi-rank GPU generation and model latency checks on the project runners. The CPU cadence, event-buffer, and Gloo agreement results above are ready for review.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Copilot AI lite review requested due to automatic review settings September 3, 2026 14:19
@copy-pr-bot

copy-pr-bot Bot commented Sep 3, 2026

Copy link
Copy Markdown

This pull request requires additional validation before any workflows can run on NVIDIA's runners.

Pull request vetters can view their responsibilities here.

Contributors can view more details about this message here.

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@greptile-apps

greptile-apps Bot commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Confidence Score: 5/5 · The PR appears safe to merge; no new actionable issue was established.RetriggerView in GreptileConfidence Score: 5/5

[Medium impact] The PR appears safe to merge; no new actionable issue was established.

Summary

The model loop now reads fresh input after cadence pacing, so input and resets received during the wait can reach the upcoming step.

  • The model step now uses input that arrives during cadence pacing.

All supplied previous threads are resolved and unnumbered, so they receive no numbered finding entries. Tests were not rerun during this review.

Diagram

%%{init: {'theme': 'neutral'}}%%
flowchart TD
  A[Check whether ranks should stop] --> B[Read input and run queued messages]
  B --> C[Wait for cadence]
  C --> D[Agree preparation is complete]
  D --> E[Read fresh input and apply reset]
  E --> F[Agree to run the step]
  F --> G[Discard earlier generation timing]
  G --> H[Run model step]
  H --> I[Publish output or keep buffered timing]
Loading

Reviews (18) · Last reviewed commit: "Merge main into the contribution branch" · Reviewed by Greptile

Comment thread flashdreams/flashdreams/api_v2/loop.py Resolved
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Comment thread flashdreams/flashdreams/api_v2/loop.py Resolved
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@gtong-nv

gtong-nv commented Sep 3, 2026

Copy link
Copy Markdown
Collaborator

The model loop snapshots EventBuffer before _pace(). Input arriving during that cadence wait reaches the following model step, adding up to one configured step interval.

Thanks @ZenAlexa , this is indeed an issue. With our current design, we need to do two paces for the model loop and UI loop.

[[collect events] -> [run] -> [model pace for BACKPRESSUE]  -> [present] -> [UI/present pace for PRESENTATION MODE]] -> [[collect events]

Your PR should address issue with the model pace order

read events A
    |
    +------ model rate-limit wait ------+
                                        |
                 event B arrives here --+--> not included
                                        |
                              model.step(N, A)

But model pace will only happen when BLOCK mode is used in BACKPRESSUE, and happens when model generation is faster than UI rate (which defaults to 60hz), which is rare.
I would suggest clear the PR to only address this issue.
The other changes listed below, don't seem to be relevant

make finished-loop settlement atomic with both reset generation and asynchronous message acceptance
execute every message accepted before the terminal cutoff as one finite batch, then resume generation when that batch reopens model state

Keep event collection immediately after model pacing.
Restore the terminal lifecycle path for separate follow-up.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Author

Yep, I agree on keeping this PR tight 👍

One detail I found while tracing it: _pace() is currently driven by frames_per_second_for_step on every model-loop iteration. BackpressureMode.BLOCK adds a separate wait when the presentation queue fills. The ordering issue therefore exists across both modes, and its visible cost is largest when pacing actually sleeps.

I’ve trimmed #573 down to the ordering change and one focused regression. The terminal message settlement is a real lifecycle issue with its own boundary, so I’ve taken it out of this PR and will keep that work separate.

…anup-investigate-the-large-input-to-model-step

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

# Conflicts:
#	flashdreams/flashdreams/api_v2/loop.py
@ZenAlexa

ZenAlexa commented Sep 3, 2026

Copy link
Copy Markdown
Author

Caught up with #548's multi-session lifecycle in 8e174e70.

The model loop now reads once before cadence for lifecycle and finished-state decisions, then folds in one more event-buffer snapshot after cadence before the step. Queued state messages keep their once-per-model-step ordering. The focused CPU suite passes all 61 tests (•̀ᴗ•́)و

@ZenAlexa

ZenAlexa commented Sep 3, 2026 •

Copy link
Copy Markdown
Author

Yep, the race exists on current main. #573 intentionally removed that lifecycle change in f7913e96, and the current two-file diff leaves terminal settlement unchanged, matching the scope request above. invoke_async currently documents queued shutdown drops. This makes it a lifecycle-contract decision, and the cadence ordering diff remains isolated. I split that decision into #578.

Comment thread flashdreams/flashdreams/api_v2/loop.py Resolved
@ZenAlexa

ZenAlexa commented Sep 5, 2026

Copy link
Copy Markdown
Author

The second event_buffer.read(reader_id) is intentional and defines the cadence boundary:

  • The first read feeds _begin_run() before the cadence wait. It handles lifecycle events, reset generation, and the pre-wait snapshot.
  • The second read runs after the wait and advances the same reader cursor. It collects events appended during the wait and folds them into the pending events through _incorporate_user_events() before step().

EventBuffer.read() advances each reader to the buffer end, so the first snapshot is not duplicated. The regression test_model_loop_collects_input_after_pacing appends a keyboard event from the patched cadence wait and verifies that it reaches the next model step. The focused test_session_runner.py suite passes 61 tests on this head.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Comment thread flashdreams/flashdreams/api_v2/loop.py Resolved
@ZenAlexa

Copy link
Copy Markdown
Author

I've synced the cadence fix with current main and rerun the input-buffer and session lifecycle tests.

The regression continues to reproduce the stale input on the base branch and passes with the post-wait read.

@ZenAlexa

Copy link
Copy Markdown
Author

I checked the post-cadence queue concern against the shutdown contract: queued operations are discarded when the loop closes.

Reset events use the event-buffer generation, and session replacement goes through the UI loop. I'm keeping one message snapshot per iteration here.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

ZenAlexa commented Oct 8, 2026

Copy link
Copy Markdown
Author

@gtong-nv, the two snapshots now preserve rank-zero input ownership across the current StepAgreement protocol: preparation handles the pre-wait lifecycle state, then a fresh broadcast and readiness agreement admit late input before every rank enters step. Queued operations execute once during preparation. At 37c3e708, six two-rank Gloo scenarios pass; the paired 30 Hz probe moves input consumption forward one step, with about 252 µs of additional control-loop cost per step. Could you recheck that cadence boundary on the updated implementation?

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa
ZenAlexa requested a review from a team as a code owner October 13, 2026 18:22
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Preserve post-pacing input refresh and rank agreement alongside the
current client file-selection and UI request lifecycle.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
…o-model-step

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
@ZenAlexa

Copy link
Copy Markdown
Author

I rechecked the current head 85439c3d. The diff is now limited to the cadence-order fix and its focused tests: input is reread after the model pacing wait, and the test covers both an input arriving during pacing and the reset timing it exercises. The lifecycle/collective safeguards in the diff are required to keep the post-pace read on the same admission boundary; I did not add the broader finished-loop/message-queue redesign. The current branch remains ready for the maintainer review of this narrower scope.

Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>

This branch has not been deployed

No deployments
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.

3 participants