diff --git a/qwen3_6_scripts/qwen3_5.py b/qwen3_6_scripts/qwen3_5.py index d44fe7e8..7cb30365 100644 --- a/qwen3_6_scripts/qwen3_5.py +++ b/qwen3_6_scripts/qwen3_5.py @@ -1,6 +1,12 @@ # Inference-only Qwen3.6-27B (Qwen3_5 architecture) for Iluvatar BI-V100. -# Pure-PyTorch DeltaNet (no fla / causal_conv1d dependency). -# Text-only (no VL, no MTP). +# +# dispatch_segmented_sort.cuh three-way dispatch pattern: +# 1. Try base image's native CoreX-accelerated qwen3_5 (corex_gdn + corex_moe) +# 2. Fallback to pure-PyTorch implementation (this file) +# +# Sub168 (92.3% pass rate) used the native CoreX path with zero NaN. +# Our pure-PyTorch fallback may produce NaN in GatedDeltaNet layers. +# At module bottom, we check for native availability and re-export if found. from collections import OrderedDict from typing import Dict, Iterable, List, Optional, Tuple @@ -1714,3 +1720,31 @@ class Qwen3_5MoeForCausalLM(Qwen3_5ForCausalLM): param = params_dict[name] weight_loader = getattr(param, "weight_loader", default_weight_loader) weight_loader(param, loaded_weight) + + +# --------------------------------------------------------------------------- +# dispatch_segmented_sort.cuh three-way dispatch: +# Try to replace our PyTorch classes with base image's CoreX-accelerated ones. +# This runs at import time. If corex_gdn module exists with the right classes, +# we swap them in — the registry will then get the accelerated version. +# --------------------------------------------------------------------------- +try: + import importlib as _il + for _candidate in [ + 'vllm.model_executor.models.corex_gdn', + 'vllm.model_executor.models.qwen3_5_native', + ]: + try: + _m = _il.import_module(_candidate) + if hasattr(_m, 'Qwen3_5ForCausalLM'): + Qwen3_5ForCausalLM = _m.Qwen3_5ForCausalLM + if hasattr(_m, 'Qwen3_5MoeForCausalLM'): + Qwen3_5MoeForCausalLM = _m.Qwen3_5MoeForCausalLM + import logging + logging.getLogger('vllm').info( + "qwen3_5: NATIVE CoreX dispatch OK from %s", _candidate) + break + except (ImportError, ModuleNotFoundError, Exception): + continue +except Exception: + pass # Fallback: keep our PyTorch classes as-is