fix(io_struct): index extra_key per sub-request in batched GenerateReqInput#26971
Merged
hnyls2002 merged 1 commit intoJun 14, 2026
Conversation
Contributor
|
Warning You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again! |
…qInput Closes sgl-project#26755. `GenerateReqInput.extra_key` is typed `Optional[Union[List[str], str]]`, but batch normalization did not normalize/expand it and `__getitem__` passed `extra_key=self.extra_key` to every sub-request instead of indexing it. A batched request with `extra_key=["tenant-A", "tenant-B"]` crashed downstream prefix-cache matching with `TypeError: unhashable type: 'list'` in `RadixKey.child_key()` because every sub-request inherited the full list. Fix: - `_normalize_extra_key`: broadcast a scalar string to a list of length `num`, validate list length against `batch_size`, expand by `parallel_sample_num`. Mirrors the existing `_normalize_custom_logit_processor` style. - `__getitem__`: index `self.extra_key[i]` when non-None, broadcast None otherwise (matches `custom_logit_processor` / `lora_path` pattern in the same method). Tests: extended `TestGenerateReqInputNormalization` in `test/registered/unit/managers/test_io_struct.py` with a `test_extra_key_normalization` case covering per-request list, scalar broadcast, None, parallel-sample expansion, and the wrong-length error path. Single (non-batched) requests with a scalar `extra_key` are unchanged.
5ce8ab7 to
2e0dd54
Compare
hnyls2002
approved these changes
Jun 14, 2026
Collaborator
|
/tag-and-rerun-ci |
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
GenerateReqInput.extra_keyis typedOptional[Union[List[str], str]], but batch normalization did not normalize/expand it and__getitem__passedextra_key=self.extra_keyto every sub-request instead of indexing it (issue #26755).A batched request with a per-request list crashes downstream prefix-cache matching:
{"text": ["P", "P"], "extra_key": ["tenant-A", "tenant-B"], "sampling_params": [{"max_new_tokens": 1}, {"max_new_tokens": 1}]}both sub-requests inherit
extra_key=["tenant-A", "tenant-B"], andRadixKey.child_key()produces(['tenant-A', 'tenant-B'], 50)which fails withTypeError: unhashable type: 'list'.Modifications
python/sglang/srt/managers/io_struct.py:_normalize_extra_key(num)wired into_normalize_batch_inputs, mirroring the existing_normalize_custom_logit_processorstyle:None→ unchangedstr→[str] * num(broadcast to every sub-request)listof lengthbatch_size→ expanded byparallel_sample_numlistof mismatched length →ValueErrorwith a clear messageValueError__getitem__now readsself.extra_key[i]when non-None andNoneotherwise — matches thecustom_logit_processor/lora_pathpattern already used a few lines above in the same method.After normalization the invariant becomes:
extra_key is None or len(extra_key) == batch_size * parallel_sample_num, identical to the convention used bylora_path/custom_logit_processor/logprob_params.Tests
test/registered/unit/managers/test_io_struct.py::TestGenerateReqInputNormalization::test_extra_key_normalizationcovers:__getitem__returns scalar per index (the bug fix).__getitem__returns the same string for every index.None→ staysNone,__getitem__broadcastsNone.parallel_sample_num=2→ list doubled byparallel_sample_num.ValueErrorwithbatch sizein the message.extra_key→ unchanged.Registered to
base-b-test-cpu/stage-b-test-1-gpu-small-amd/ cudabase-b1-gpu-largevia the file's existingregister_*_ci(...)block.Accuracy
Not applicable. No change to sampling, model forward, or scheduling. Only the routing of
extra_keyfrom the batched input to its sub-requests changes; downstream consumers (RadixKey, prefix cache) already expect a scalar per request.Speed Tests and Profiling
Not applicable. Normalization adds one Python list operation per batched request at admission time; negligible vs. tokenization and prefill.
Checklist
Closes #26755.
CI States
Latest PR Test (Base): ⏳ Run #26981186663
Latest PR Test (Extra): ❌ Run #26981186627