Repository navigation
[Core] Add subclass hooks for the generation request class and optimistic prefill eligibility - #44113
Merged
Merged
Conversation
…stic prefill eligibility A fork that keeps per-request state on a `Req` subclass, or carries an extra field on the tokenized wire type, currently has to copy `handle_generate_request`, `Session.create_req` and `_create_tokenized_object` wholesale to swap the class they construct. Route the existing construction sites through one override point per class instead: - `Scheduler._create_generation_req(recv_req, *args, **kwargs)` builds the `Req` on the plain, session and unknown-session paths. `Session.create_req` takes a `req_factory` so the session path reaches the same hook. - `TokenizerManager.tokenized_generate_req_type` and `batch_tokenized_generate_req_type` name the wire types that single and batched dispatch construct. - `PrefillBootstrapQueue.can_prefill_before_bootstrap(req)` holds the per-request eligibility test for prefilling before the receiver is bound. The pause check and the metadata-buffer admission stay in the shared queue loop, so a permissive subclass cannot resume a retracted request. Default behaviour is unchanged. Tests pin that every construction site goes through the hook and that the pause check stays outside the eligibility hook. Co-authored-by: CuiCoco <[email protected]>
metamergebot
requested review from
ByronHsu,
Duyi-Wang,
HaiShaw,
ShangmingCai,
Ying1123,
hnyls2002,
merrymercy,
sogalin and
xiezhq-hermann
as code owners
October 13, 2026 18:37
Collaborator
Author
|
This port clears our bar on gate 21✓✗3✂5 lint✓ build 3✓✗1✂3 A✓ B✓ C 0/9⏳ other 7✓✂7 · accel ✗amd,xpu @fei-xx @merrymercy @CuiCoco — could one of you take a look and merge it if you are happy? Nothing else is waiting on our side. |
jain-ria
added a commit
to jain-ria/sglang
that referenced
this pull request
Oct 15, 2026
Two unit tests construct their objects with `__new__` and set only the attributes they need. Recent main changes read attributes the real constructors always set but the fakes lacked: - sgl-project#44326 made `PrefillCudaGraphRunner.can_run_graph` read `max_seq_len`; `test_cp_strategy_unit.py`'s runner did not set it. - sgl-project#42817 made generate-request handling read `kv_events_publisher`; `test_request_class_override_points.py`'s fake scheduler (sgl-project#44113) lacked it. Both failed with AttributeError on main and on every PR running the CPU suite. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jain-ria <[email protected]>
jain-ria
added a commit
to jain-ria/sglang
that referenced
this pull request
Oct 15, 2026
`TokenizerManager._send_batch_request` reads `positional_embeds_transport` (sgl-project#39730), which the hand-built manager in `test_request_class_override_points.py` (sgl-project#44113) never set, so `test_tokenizer_manager_emits_the_subclass_wire_types` failed with AttributeError. Stub it like the neighbouring cuda_vmm transport. Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: jain-ria <[email protected]>
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.
Motivation
A downstream fork that keeps per-request state on a
Reqsubclass, or carries one extra field on the tokenized wire type, currently has to copyhandle_generate_request,Session.create_reqand_create_tokenized_objectwholesale just to change the class they construct. The same goes for a fork that wants its own rule for when a disaggregated prefill may run before its decode receiver is bound: the eligibility test is inlined inpop_bootstrapped, next to the pause check and the metadata-buffer admission that every subclass must keep.This routes the existing construction sites through one override point per class, in the spirit of the
init_*override points the large classes already expose. Default behaviour is unchanged.Modifications
Scheduler._create_generation_req(recv_req, *args, **kwargs)builds theReqon the plain, session and unknown-session paths ofhandle_generate_request.Session.create_reqtakes areq_factory(defaultReq) so the session path reaches the same hook.TokenizerManager.tokenized_generate_req_typeandbatch_tokenized_generate_req_typeare class attributes naming the wire types that single and batched dispatch construct.PrefillBootstrapQueue.can_prefill_before_bootstrap(req)holds the per-request eligibility test for prefilling while the sender is still bootstrapping. Theis_retractedpause check andensure_metadata_bufferstay in the shared queue loop, so a permissive subclass cannot resume a retracted request or skip metadata admission.Accuracy Tests
Not applicable: no numerical change.
Speed Tests and Profiling
Not applicable: the hot paths gain one bound-method call per request admission.
Checklist
base-a-test-cpu):test/registered/unit/managers/test_request_class_override_points.py(new): aSchedulersubclass overriding_create_generation_reqreceives itsReqsubclass on all three request paths; aTokenizerManagersubclass's wire types reach single and batched dispatch.test/registered/unit/managers/test_priority_scheduling_disaggregation.py: aPrefillBootstrapQueuesubclass whose eligibility hook always answers yes admits a bootstrapping request that the default rule would hold, and still never admits a retracted one.mainand pass with this change.test_priority_scheduling_disaggregation,test_scheduler_sampling_mask_validation,test_multimodal_abort_cleanup,test_gemma4_uniform_lifecycle,test_session_token_share_unit,test_prefill_result_polling,test_admission_abort_not_enqueued,test_disagg_idle_step_counters,test_scheduler_hicache_events.CI States
Latest PR Test (Base): ❌ Run #38448219291
Latest PR Test (Extra): ❌ Run #38448219588
Latest PR Test (AMD ROCm 10): ❌ Run #38448219387