[Score API] Implement EngineScoreMixin for scoring functionality and refactor Tok…#21342
Merged
hnyls2002 merged 14 commits intosgl-project:mainfrom Apr 3, 2026
Merged
Conversation
…enizerManager to use TokenizerManagerScoreMixin. Add new engine_score_mixin and tokenizer_manager_score_mixin files, and update CODEOWNERS to reflect new ownership. Include unit tests for scoring methods.
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
Collaborator
Author
|
/rerun-failed-ci |
Collaborator
Author
|
/tag-and-rerun-ci here |
Collaborator
23 tasks
JustinTong0323
pushed a commit
to JustinTong0323/sglang
that referenced
this pull request
Apr 7, 2026
Fridge003
pushed a commit
that referenced
this pull request
Apr 7, 2026
xiezhq-hermann
pushed a commit
to antgroup/sglang
that referenced
this pull request
Apr 7, 2026
yhyang201
pushed a commit
to yhyang201/sglang
that referenced
this pull request
Apr 22, 2026
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.
Refactor: Extract Scoring API into Dedicated Mixin Files + CODEOWNERS
Motivation
The Scoring API (
/v1/score,Engine.score(),Engine.async_score()) is a self-contained feature spanning entrypoints, managers, and tests. This PR extracts scoring-specific logic into dedicated files and adds CODEOWNERS entries so that scoring contributors are automatically requested for review on scoring-related changes.What Changed
1. New file:
python/sglang/srt/entrypoints/engine_score_mixin.pyExtracted
score()andasync_score()from theEngineclass into anEngineScoreMixin. TheEngineclass now inherits from this mixin — no behavior change, just cleaner separation.2. Renamed:
tokenizer_manager_multiitem_mixin.py→tokenizer_manager_score_mixin.pyRenamed the file and class (
TokenizerManagerMultiItemMixin→TokenizerManagerScoreMixin) to better reflect its purpose. This file contains the core scoring logic:score_request(),score_prompts(), multi-item scoring helpers, and theScoreResultdataclass.3. Updated:
python/sglang/srt/entrypoints/engine.pyEnginenow inherits fromEngineScoreMixin(MRO:Engine → EngineScoreMixin → EngineBase → ABC)score()/async_score()methods (now provided by the mixin)4. Updated:
.github/CODEOWNERSAdded per-file ownership for all scoring-specific files:
5. Updated:
test/registered/openai_server/basic/test_serving_rerank.pyUpdated import path to reflect the renamed module.
Files NOT Touched (and why)
These files contain scoring-related infrastructure (GPU kernels, scheduler logprob processing, attention masking) that is shared with other features. They were intentionally left in place:
layers/logits_processor.py—compute_logprobs_for_multi_item_scoring()operates on GPU tensors using logits-processor-internal APIslayers/attention/flashinfer_backend.py—MultiItemScoringParamsand_process_multi_item_scoring()are flashinfer attention-level codemanagers/scheduler_output_processor_mixin.py— multi-item scoring conditionals are interleaved with regular logprob processingserver_args.py—multi_item_scoring_delimiteris a server config flagValidation
Server startup
Server starts successfully with no import errors.
Single-item scoring
Response:
{ "scores": [[6.398421076647679e-06, 3.3389641633503636e-06]], "model": "...", "usage": {"prompt_tokens": 23, "total_tokens": 23}, "object": "scoring" }Multi-item scoring (3 items, softmax)
Response:
{ "scores": [ [0.4857216775417328, 0.5142783522605896], [0.6157812476158142, 0.3842187821865082], [0.5241511464118958, 0.475848913192749] ], "model": "...", "usage": {"prompt_tokens": 28, "total_tokens": 28}, "object": "scoring" }Import verification
Test Plan
/v1/scoreendpoint returns correct results for single-item scoring/v1/scoreendpoint returns correct results for multi-item scoring with softmaxEngine.score()andEngine.async_score()are accessible via mixin inheritancetest/registered/core/test_score_api.pypassestest/registered/openai_server/basic/test_serving_rerank.pypasses