Skip to content

Commit 5baaa24

Browse files
committed
Address PR #313 Copilot review: Pillow extra + drop dead preprocess_weights
1) Add Pillow to the ort-genai optional-dependencies extra. The examples/qwen3_6_35b_a3b_ort_genai.py and other multimodal example scripts import PIL.Image, but the doc says 'pip install mobius-ai[ort-genai]' which previously installed only onnxruntime-genai. Without this users hit ModuleNotFoundError when running --image. 2) Remove Qwen35MoEVLDecoderModel.preprocess_weights. The method was unreachable: this class is only ever constructed as a sub-module of Qwen35MoEVL3ModelCausalLMModel and is not registered standalone, so the wrapper's preprocess_weights does all weight routing (prefix-strip + MoE expert unpack + tied lm_head). The removed method also had two latent bugs (tie_word_embeddings checked for the un-stripped key 'model.embed_tokens.weight' that never exists post-strip; fused MoE expert tensors were not unpacked into per-expert ONNX initializers). Rather than fix dead code, drop it and document why the class has no preprocess_weights. Signed-off-by: justinchuby <[email protected]>
1 parent d4a1d4a commit 5baaa24

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

‎pyproject.toml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ testing = [
4545
"librosa",
4646
"jsonschema>=4.0",
4747
]
48-
ort-genai = ["onnxruntime-genai"]
48+
ort-genai = ["onnxruntime-genai", "Pillow"]
4949
docs = ["furo", "myst-parser", "sphinx", "sphinx_copybutton"]
5050

5151
[tool.setuptools.packages.find]

‎src/mobius/models/qwen35.py‎

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -616,26 +616,13 @@ def forward(
616616
logits = self.lm_head(op, hidden_states)
617617
return logits, present_key_values
618618

619-
def preprocess_weights(
620-
self, state_dict: dict[str, torch.Tensor]
621-
) -> dict[str, torch.Tensor]:
622-
"""Route language_model weights for standalone decoder build."""
623-
renamed: dict[str, torch.Tensor] = {}
624-
for key, value in state_dict.items():
625-
if key.startswith(("mtp_", "mtp.")):
626-
continue
627-
stripped = key
628-
if stripped.startswith("model."):
629-
stripped = stripped[len("model.") :]
630-
if stripped.startswith("visual."):
631-
continue
632-
if stripped.startswith("language_model."):
633-
stripped = stripped[len("language_model.") :]
634-
renamed[stripped] = value
635-
if self.config.tie_word_embeddings:
636-
if "lm_head.weight" not in renamed and "model.embed_tokens.weight" in renamed:
637-
renamed["lm_head.weight"] = renamed["model.embed_tokens.weight"]
638-
return renamed
619+
# No preprocess_weights here: this class is an internal sub-module of
620+
# Qwen35MoEVL3ModelCausalLMModel (constructed at line ~667 below) and is
621+
# never registered standalone. The wrapper's preprocess_weights handles
622+
# all HF weight routing for the 3-model package, including the fused
623+
# MoE expert unpack and the tied lm_head/embeddings hookup. Adding a
624+
# standalone preprocess_weights here would be dead code at best and
625+
# confusingly out-of-sync with the wrapper at worst.
639626

640627

641628
class Qwen35MoEVL3ModelCausalLMModel(nn.Module):

0 commit comments

Comments
 (0)