Skip to content

[Core] Add subclass hooks for the generation request class and optimistic prefill eligibility - #44113

Merged
hanming-lu merged 1 commit into
mainfrom
oss-sync-9decd88ac6
Oct 14, 2026
Merged

hanming-lu merged 1 commit into
mainfrom
oss-sync-9decd88ac6

Conversation

@metamergebot

@metamergebot metamergebot commented Oct 13, 2026 •

Copy link
Copy Markdown
Collaborator

Motivation

A downstream fork that keeps per-request state on a Req subclass, or carries one extra field on the tokenized wire type, currently has to copy handle_generate_request, Session.create_req and _create_tokenized_object wholesale 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 in pop_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 the Req on the plain, session and unknown-session paths of handle_generate_request. Session.create_req takes a req_factory (default Req) so the session path reaches the same hook.
  • TokenizerManager.tokenized_generate_req_type and batch_tokenized_generate_req_type are 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. The is_retracted pause check and ensure_metadata_buffer stay 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

  • Unit tests (CPU, base-a-test-cpu):
    • test/registered/unit/managers/test_request_class_override_points.py (new): a Scheduler subclass overriding _create_generation_req receives its Req subclass on all three request paths; a TokenizerManager subclass's wire types reach single and batched dispatch.
    • test/registered/unit/managers/test_priority_scheduling_disaggregation.py: a PrefillBootstrapQueue subclass whose eligibility hook always answers yes admits a bootstrapping request that the default rule would hold, and still never admits a retracted one.
    • All three cases fail on current main and pass with this change.
  • Existing CPU unit tests around the touched code pass: 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.
  • Pre-commit hooks (ruff-format, ruff, isort, codespell, registered-test checks) are clean on the changed files.

CI States

Latest PR Test (Base): ❌ Run #38448219291
Latest PR Test (Extra): ❌ Run #38448219588
Latest PR Test (AMD ROCm 10): ❌ Run #38448219387

…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 metamergebot added the run-ci CI: run the baseline test suite on this PR label Oct 13, 2026
@metamergebot

Copy link
Copy Markdown
Collaborator Author

This port clears our bar on b2676fe291f415adf292c5afcda880fb9d02859e: every base-a and base-b job is green.
base-c and the accelerator suites are reported but not gated, because they run
on scarce hardware and upstream merges through them routinely.

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.

@hanming-lu
hanming-lu merged commit 2a9f6a2 into main Oct 14, 2026
218 of 265 checks passed
@hanming-lu
hanming-lu deleted the oss-sync-9decd88ac6 branch October 14, 2026 23:42
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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

run-ci CI: run the baseline test suite on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants