Repository navigation
refactor(worker): move decode composition root to worker - #892
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.
Extract D8 Slots 17-18 legacy decode page boundary and CPU_ATTN / LEGACY_MICROBATCH_GPU step helpers into keyword-only explicit-parameter functions in decode_engine.py with direct-parameter tests.
Remove unused DecodeStrategy import from batchgen/worker/decode_engine.py after splitting CPU_ATTN and LEGACY_MICROBATCH_GPU helpers.
Complete D8 19/19 decode decoupling by moving the thin DecoupledGpuDecode.run composition root onto BatchGenWorker._run_decoupled_gpu_decode and removing DecoupledGpuDecode from decode_engine.py. All worker-attribute writes and worker-capturing closures across engine modules drop to zero.
Update the eight remaining decode-engine AST/direct-params tests to inspect BatchGenWorker._run_decoupled_gpu_decode after Slot 19 removed DecoupledGpuDecode.
Fix F401 unused import left after re-anchoring test_decode_round_obs_direct_params.py to BatchGenWorker._run_decoupled_gpu_decode.
Slot 18 changed BatchGenWorker.update_new_token to return CPU token_ids: List[int] so legacy decode avoids an extra per-token .item() host sync.
…-round-dispatch-params
Update five remaining AST tests to inspect decode_engine.py alongside batchgen_worker.py after D8 extracted wave configuration, completion cleanup, and step replay guards.
Update _loop() in test_decode_deferred_token_readback.py to inspect BatchGenWorker._run_decoupled_gpu_decode after Slot 19 moved the composition root back to the worker.
…y-decisions-params
…code-forward-prep-params
…orward-sample-params
…egacy-helpers-params
…-round-dispatch-params
Removes the unused legacy_past_kv_byte_size import left after extracting legacy decode helpers to decode_engine.py.
…-round-dispatch-params
…y-decisions-params
…code-forward-prep-params
…orward-sample-params
…egacy-helpers-params # Conflicts: # batchgen/batchgen_worker.py
…-round-dispatch-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.
…egacy-helpers-params
…-round-dispatch-params
Extract resolve_decode_step_rank_batch_size into decode_engine.py so batchgen_worker.py model-branch span stays at 95 and decode_engine.py shrinks to 104.
Use lowercase tuple return annotation in resolve_decode_step_rank_batch_size to satisfy F821 lint check.
Andrewxu313
changed the base branch from
tairan/decode-legacy-helpers-params
to
main
December 4, 2026 04:56
…ispatch-params # Conflicts: # batchgen/worker/decode_engine.py # tests/test_decode_exit_pending_load_integration.py # tests/test_decode_step_timing_wiring.py # tests/unit/test_decode_engine_empty_rank_names.py # tests/worker/test_boundary_decisions_direct_params.py # tests/worker/test_boundary_follow_up_direct_params.py # tests/worker/test_decode_forward_prep_direct_params.py # tests/worker/test_decode_forward_sample_direct_params.py # tests/worker/test_worker_model_branches.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
Complete D8 (19/19) decode decoupling by moving the thin
DecoupledGpuDecode.runcomposition root back ontoBatchGenWorker._run_decoupled_gpu_decodeand removingDecoupledGpuDecodeandDecodeModelStateBinderfrombatchgen/worker/decode_engine.py.Every remaining decode stage in
batchgen/worker/decode_engine.pyis now a pure explicit-parameter helper with zeroworkerparameters, zero worker attribute writes, and zero closures over the worker:tests/worker/test_engine_worker_writes_single_owner.pyALLOWED->{}tests/worker/test_engine_closures_over_the_worker.pyALLOWED->set()Motivation
Matches the D5 (
worker_lifecycle_engine.py) convergence pattern sobatchgen/worker/decode_engine.pyowns zero worker state and satisfies P1 single-writer and P3 one-way dependency invariants.Type of Change
core— engine scaffolding, worker, scheduler, KV cache, or serverFile changes
batchgen/batchgen_worker.py_run_decoupled_gpu_decodethin composition root callingdecode_engineexplicit-parameter helpersbatchgen/worker/decode_engine.pyDecoupledGpuDecodeandDecodeModelStateBinderand keepresolve_decode_step_rank_batch_sizeexplicit-parameter helpertests/test_decode_deferred_token_readback.py_loop()AST lookup toBatchGenWorker._run_decoupled_gpu_decodetests/test_decode_exit_pending_load_integration.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_decode_host_kv_stream_order.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_decode_step_host_bookkeeping.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_decode_step_timing_wiring.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_worker_host_kv_append_completion.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_worker_pool_restart.pyBatchGenWorker._run_decoupled_gpu_decodetests/test_worker_weight_passes.pydecode_enginehelperstests/test_decode_transition_metadata.pydecode_engine.configure_decode_wave_local_rows_and_graphstests/test_glm5_worker_fa3_wiring.pydecode_engine.pytests/test_kimi_k3_server_startup_init.pyprewarm_decode_jitordering check acrossgenerate()anddecode_engine.configure_decode_wave_local_rows_and_graphstests/unit/test_debug_state_adoption.pybatchgen_worker.pyanddecode_engine.pyfor phase-entry debug adoptiontests/unit/test_decode_dp_group_packing.pydecode_engine.pycompletion-cleanup loop in saved-group cleanup verificationtests/unit/test_decode_driver_unification.pyBatchGenWorker._run_decoupled_gpu_decodetests/unit/test_decode_engine_empty_rank_names.pyBatchGenWorker._run_decoupled_gpu_decodetests/unit/test_eventlog_step_counters_wiring.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_boundary_decisions_direct_params.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_boundary_follow_up_direct_params.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_forward_prep_direct_params.pyinference_modeAST check toBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_forward_sample_direct_params.pyinference_modeAST check toBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_group_rows_log.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_round_obs_direct_params.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_round_prep_direct_params.pyBatchGenWorker._run_decoupled_gpu_decodetests/worker/test_decode_width_bucket_invariant.py_load_decode_modelsite indecode_engine.pyand re-anchor over-bucket assertiontests/worker/test_engine_closures_over_the_worker.pyALLOWEDtoset()(zero worker-capturing engine closures remain)tests/worker/test_engine_worker_writes_single_owner.pyALLOWEDto{}(zero engine writes to worker attributes remain)tests/worker/test_glm5_criticality_probe_worker.pytests/worker/test_worker_model_branches.pydecode_engine.pymodel-branch span budget from 107 to 104Checklist
README.mdchanged, I ranpython3 scripts/check_readme_update.py --base-ref origin/mainand preserved all News history.