@@ -4291,6 +4291,61 @@ def test_preflight_records_mapped_bias_and_scale_parameters(self) -> None:
42914291 stat .source_bytes for stat in report .source_qtype_census
42924292 )
42934293
4294+ def test_qwen35moe_mixed_float_experts_fail_closed_on_default_route (self ) -> None :
4295+ """The quantized Qwen3.5-MoE route must not requantize source-float experts."""
4296+ from gguf import GGMLQuantizationType
4297+ from onnxscript import nn
4298+
4299+ from mobius .components import QuantizedLinear
4300+ from mobius .integrations .gguf ._builder import _preflight_quantization_report
4301+
4302+ def make_expert () -> nn .Module :
4303+ expert = nn .Module ()
4304+ expert .gate_proj = QuantizedLinear (64 , 64 )
4305+ expert .up_proj = QuantizedLinear (64 , 64 )
4306+ expert .down_proj = QuantizedLinear (64 , 64 )
4307+ return expert
4308+
4309+ mlp = nn .Module ()
4310+ mlp .experts = nn .ModuleList ([make_expert (), make_expert ()])
4311+ layer = nn .Module ()
4312+ layer .mlp = mlp
4313+ layer .self_attn = nn .Module ()
4314+ layer .self_attn .o_proj = QuantizedLinear (64 , 64 )
4315+ module = nn .Module ()
4316+ module .model = nn .Module ()
4317+ module .model .layers = nn .ModuleList ([layer ])
4318+ tensors = [
4319+ SimpleNamespace (
4320+ name = "blk.0.attn_output.weight" ,
4321+ tensor_type = GGMLQuantizationType .Q4_0 ,
4322+ shape = (64 , 64 ),
4323+ n_bytes = 2_304 ,
4324+ ),
4325+ SimpleNamespace (
4326+ name = "blk.0.ffn_gate_exps.weight" ,
4327+ tensor_type = GGMLQuantizationType .F16 ,
4328+ shape = (64 , 64 , 2 ),
4329+ n_bytes = 16_384 ,
4330+ ),
4331+ ]
4332+ source = SimpleNamespace (reader_tensors = lambda : iter (tensors ), _reader = None )
4333+
4334+ with pytest .raises (
4335+ ValueError ,
4336+ match = "selected quantized graph would quantize a source-float tensor" ,
4337+ ):
4338+ _preflight_quantization_report (
4339+ source ,
4340+ "qwen35moe" ,
4341+ module ,
4342+ SimpleNamespace (),
4343+ preserve_quantization = True ,
4344+ target_bits = 4 ,
4345+ target_block_size = 32 ,
4346+ execution_provider = "cpu" ,
4347+ )
4348+
42944349 def test_norms_are_float (self , q4_0_gguf : Path ):
42954350 """Norm weights remain float, not quantized."""
42964351 import onnx_ir as ir
0 commit comments