Repository navigation
[data][llm] Add SGLang score task: multi-item scoring, embedding overrides, score extraction - #67038
Conversation
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
59537a7 to
2a23163
Compare
|
This pull request has been automatically marked as stale because it has not had You can always ask for help on our discussion forum or Ray's public slack channel. If you'd like to keep this open, just leave any comment, and the stale label will be removed. |
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
22fa56a to
235df10
Compare
239eb03 to
7c9a88b
Compare
7c9a88b to
95e46ad
Compare
Without MIS, the tokenize stage folds the query into each item, so SGLang's query-prefix anchor check never sees it. Mirror that check in the stage. Co-authored-by: Copilot <[email protected]> Signed-off-by: Jian Sheng <[email protected]>
- Release test: compare MIS and single-item scoring on the same token IDs, since text tokenization differs between the two at the query/item boundary. - Docs: note MIS tokenization, label order, and score-extraction config. - Score tokenize stage reports the override columns as optional inputs. - Docstring and comment fixes. Co-authored-by: Copilot <[email protected]> Signed-off-by: Jian Sheng <[email protected]>
…portorskip Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jeffrey Wang <[email protected]>
…checks Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jeffrey Wang <[email protected]>
The ray logger doesn't propagate to root, so caplog under CI's pytest 7.4.4 never captured the validate_model warning. Co-authored-by: Copilot <[email protected]> Signed-off-by: Jian Sheng <[email protected]>
Each anchor's scores should match plain scoring of the item truncated at that anchor, with and without multi-item scoring. Needs sglang >=0.5.21 (bumped to 0.5.23 in ray-project#68250). Co-authored-by: Copilot <[email protected]> Signed-off-by: Jian Sheng <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Jeffrey Wang <[email protected]>
## Description Bumps sglang in the release-test BYOD layer (`byod_llm_sglang_test.sh`) from 0.5.15.post1 to 0.5.23, and drops the inlined Ray metrics patch (upstreamed) along with its copy in `python/requirements/llm/patches/`. ## Related issues Needed by #67038 (sglang `task_type="score"`): - `Engine.async_score` first accepts `score_extraction_token_id` in 0.5.21, so score extraction can't be release-tested on the current pin. - Since 0.5.21, sglang tokenizes text items without special tokens, which is what #67038's score tokenize stage does. On 0.5.15.post1, sglang adds BOS to each item for tokenizers that add one (e.g. Llama), so its multi-item scoring tokenization differs from Ray's. AI assistance (Claude Code) was used; I reviewed every changed line. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Signed-off-by: Jeffrey Wang <[email protected]> Co-authored-by: Claude Opus 5.5 <[email protected]>
|
@fortunecookiee please merge from the latest master. #68250 (bumping release test's sglang version) just landed. |
jeffreywang88
left a comment
There was a problem hiding this comment.
I think there are some unnecessary config checks and tests. In general, I'd follow two principles:
- If sglang already performs a config check, we shouldn't duplicate it in Ray.
- Prefer end-to-end integration tests, don't duplicate test coverages, and only add unit tests for functionality we've implemented specifically in ray.
I'd also avoid lazy imports unless necessary and low-signal tests.
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 5aa7609. Configure here.
| if embed_id is not None and embed_id == extraction_id: | ||
| raise ValueError( | ||
| "'embed_override_token_id' and 'score_extraction_token_id' must " "differ." | ||
| ) |
There was a problem hiding this comment.
Score extraction skips incompatible option checks
Medium Severity
_validate_score_config never rejects score_extraction_token_id paired with item_first or allow_auto_truncate, even though both are documented as unsupported and the helper is meant to catch combinations SGLang would only fail on a worker. With item_first, the tokenize stage still builds item+query sequences, so extraction positions sit in the item prefix and causal scoring never sees the query. That can yield silently wrong scores instead of a build-time error, and allow_auto_truncate still reaches GPU workers before failing.
Additional Locations (1)
Reviewed by Cursor Bugbot for commit 5aa7609. Configure here.
There was a problem hiding this comment.
SGLang's _validate_score_extraction already rejects item_first and allow_auto_truncate with extraction, and we're not duplicating SGLang's config checks here.
- Always tokenize score queries with special tokens, as SGLang does. - Drop the ForCausalLM label check and torch override branches; SGLang and Ray Data already cover them. - Use result.prompt_tokens and pydantic ConfigDict. - Test tokenization against the real Qwen3-0.6B tokenizer and drop duplicate or low-signal tests. Co-authored-by: Copilot <[email protected]> Signed-off-by: Jian Sheng <[email protected]>
|
@jeffreywang88 could you pls take another look? |
jeffreywang88
left a comment
There was a problem hiding this comment.
Thanks @fortunecookiee please update PR description as I kick off GPU tests.
Signed-off-by: Jeffrey Wang <[email protected]> Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Second try https://buildkite.com/ray-project/release/builds/117010/canvas?sid=01a20b54-bfeb-43f8-9d6b-d45ac7de1d53&open=false after fixing / updating the tests. |
|
@eicherseiji Copilot suggests getting your approval as well to cover the missing review, could you help ship? |


Description
Adds
task_type="score"toSGLangEngineProcessorConfig, backed by SGLang'sEngine.async_score. Each row scores onequeryagainst a list ofitems; the output columnscoresholds one score list per item, in item order.This brings the SGLang optimizations for JEV-like decision models (Scaling JEV-like Decision Models with SGLang) to Ray Data batch inference: multi-item scoring (MIS) for pointwise decisions, and setwise scoring through score extraction.
Pipeline
Features
Multi-item scoring (MIS):
engine_kwargs={"enable_mis": True}scores all of a row's items in one forward pass.Embedding overrides: replace the embedding at each marker token with a vector from
query_embed_overrides/item_embed_overrides, one vector per marker, in order.Score extraction (setwise scoring): read a score at every extraction token in an item instead of only at its last token. Each item then gets one score list per extraction token.
task_kwargslabel_token_idsapply_softmax,item_firstasync_score.embed_override_token_idscore_extraction_token_idTokenization
The tokenize stage matches SGLang's text path, always with the tokenizer's special tokens:
query + item(item + querywithitem_first) is tokenized as one sequence andquery_token_idsis empty, since the engine would concatenate them.Validation
Checks are limited to what SGLang can't catch, or would only catch on a GPU worker:
task_kwargskeys; score options placed inengine_kwargs; token IDs outside the model vocabulary (the engine runs withskip_tokenizer_init, so it doesn't range-check them); marker IDs that collide with the MIS delimiter or each other;item_firstwith MIS.sglang>=0.5.21, the first release whoseasync_scoreacceptsscore_extraction_token_id.Everything else (missing
label_token_ids, extraction withitem_first/allow_auto_truncate, per-row override counts) is left to SGLang.Code structure
One class,
_SGLangScoreTaskintasks/sglang/score.py, on the_SGLangTaskhooks from #67655:options_modelSGLangScoreOptionsunsupported_stagesforced_engine_kwargsskip_tokenizer_init=Trueprepare_configbuild_tokenize_stageSGLangScoreTokenizeStagevalidate_model(new, no-op on base)prepare_request/runasync_score->scoresShared helpers in
stages/common.py:to_token_id_listandis_missing(Ray Data stores a missing value as NaN next to array rows). Embedding overrides are converted from numpy, the form Ray Data rows hold. Generate behavior is unchanged.Related issues
Additional information
task_type="score": vLLM scores one prompt per row with a cross-encoder. SGLang scores one query against many items, so the inputs arequery/itemsand the output isscores.async_score: SGLang's syncscore()runs its own event loop and deadlocks inside the stage's loop.Testing
CPU (macOS, mocked SGLang; tokenize tests use the real Qwen3-0.6B tokenizer from Ray's S3 mirror):
pytest python/ray/llm/tests/batch/cpu/processor/test_sglang_score_proc.py python/ray/llm/tests/batch/cpu/stages/test_sglang_score_tokenize_stage.py python/ray/llm/tests/batch/cpu/stages/test_sglang_score_engine_stage.py python/ray/llm/tests/batch/cpu/stages/test_common.py: 56 passed.pre-commit run --files <changed files>: passed.GPU (release tests, Qwen3-0.6B,
sglang==0.5.23), inrelease/llm_tests/batch/test_batch_sglang.py:test_sglang_score_matches_engine: Ray Data scores match a directsglang.Engine.scoretext call using the same engine kwargs, MIS off and on.test_sglang_score_embed_overrides: a marker overridden with a token's own embedding scores like that token, MIS off and on.test_sglang_score_extraction: each anchor's scores match plain scoring of the item truncated at that anchor, MIS off and on.doc_code/working-with-llms/sglang_score_example.pyruns in the newllm_doc_sglang_testsrelease test.AI assistance: GitHub Copilot helped write and review this change. I reviewed every changed line and ran the CPU tests above.