-
Notifications
You must be signed in to change notification settings - Fork 102
feat(vllm-0.24): add Qwen3.5 text-only runtime compatibility #383
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
Open
CherryLemon
wants to merge
7
commits into
v0.3.0-dev
Choose a base branch
from
feat/v030dev-qwen35-runtime-compat
base: v0.3.0-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
eafd810
feat(vllm-0.24): support Qwen3.5 text-only models at runtime
CherryLemon a363521
fix(moe): patch vLLM 0.24 moe_sum through FlagGems
CherryLemon de5c55b
fix(moe): preserve upstream quantized methods
CherryLemon 2b0f65e
refactor(qwen3.5): rely on the vLLM 0.24 branch contract
CherryLemon 92d8a6e
refactor(moe): dispatch moe_sum through OpManager
CherryLemon 04069d2
refactor(qwen3.5): target canonical text config
CherryLemon ffcf599
docs(moe): name the dispatch bridge accurately
CherryLemon 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import sys | ||
| from types import ModuleType | ||
|
|
||
| from vllm_fl.dispatch.backends.vendor.cuda.impl.fused_moe import moe_sum_cuda | ||
|
|
||
|
|
||
| def test_cuda_moe_sum_unwraps_dispatch_adapter(monkeypatch): | ||
| calls = [] | ||
| custom_ops = ModuleType("vllm._custom_ops") | ||
|
|
||
| def native_moe_sum(inp, out): | ||
| calls.append(("native", inp, out)) | ||
|
|
||
| def dispatch_adapter(inp, out): | ||
| calls.append(("dispatch", inp, out)) | ||
|
|
||
| dispatch_adapter._vllm_fl_original = native_moe_sum | ||
| custom_ops.moe_sum = dispatch_adapter | ||
| monkeypatch.setitem(sys.modules, "vllm._custom_ops", custom_ops) | ||
|
|
||
| inp, out = object(), object() | ||
| moe_sum_cuda(inp, out) | ||
|
|
||
| assert calls == [("native", inp, out)] |
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,56 @@ | ||
| # Copyright (c) 2026 BAAI. All rights reserved. | ||
|
|
||
| from unittest.mock import MagicMock, patch | ||
|
|
||
| from vllm_fl.ops.fused_moe import layer | ||
|
|
||
|
|
||
| def _runner_with_quant_method(quant_method): | ||
| runner = MagicMock() | ||
| runner._quant_method = quant_method | ||
| runner.moe_config = MagicMock() | ||
| return runner | ||
|
|
||
|
|
||
| def test_fused_moe_fl_replaces_unquantized_method(): | ||
| quant_method = MagicMock(spec=layer.UnquantizedFusedMoEMethod) | ||
| runner = _runner_with_quant_method(quant_method) | ||
| replacement = MagicMock() | ||
|
|
||
| with ( | ||
| patch.object(layer, "_OrigFusedMoE", return_value=runner), | ||
| patch.object( | ||
| layer, | ||
| "UnquantizedFusedMoEMethodFL", | ||
| return_value=replacement, | ||
| ) as replacement_cls, | ||
| patch.object(layer, "replace_router_with_fl") as replace_router, | ||
| ): | ||
| result = layer.FusedMoEFL(test_arg=True) | ||
|
|
||
| assert result is runner | ||
| replacement_cls.assert_called_once_with(runner.moe_config) | ||
| runner._replace_quant_method.assert_called_once_with(replacement) | ||
| replace_router.assert_called_once_with() | ||
|
|
||
|
|
||
| def test_fused_moe_fl_preserves_quantized_method(): | ||
| quant_method = object() | ||
| runner = _runner_with_quant_method(quant_method) | ||
|
|
||
| with ( | ||
| patch.object(layer, "_OrigFusedMoE", return_value=runner), | ||
| patch.object(layer, "UnquantizedFusedMoEMethodFL") as replacement_cls, | ||
| patch.object(layer, "replace_router_with_fl") as replace_router, | ||
| patch.object(layer.logger, "info_once") as info_once, | ||
| ): | ||
| result = layer.FusedMoEFL() | ||
|
|
||
| assert result is runner | ||
| replacement_cls.assert_not_called() | ||
| runner._replace_quant_method.assert_not_called() | ||
| replace_router.assert_called_once_with() | ||
| info_once.assert_called_once_with( | ||
| "Preserving upstream quantized MoE method %s in FusedMoEFL.", | ||
| "object", | ||
| ) |
Empty file.
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,73 @@ | ||
| from types import ModuleType | ||
|
|
||
| from vllm_fl.patches import moe_sum | ||
|
|
||
|
|
||
| class _FakeTensor: | ||
| def __init__(self, numel, hidden_stride=1): | ||
| self._numel = numel | ||
| self._hidden_stride = hidden_stride | ||
|
|
||
| def numel(self): | ||
| return self._numel | ||
|
|
||
| def stride(self, dim): | ||
| assert dim == -1 | ||
| return self._hidden_stride | ||
|
|
||
|
|
||
| def test_moe_sum_patch_routes_nonempty_and_guards_empty(monkeypatch): | ||
| calls = [] | ||
| ops = ModuleType("fake_vllm_custom_ops") | ||
| ops.moe_sum = lambda input, output: calls.append(("original", input, output)) | ||
|
|
||
| monkeypatch.setattr( | ||
| moe_sum, "use_flaggems_op", lambda op_name: op_name == "moe_sum" | ||
| ) | ||
| monkeypatch.setattr( | ||
| moe_sum, | ||
| "_dispatch_moe_sum", | ||
| lambda input, output: calls.append(("dispatch", input, output)), | ||
| ) | ||
|
|
||
| assert moe_sum.patch_vllm_moe_sum(ops) is True | ||
| assert moe_sum.patch_vllm_moe_sum(ops) is False | ||
|
|
||
| nonempty_input = _FakeTensor(24) | ||
| nonempty_output = _FakeTensor(8) | ||
| ops.moe_sum(nonempty_input, nonempty_output) | ||
| ops.moe_sum(_FakeTensor(0), nonempty_output) | ||
|
|
||
| assert calls == [("dispatch", nonempty_input, nonempty_output)] | ||
| assert ops.moe_sum._vllm_fl_original is not ops.moe_sum | ||
|
|
||
|
|
||
| def test_moe_sum_patch_uses_stride_safe_fallback(monkeypatch): | ||
| calls = [] | ||
| ops = ModuleType("fake_vllm_custom_ops") | ||
| ops.moe_sum = lambda input, output: None | ||
|
|
||
| monkeypatch.setattr(moe_sum, "use_flaggems_op", lambda op_name: True) | ||
| monkeypatch.setattr( | ||
| moe_sum, | ||
| "_torch_moe_sum", | ||
| lambda input, output: calls.append((input, output)), | ||
| ) | ||
|
|
||
| assert moe_sum.patch_vllm_moe_sum(ops) is True | ||
| noncontiguous_input = _FakeTensor(24, hidden_stride=2) | ||
| output = _FakeTensor(8) | ||
| ops.moe_sum(noncontiguous_input, output) | ||
|
|
||
| assert calls == [(noncontiguous_input, output)] | ||
|
|
||
|
|
||
| def test_moe_sum_patch_respects_flaggems_disable(monkeypatch): | ||
| ops = ModuleType("fake_vllm_custom_ops") | ||
| original = lambda input, output: None | ||
| ops.moe_sum = original | ||
|
|
||
| monkeypatch.setattr(moe_sum, "use_flaggems_op", lambda op_name: False) | ||
|
|
||
| assert moe_sum.patch_vllm_moe_sum(ops) is False | ||
| assert ops.moe_sum is original |
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,116 @@ | ||
| from types import SimpleNamespace | ||
|
|
||
| from vllm_fl.patches import qwen3_5_text as compat | ||
|
|
||
|
|
||
| def test_apply_registers_only_plugin_owned_lazy_models(monkeypatch): | ||
| from vllm.model_executor.models import ( | ||
| config as model_config, | ||
| registry as model_registry, | ||
| ) | ||
| from vllm.transformers_utils import config as transformers_config | ||
|
|
||
| registered = {} | ||
| fake_registry = SimpleNamespace( | ||
| register_model=lambda architecture, model: registered.__setitem__( | ||
| architecture, model | ||
| ) | ||
| ) | ||
| monkeypatch.setattr(transformers_config, "_CONFIG_REGISTRY", {}) | ||
| monkeypatch.setattr(model_config, "MODELS_CONFIG_MAP", {}) | ||
| monkeypatch.setattr(model_registry, "_TEXT_GENERATION_MODELS", {}) | ||
| monkeypatch.setattr(model_registry, "_VLLM_MODELS", {}) | ||
| monkeypatch.setattr(model_registry, "ModelRegistry", fake_registry) | ||
|
|
||
| assert compat.apply_qwen3_5_text_patches() is True | ||
|
|
||
| assert registered == { | ||
| "Qwen3_5ForCausalLM": ("vllm_fl.models.qwen3_5:Qwen3_5ForCausalLM"), | ||
| "Qwen3_5MoeForCausalLM": ("vllm_fl.models.qwen3_5:Qwen3_5MoeForCausalLM"), | ||
| } | ||
| assert transformers_config._CONFIG_REGISTRY == { | ||
| "qwen3_5_text": "Qwen3_5TextConfig", | ||
| "qwen3_5_moe_text": "Qwen3_5MoeTextConfig", | ||
| } | ||
| assert { | ||
| "Qwen3_5ForCausalLM": compat.Qwen3_5ForConditionalGenerationConfig, | ||
| "Qwen3_5MoeForCausalLM": compat.Qwen3_5ForConditionalGenerationConfig, | ||
| } == model_config.MODELS_CONFIG_MAP | ||
|
|
||
|
|
||
| def test_lazy_model_shim_marks_upstream_classes_hybrid(): | ||
| from vllm_fl.models.qwen3_5 import ( | ||
| Qwen3_5ForCausalLM, | ||
| Qwen3_5MoeForCausalLM, | ||
| ) | ||
|
|
||
| for model_cls in (Qwen3_5ForCausalLM, Qwen3_5MoeForCausalLM): | ||
| assert model_cls.is_hybrid is True | ||
| assert hasattr(model_cls, "get_mamba_state_dtype_from_config") | ||
| assert hasattr(model_cls, "get_mamba_state_shape_from_config") | ||
| assert hasattr(model_cls, "get_mamba_state_copy_func") | ||
|
|
||
|
|
||
| def test_lazy_model_shim_remaps_vl_checkpoint_weights(monkeypatch): | ||
| from vllm_fl.models import qwen3_5 | ||
|
|
||
| calls = {} | ||
|
|
||
| class FakeLoader: | ||
| def __init__(self, model, **kwargs): | ||
| calls["init"] = (model, kwargs) | ||
|
|
||
| def load_weights(self, weights, **kwargs): | ||
| calls["load"] = (weights, kwargs) | ||
| return {"loaded"} | ||
|
|
||
| monkeypatch.setattr(qwen3_5, "AutoWeightsLoader", FakeLoader) | ||
| model = object() | ||
| weights = [("model.language_model.proj.weight", object())] | ||
|
|
||
| assert qwen3_5._load_weights(model, weights) == {"loaded"} | ||
| assert calls["init"] == ( | ||
| model, | ||
| { | ||
| "skip_prefixes": ["mtp."], | ||
| "ignore_unexpected_prefixes": ["model.visual."], | ||
| }, | ||
| ) | ||
| assert calls["load"][0] is weights | ||
| assert calls["load"][1]["mapper"] is qwen3_5._WEIGHTS_MAPPER | ||
| assert qwen3_5._WEIGHTS_MAPPER.orig_to_new_prefix == { | ||
| "model.language_model.": "model." | ||
| } | ||
|
|
||
|
|
||
| def test_lazy_model_shim_declares_hf_to_vllm_mapper(): | ||
| """configure_quant_config needs the class attribute, not just load_weights. | ||
|
|
||
| Rebinding load_weights fixes weight names only. The FP8 ignored_layers | ||
| rewrite goes through this attribute, and its absence fails silently. | ||
| """ | ||
| from vllm.model_executor.models import qwen3_5 as upstream | ||
|
|
||
| from vllm_fl.models import qwen3_5 # noqa: F401 - import applies the shim | ||
|
|
||
| mapper = upstream.Qwen3_5ForCausalLMBase.hf_to_vllm_mapper | ||
| assert mapper is not None | ||
| assert mapper.orig_to_new_prefix == {"model.language_model.": "model."} | ||
|
|
||
| for model_cls in (upstream.Qwen3_5ForCausalLM, upstream.Qwen3_5MoeForCausalLM): | ||
| assert model_cls.hf_to_vllm_mapper is mapper | ||
|
|
||
|
|
||
| def test_lazy_model_shim_keeps_existing_hf_to_vllm_mapper(monkeypatch): | ||
| """Compose with the vLLM-side source patch instead of overwriting it.""" | ||
| from vllm.model_executor.models import qwen3_5 as upstream | ||
|
|
||
| from vllm_fl.models import qwen3_5 | ||
|
|
||
| sentinel = object() | ||
| monkeypatch.setattr( | ||
| upstream.Qwen3_5ForCausalLMBase, "hf_to_vllm_mapper", sentinel, raising=False | ||
| ) | ||
| qwen3_5._patch_upstream_base() | ||
|
|
||
| assert upstream.Qwen3_5ForCausalLMBase.hf_to_vllm_mapper is sentinel |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
provide a general readme instead model-level readme
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated. I replaced the model-specific section with a general
Runtime compatibility hookssection describing plugin-owned config/model registration and OpManager-based operator adapters. Model-specific implementation details remain in the code and PR description.