Skip to content

[Multimodal] Chunk and cache audio items whose offsets span several placeholder runs - #43301

Merged
hanming-lu merged 1 commit into
mainfrom
oss-sync-065c5970fe
Oct 9, 2026
Merged

hanming-lu merged 1 commit into
mainfrom
oss-sync-065c5970fe

Conversation

@metamergebot

@metamergebot metamergebot commented Oct 9, 2026 •

Copy link
Copy Markdown
Collaborator

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_embedding keeps audio items on the per-item path even when they have several offsets. New helpers _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. PerImageRequestInfo.overlapping now carries (idx, item, token_count) instead of (idx, item, start, end).
  • _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/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 single torch.cat/torch.concat call 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:

python -m pytest -q test/registered/chunked_prefill/test_mm_chunked_embedding_unit.py   # 28 passed
python -m pytest -q test/registered/unit/managers/test_mm_embedding_length.py test/registered/unit/models/test_kimi_k3_vision.py   # 34 passed

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

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

Copy link
Copy Markdown
Contributor

Let me know if you need help understanding what was the motivation for this or need any changes.

@metamergebot

Copy link
Copy Markdown
Collaborator Author

This port clears our bar on f5ea1514c3d7d77cc01eb2e5effd4ab83ec9f1f0: 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/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.

@hanming-lu
hanming-lu merged commit 87845cd into main Oct 9, 2026
214 of 261 checks passed
@hanming-lu
hanming-lu deleted the oss-sync-065c5970fe branch October 9, 2026 17:57
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]>
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.

3 participants