Repository navigation
[Multimodal] Chunk and cache audio items whose offsets span several placeholder runs - #43301
Merged
Merged
Conversation
…laceholder runs An audio item can be interleaved with text, so its placeholder tokens arrive in several runs (for example offsets [(2, 3), (6, 7), (10, 11)] for one six-token item) rather than one contiguous span. The chunked prefill embedding path treated any item with more than one offset as a "full" request: the whole request was re-encoded on every chunk and the per-item embedding cache was never consulted, so a history item replayed on the next turn was encoded again every time. - `_get_chunked_prefill_embedding` keeps audio items on the per-item path even when they have several offsets. `_item_overlap` and `_slice_item_chunk` derive an item's token count and its slice for one chunk from all of its runs; single-offset items keep the previous arithmetic. - `_get_chunked_embedding_by_item` and `_assemble_per_image_chunk` return the ordered item slices instead of concatenating them, and the caller concatenates the whole batch once. A single slice is returned as-is, so a request with one cached item gets a view of the cache entry and no copy. - `_get_precomputed_embedding` slices each precomputed item by its own offsets instead of concatenating a request's items first and slicing with the flattened offsets, and skips the concat for a single slice. - When `embedding_cache.set` admits an entry, the stored tensor is used as the chunk source if its token count matches, so returned chunks alias the cache entry rather than the encoder's batch output buffer. - `test_mm_chunked_embedding_unit.py` covers multi-offset audio items on both the batched and per-request paths: chunk boundaries inside an item, a replayed item served from the cache, request-order assembly with a single concat under cache pressure, and precomputed multi-offset slices. The new cases fail on the previous code. Co-authored-by: YavorGIvanov <[email protected]>
metamergebot
requested review from
Ying1123,
hnyls2002,
merrymercy and
xiezhq-hermann
as code owners
October 9, 2026 06:10
Contributor
|
Let me know if you need help understanding what was the motivation for this or need any changes. |
Collaborator
Author
|
This port clears our bar on gate 21✓✗3✂5 lint✓ build 3✓✗1✂3 A✓ B✓ C 0/10⏳ other 7✓✂7 · accel ✗amd,npu @hanming-lu @merrymercy @YavorGIvanov — could one of you take a look and merge it if you are happy? Nothing else is waiting on our side. |
detain
added a commit
to detain/sglang
that referenced
this pull request
Oct 10, 2026
Brings in 699 upstream commits up to 87845cd (sgl-project#43301, 2026-10-09). Conflict resolutions (67 files): - multimodal_gen quality tiers: adopt upstream exact/lossless/high migration (old lossless=bit-exact -> new "exact"; fusion moves into "lossless", which is now the DEFAULT). Migrated the stack's teacache guard (minimax_h3) to the "exact" tier and ltx_2 mask-skip to quality_allows(q, "lossless"). - video saving: take upstream's one-pass _save_video_ffmpeg (plugin-free), superseding the stack's PyAV/ffmpeg-pipe two-pass path (c16d89e/1b66dcb374); video_api generate_audio re-expressed over their request_extra_value. - teacache: union API -- keep our get_thresh/get_skip_boundaries/is_step_boundary alongside their get_skip_step_range (wanvideo/longcat/minimax + tests use all). - orchestrator.py: kept OURS wholesale (their refactor targets classic dispatchers our DAG sgl-project#139 removed); glm_distributed NotImplementedError lives in scheduler_mixin. - schedule_batch: retained our grammar_needs_sync field. - pool_host / mamba naming: took theirs. - unified_radix_cache: took their prefix-hit API, re-porting our bounded-evict logic into allocate_storage_hit. - hybrid_cache_controller: kept sgl-project#39830 degrade-to-miss guard over their changes. - hybrid_pool_assembler: took theirs (sgl-project#39893 absorbed our earlier patch). - qwen4_exp: rebuilt stage-boundary logic + re-applied PLE deltas. - qsa_sparse_attn_backend: integrated upstream CP / breakable-graphs / verify-fusion over our SM120 triton-decode and FP8-descale paths. - sgl-project#38480 + sgl-project#39862 arrived via upstream (stack dupes dropped). - tests: upstream deleted test_scheduler_decision_batch_params; ported that coverage to test_scheduler_grammar_mixed_tail_sync.py. - quantization import test (merge fallout): upstream renamed kitchen_int8 -> convrot_int8 and dropped the package-level config-class __getattr__ shim, so test_quantization_imports now asserts get_quantization_config dispatch against the concrete modules (canonical convrot names) plus an explicit kitchen_int8->convrot alias check. Deferred: GPU end-to-end verification owed (all 4 GPUs are running production servers; this battery was CPU-forced). Stack fixes land live only after the next diffusion/AR server restarts. Co-Authored-By: Claude Opus 5.5 (1M context) <[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
An audio item can be interleaved with text, so its placeholder tokens arrive in several runs (for example offsets
[(2, 3), (6, 7), (10, 11)]for one six-token item) rather than one contiguous span. The chunked prefill embedding path treated any item with more than one offset as a "full" request: the whole request was re-encoded on every chunk and the per-item embedding cache was never consulted, so a history item replayed on the next turn was encoded again every time.Modifications
_get_chunked_prefill_embeddingkeeps audio items on the per-item path even when they have several offsets. New helpers_item_overlapand_slice_item_chunkderive an item's token count and its slice for one chunk from all of its runs; single-offset items keep the previous arithmetic._get_chunked_embedding_by_itemand_assemble_per_image_chunkreturn the ordered item slices instead of concatenating them, and the caller concatenates the whole batch once. A single slice is returned as-is, so a request with one cached item gets a view of the cache entry and no copy.PerImageRequestInfo.overlappingnow carries(idx, item, token_count)instead of(idx, item, start, end)._get_precomputed_embeddingslices each precomputed item by its own offsets instead of concatenating a request's items first and slicing with the flattened offsets, and skips the concat for a single slice.embedding_cache.setadmits an entry, the stored tensor is used as the chunk source if its token count matches, so returned chunks alias the cache entry rather than the encoder's batch output buffer.test/registered/chunked_prefill/test_mm_chunked_embedding_unit.py(CPU-only,base-a-test-cpu) covers multi-offset audio items on both the batched and per-request (_is_hip) paths: chunk boundaries inside an item, a replayed item served from the cache without re-encoding, request-order assembly with a singletorch.cat/torch.concatcall under cache pressure, and precomputed multi-offset slices. Existing cases are updated for the list-of-slices return type and additionally assert that returned chunks share storage with the cache entry.Accuracy Tests
Not applicable: the embeddings handed to the model are the same slices as before, assembled with one concat instead of several. The unit tests assert bitwise equality (
rtol=0, atol=0) between the chunked results and the encoder output.Local run of the three test files that import
mm_schedule:With the new test file run against unmodified
main, the new cases fail (19 failed, 9 passed), so they guard the behaviour this change adds.Speed Tests and Profiling
No kernel change. A replayed multi-offset audio item is now a cache hit instead of a full re-encode, and a request's chunk is concatenated once instead of once per item plus once per request.
Checklist
CI States
Latest PR Test (Base): 🚫 Run #37892209375
Latest PR Test (Extra): ❌ Run #37892208896
Latest PR Test (AMD ROCm 10): ❌ Run #37892209208