Skip to content

[MM] Add opt-in exact multimodal embedding row-count check at final placement - #41744

Open
rodamani wants to merge 6 commits into
sgl-project:mainfrom
modal-projects:rohan/up/mm-embedding-row-count
Open

rodamani wants to merge 6 commits into
sgl-project:mainfrom
modal-projects:rohan/up/mm-embedding-row-count

Conversation

@rodamani

@rodamani rodamani commented Sep 29, 2026 •

Copy link
Copy Markdown
Contributor

Motivation

The final multimodal placement check in mm_schedule.py (_adjust_embedding_length) keeps a suffix (with a warning) when an embedding has more rows than placeholder tokens, which can shift image rows onto the wrong placeholders, and it counts only the first dimension of higher-rank encoder outputs. Some deployments may rely on the crop, so this PR adds an opt-in strict check instead of changing the default.

Modifications

  • New SGLANG_ENABLE_STRICT_MM_EMBEDDING_LENGTH (default False). When set, _adjust_embedding_length requires the flattened embedding row count (_embedding_token_count) to equal the placeholder count and raises with both counts and a chunked-prefill hint on any mismatch.
  • Default path is byte-for-byte unchanged (crop overlong with a warning, raise on short). Model-owned padding/trimming and EVS placeholder redistribution are untouched.
  • Tests: main's crop/short tests kept as-is; strict-mode exact/mismatch tests over 2D/3D/4D embeddings; chunked-prefill position and EVS row-count tests run with the flag both off and on.
  • test/registered/unit/managers/test_mm_embedding_length.py.

Relationship to open PRs: #36724 requires exact token counts for fresh encoder output before cache insertion, but leaves the suffix crop at final placement unchanged.

Accuracy Tests

CPU: test_mm_embedding_length.py 45 passed.

Compatibility

No behavior change unless the env var is set. Short-term by design: the underlying question (whether any model legitimately depends on the final-placement crop) needs a per-model audit; if none do, the strict check could become the default in a follow-up.

Speed Tests and Profiling

No hot-path change beyond the fix itself; not separately benchmarked.

Checklist

Review and Merge Process

  1. Ping Merge Oncalls to start the process. See the PR Merge Process.
  2. Get approvals from CODEOWNERS and other reviewers.
  3. Trigger CI tests with comments or contact authorized users to do so.
    • Common commands include /tag-and-rerun-ci, /tag-run-ci-label, /rerun-failed-ci
  4. After green CI and required approvals, ask Merge Oncalls or people with Write permission to merge the PR.

CI States

Latest PR Test (Base): ❌ Run #36767693421
Latest PR Test (Extra): ❌ Run #36767693169
Latest PR Test (AMD ROCm 10): ❌ Run #36767693525

The final multimodal placement check silently kept a suffix when an
embedding had too many rows, which can shift image rows onto different
placeholder tokens, and counted only the first dimension of higher-rank
encoder outputs. Require an exact flattened token-row count at final
placement and report mismatches with both counts and a chunked-prefill
hint. Model-owned padding/trimming and EVS placeholder redistribution keep
their existing behavior.

Relationship to upstream: sgl-project#36724 (open) requires exact
token counts for fresh encoder output before cache insertion, as part of a
larger request-isolation change, but leaves _adjust_embedding_length's
suffix crop at final placement unchanged. Main still crops.

Carried from #43.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@rodamani
rodamani marked this pull request as ready for review September 29, 2026 21:15
rodamani and others added 3 commits September 29, 2026 14:19
Cropping overlong multimodal embeddings with a warning stays the default.
SGLANG_ENABLE_STRICT_MM_EMBEDDING_LENGTH=1 raises on any mismatch between
flattened embedding rows and placeholder tokens instead. Restores main's crop
tests and the test file's original CI suite.

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
@rodamani rodamani changed the title [MM] Require exact multimodal embedding row counts at final placement [MM] Add opt-in exact multimodal embedding row-count check at final placement Sep 29, 2026
@rodamani

Copy link
Copy Markdown
Contributor Author

/tag-and-rerun-ci

@github-actions github-actions Bot added the run-ci CI: run the baseline test suite on this PR label Sep 30, 2026

This branch has not been deployed

No deployments
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.

2 participants