Repository navigation
refactor(worker): extract decode wave helpers with explicit params - #890
Merged
Merged
Conversation
Move the post-boundary page-table verification block of DecoupledGpuDecode.run into a module-level verify_boundary_page_table (keyword-only params, frozen BoundaryFollowUpOutcome): the guard, the slot-order snapshot, the mapper call, the ordered comparison and the rebuild. The row-epoch bump, both cumulative boundary counters and the verification-flag reset stay verbatim in the caller, so they remain published before the check runs and survive a mapper or rebuild error. The deferred-readback drain and its shutdown exit are untouched. Statements move verbatim apart from one spelling substitution; no new import. Tests: new declared-input tests for the check plus a caller-order pin from the dispatch assignment through the flag rebind.
…y-followup-params
Move the post-boundary decision region of DecoupledGpuDecode.run into a module-level decide_after_page_boundary (keyword-only params, frozen BoundaryDecisionOutcome): the watermark hold, admission polling, the rank-0 boundary log, the empty-decode pending-load integration and the host-capacity votes. Each original break/continue becomes a return whose outcome carries an explicit control result; the caller rebinds the eight loop locals and then executes the break or continue itself. Worker methods are passed as bound callables and invoked at their original points, so every worker publication and every collective keeps its order on all six exit paths. Statements move verbatim apart from spelling substitution; no new import. Tests: new declared-input tests for the six exit paths, wiring and caller order; the watermark-hold and slot-8 caller pins re-anchor through the new function without weakening.
Main gained the squash of the page-table check this branch is stacked on; the tree is unchanged by this merge (conflicts were history-only).
Fix F541 lint violation on line 875 of batchgen/worker/decode_engine.py so the Slot 9 PR passes pr-lint-gate.
Update the hardcoded _BASELINE_REGION fixture in test_boundary_decisions_direct_params.py to drop the unused f-string prefix removed from decide_after_page_boundary.
Extract D8 Slot 10 forward metadata assembly, replay metadata preparation, and KV callback plus profiling setup out of DecoupledGpuDecode.run into keyword-only helpers with frozen outcomes, preserving the torch.inference_mode scope and Ruling 4 rank-count publication boundary.
…-params' into tairan/decode-forward-prep-params
Extract D8 Slot 11 (CUDA graph replay, eager forward, token selection, and post-graph KV staging) out of DecoupledGpuDecode.run into execute_decode_step_forward_and_sample with model-agnostic keyword-only parameters and DecodeStepForwardOutcome, preserving torch.inference_mode scope and re-anchoring decode dispatch AST tests.
Extract D8 Slot 12 (deferred and immediate token readback, host KV drain, trajectory append, per-row token writeback, and timing split) out of DecoupledGpuDecode.run into complete_decode_step_readback with keyword-only parameters and DecodeStepReadbackOutcome, keeping the ordered shutdown exit and cumulative forward timing write in the caller.
Drop the unused pytest import from tests/worker/test_decode_readback_direct_params.py to satisfy pr-lint-gate F401.
Align the three abandoned-exit AST tests in test_worker_pool_restart.py with complete_decode_step_readback and the decode loop _READBACK_SHUTDOWN handler.
Extract D8 Slots 13-16 decode wave preparation, batch sync, local row/graph configuration, and interval finalization into keyword-only explicit-parameter helpers in decode_engine.py with direct-parameter unit tests.
…nto tairan/decode-wave-helpers-params
Remove the eliminated generate decode_uuids.sort lambda from test_worker_capturing_closures.py and re-anchor test_prefix_drain_metric.py to select_and_sync_decode_wave_batch.
…y-decisions-params
…code-forward-prep-params
…orward-sample-params
…y-decisions-params
…code-forward-prep-params
…orward-sample-params
Update KNOWN_MODEL_BRANCH_SPANS after extracting decode forward-prep helpers.
…orward-sample-params
Update KNOWN_MODEL_BRANCH_SPANS after extracting execute_decode_step_forward_and_sample.
Andrewxu313
changed the base branch from
tairan/decode-readback-params
to
main
December 4, 2026 04:51
…lpers-params # Conflicts: # batchgen/worker/decode_engine.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Extract the four decode-wave lifecycle stages in
BatchGenWorker.generate()(D8 Slots 13–16) into keyword-only explicit-parameter helpers inbatchgen/worker/decode_engine.py:prepare_decode_wave_model_and_kv(Slot 13)select_and_sync_decode_wave_batch(Slot 14)configure_decode_wave_local_rows_and_graphs+DecodeWaveConfigOutcome(Slot 15)finalize_decode_wave_interval+DecodeWaveExitOutcome(Slot 16)BatchGenWorker.generate()retains_enter_decode_phase_context()/try...finally: _exit_decode_phase_context(),_cohort_shutdown_observedearly exit, and_decode_group_idx += 1.Motivation
Continues the D8 decode-engine decoupling sequence so decode-wave logic takes explicit parameters and callbacks with zero worker object reference.
Type of Change
core— engine scaffolding, worker, scheduler, KV cache, or serverFile changes
batchgen/batchgen_worker.pydecode_enginehelpersbatchgen/worker/decode_engine.pyprepare_decode_wave_model_and_kv,select_and_sync_decode_wave_batch,configure_decode_wave_local_rows_and_graphs, andfinalize_decode_wave_intervaltests/test_worker_pool_restart.pytests/unit/test_decode_group_binding_invariant.pyconfigure_decode_wave_local_rows_and_graphstests/unit/test_decode_phase_context_once.py_enter_decode_phase_context/_exit_decode_phase_contextbracket the wave helperstests/unit/test_prefix_drain_metric.pyselect_and_sync_decode_wave_batchtests/worker/test_decode_wave_helpers_direct_params.pytests/worker/test_sequence_table.pyselect_and_sync_decode_wave_batchtests/worker/test_worker_capturing_closures.pygeneratedecode_uuids.sortlambda fromALLOWEDChecklist
README.mdchanged, I ranpython3 scripts/check_readme_update.py --base-ref origin/mainand preserved all News history.