Repository navigation
feat(mm-routing): add Qwen video-aware KV routing for SGLang #15014
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
a62a072
feat(mm-routing): add Qwen video routing for SGLang
krishung5 93d32bd
Merge remote-tracking branch 'origin/main' into feat/sglang-qwen-vide…
krishung5 28b6eb6
fix(mm-routing): address SGLang video routing CI failures
krishung5 6dbaca4
fix(mm-routing): align SGLang video routing contracts
krishung5 4b6af2b
fix(mm-routing): harden SGLang video contracts
krishung5 f3dddc5
Merge remote-tracking branch 'origin/main' into feat/sglang-qwen-vide…
krishung5 dbf8cc8
test(mm-routing): keep independent model gate cases
krishung5 b2c14f3
Merge remote-tracking branch 'origin/main' into feat/sglang-qwen-vide…
furionw 3e9b667
docs(sglang): document video-aware KV routing
furionw a5dcabb
Merge branch 'main' into feat/sglang-qwen-video-routing
KrishnanPrash b8d23aa
Merge branch 'main' into feat/sglang-qwen-video-routing
rmccorm4 04613ba
Merge remote-tracking branch 'origin/main' into feat/sglang-qwen-vide…
furionw File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
138 changes: 138 additions & 0 deletions
138
components/src/dynamo/sglang/tests/test_sglang_video_routing.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,138 @@ | ||
| # SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. | ||
| # SPDX-License-Identifier: Apache-2.0 | ||
|
|
||
| import json | ||
| from types import SimpleNamespace | ||
|
|
||
| import pytest | ||
|
|
||
| from dynamo.llm import ModelRuntimeConfig | ||
| from dynamo.sglang import video_routing | ||
|
|
||
| pytestmark = [ | ||
| pytest.mark.unit, | ||
| pytest.mark.sglang, | ||
| pytest.mark.multimodal, | ||
| pytest.mark.gpu_0, | ||
| pytest.mark.profiled_vram_gib(0), | ||
| pytest.mark.pre_merge, | ||
| ] | ||
|
|
||
|
|
||
| def _engine( | ||
| *, | ||
| video_config=None, | ||
| model_type="qwen3_vl", | ||
| architecture="Qwen3VLForConditionalGeneration", | ||
| overrides_video_replacement=True, | ||
| ): | ||
| if overrides_video_replacement: | ||
|
|
||
| class QwenProcessor(video_routing.transformers.ProcessorMixin): | ||
| def replace_video_token(self): | ||
| return None | ||
|
|
||
| else: | ||
|
|
||
| class QwenProcessor(video_routing.transformers.ProcessorMixin): | ||
| pass | ||
|
|
||
| mm_processor = SimpleNamespace( | ||
| hf_config=SimpleNamespace( | ||
| model_type=model_type, | ||
| architectures=[architecture], | ||
| ), | ||
| video_config=video_config or {}, | ||
| _processor=QwenProcessor.__new__(QwenProcessor), | ||
| ) | ||
| return SimpleNamespace( | ||
| tokenizer_manager=SimpleNamespace(mm_processor=mm_processor) | ||
| ) | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def qwen_preprocessor(monkeypatch): | ||
| monkeypatch.setattr( | ||
| video_routing, | ||
| "sglang_qwen_vl", | ||
| SimpleNamespace( | ||
| IMAGE_FACTOR=28, | ||
| VIDEO_MIN_PIXELS=100352, | ||
| VIDEO_MAX_PIXELS=602112, | ||
| VIDEO_TOTAL_PIXELS=90316800, | ||
| FRAME_FACTOR=2, | ||
| FPS=2.0, | ||
| FPS_MIN_FRAMES=4, | ||
| FPS_MAX_FRAMES=768, | ||
| ), | ||
| ) | ||
| monkeypatch.setattr( | ||
| video_routing, | ||
| "qwen3_smart_resize", | ||
| lambda **_: (1216, 4096), | ||
| ) | ||
|
|
||
|
|
||
| def test_publishes_sglang_qwen_video_contract(qwen_preprocessor): | ||
| runtime_config = ModelRuntimeConfig() | ||
|
|
||
| video_routing.publish_sglang_qwen_video_processor_contract( | ||
| runtime_config, _engine() | ||
| ) | ||
|
|
||
| contract = json.loads( | ||
| runtime_config.runtime_data[ | ||
| video_routing.SGLANG_QWEN_VIDEO_PROCESSOR_CONTRACT_RUNTIME_KEY | ||
| ] | ||
| ) | ||
| assert contract == { | ||
| "placeholder_target": "bare_video_token", | ||
| "resize_mode": "legacy_ceil", | ||
| "runless_boundary_hash": "tokens_only", | ||
| "sglang_preprocess": { | ||
| "image_factor": 28, | ||
| "video_min_pixels": 100352, | ||
| "video_max_pixels": 602112, | ||
| "video_total_pixels": 90316800, | ||
| "frame_factor": 2, | ||
| "fps": 2.0, | ||
| "min_frames": 4, | ||
| "max_frames": 768, | ||
| }, | ||
| } | ||
|
|
||
|
|
||
| def test_processor_override_disables_exact_video_contract(qwen_preprocessor): | ||
| assert ( | ||
| video_routing._resolve_qwen_video_processor_contract( | ||
| _engine(video_config={"fps": 1.0}) | ||
| ) | ||
| is None | ||
| ) | ||
|
|
||
|
|
||
| def test_inherited_video_replacement_publishes_wrapped_target(qwen_preprocessor): | ||
| contract = video_routing._resolve_qwen_video_processor_contract( | ||
| _engine(overrides_video_replacement=False) | ||
| ) | ||
|
|
||
| assert contract is not None | ||
| assert contract["placeholder_target"] == "vision_wrapped_video_token" | ||
|
|
||
|
|
||
| @pytest.mark.parametrize( | ||
| ("model_type", "architecture"), | ||
| [ | ||
| ("llava", "LlavaForConditionalGeneration"), | ||
|
krishung5 marked this conversation as resolved.
Resolved
|
||
| ("qwen3_vl", "Qwen3VLForCausalLM"), | ||
| ], | ||
| ) | ||
| def test_non_qwen_video_model_does_not_publish_contract( | ||
| qwen_preprocessor, model_type, architecture | ||
| ): | ||
| assert ( | ||
| video_routing._resolve_qwen_video_processor_contract( | ||
| _engine(model_type=model_type, architecture=architecture) | ||
| ) | ||
| is None | ||
| ) | ||
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.