-
Notifications
You must be signed in to change notification settings - Fork 76
Fix Qwen3.5 MoE load path in vLLM Metal #129
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
Closed
Closed
Changes from all commits
Commits
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 |
|---|---|---|
|
|
@@ -11,8 +11,10 @@ | |
| """ | ||
|
|
||
| import hashlib | ||
| import importlib | ||
| import math | ||
| import os | ||
| import sys | ||
| import time | ||
| from array import array | ||
| from dataclasses import dataclass | ||
|
|
@@ -61,6 +63,47 @@ | |
| _model_cache: dict[str, tuple[Any, Any]] = {} # model_name -> (model, tokenizer) | ||
| _model_cache_lock = Lock() | ||
|
|
||
|
|
||
| def _ensure_mlx_lm_model_aliases() -> None: | ||
| """Register temporary model-type aliases for mlx_lm compatibility. | ||
|
|
||
| Some newer model snapshots report a ``model_type`` that is not yet | ||
| available as a module in the currently bundled ``mlx_lm`` release. | ||
| In that case we register a best-effort import alias so ``mlx_lm`` can | ||
| still resolve the architecture. | ||
| """ | ||
| alias_map = { | ||
| # Qwen3.5 MoE currently reuses the same implementation shape as qwen3_moe. | ||
| "qwen3_5_moe": "qwen3_moe", | ||
| } | ||
|
|
||
| for alias, target in alias_map.items(): | ||
| alias_module = f"mlx_lm.models.{alias}" | ||
| target_module = f"mlx_lm.models.{target}" | ||
|
|
||
| if alias_module in sys.modules: | ||
| continue | ||
|
|
||
| # If mlx_lm already ships this architecture, do not override it. | ||
| try: | ||
| importlib.import_module(alias_module) | ||
| continue | ||
| except ModuleNotFoundError: | ||
| pass | ||
|
|
||
| try: | ||
| resolved = importlib.import_module(target_module) | ||
| except ModuleNotFoundError: | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
| logger.debug( | ||
| "Skipping mlx_lm alias registration for %s (target %s missing)", | ||
| alias, | ||
| target, | ||
| ) | ||
| continue | ||
|
|
||
| sys.modules[alias_module] = resolved | ||
| logger.info("Registered mlx_lm model alias: %s -> %s", alias, target) | ||
|
|
||
| # Try to import Rust extension for high-performance token state management | ||
| try: | ||
| from vllm_metal._rs import RequestStateManager as RustRequestStateManager | ||
|
|
@@ -645,6 +688,7 @@ def load_model(self) -> None: | |
| self._is_vlm = True | ||
| else: | ||
| # Load model and tokenizer using mlx_lm for text-only models | ||
| _ensure_mlx_lm_model_aliases() | ||
| self.model, self.tokenizer = mlx_lm_load( | ||
| model_name, | ||
| tokenizer_config={ | ||
|
|
||
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.
This change mixes two conflicting strategies: it raises the minimum
mlx-lmversion to one that should already include nativeqwen3_5*support, and also adds a runtime alias shim for older versions.