Collect model input after cadence pacing - #573
Conversation
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Greptile SummaryThe PR refreshes model-loop input after cadence pacing so events received during the wait are available to the upcoming model step.
Confidence Score: 3/5The PR does not appear safe to merge because finished model-loop paths can still discard asynchronously accepted state operations. ZenAlexa reported both terminal-settlement races fixed, but current HEAD no longer contains the atomic finished-state settlement: it checks completion and exits before message acceptance is closed, allowing accepted operations to be drained without execution. Files Needing Attention: flashdreams/flashdreams/api_v2/loop.py Important Files Changed
Reviews (5): Last reviewed commit: "Merge remote-tracking branch 'upstream/m..." | Re-trigger Greptile |
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
Thanks @ZenAlexa , this is indeed an issue. With our current design, we need to do two paces for the model loop and UI loop. Your PR should address issue with the model pace order 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. |
Keep event collection immediately after model pacing. Restore the terminal lifecycle path for separate follow-up. Signed-off-by: Ziming Wang <zimingwang945@gmail.com>
|
Yep, I agree on keeping this PR tight 👍 One detail I found while tracing it: 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
|
Caught up with #548's multi-session lifecycle in 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 (•̀ᴗ•́)و |
|
Yep, the race exists on current |
| while not self._shutdown_event.is_set() and ( | ||
| max_steps is None or steps_run < max_steps | ||
| ): | ||
| events, generation = event_buffer.read(reader_id) |
There was a problem hiding this comment.
event_buffer.read(reader_id) is called twice in this loop.
here and in line 333.
This doesn't seem right.. I will look into this
|
The second
|
Summary
This removes up to one configured model-step interval from the avoidable input-to-model-step latency tracked in #543.
_pace()is driven byframes_per_second_for_stepon each model-loop iteration.BackpressureMode.BLOCKadds a separate wait when the presentation queue is full.Terminal message settlement remains unchanged from
main; its lifecycle contract stays outside this ordering fix.Validation
PYTHONPATH=flashdreams uv run --no-project --with 'pytest>=8' --with 'pytest-manual-marker>=2' --with 'numpy>=1.24,<2.5' --with 'torch>=2.9' python -m pytest flashdreams/test_v2/test_event_buffer.py flashdreams/test_v2/test_session_runner.py -q— 56 passeduvx --from ruff==0.12.7 ruff format --check flashdreams/flashdreams/api_v2/loop.py flashdreams/test_v2/test_session_runner.pyuvx --from ruff==0.12.7 ruff check flashdreams/flashdreams/api_v2/loop.py flashdreams/test_v2/test_session_runner.pyty checkon both changed filesAddresses #543