Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 35 additions & 3 deletions src/mobius/_configs/_quantization.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,43 @@ def from_transformers(cls, hf_config) -> QuantizationConfig | None:
"onnxruntime_USE_FP4_QMOE=ON). Export the unquantized (bf16) "
"checkpoint instead, or quantize the bf16 export via Olive."
)
# Block-scaled fp8 (E4M3 weight + 2D UE8M0 block scale) and packed-fp4
# routed experts (I8-packed E2M1 nibbles + UE8M0 micro-scale) are a
# mixed-precision layout this INT4/per-tensor path cannot load — the
# packed [out, in/2] fp4 expert vs its logical [out, in] initializer
# produces a confusing "Weight shape mismatch". Detect it by property
# (not model name, not the ``quant_method`` string) and fail closed with
# a typed, actionable blocker naming the real layout + the runtime ABI
# gap. Checked before the ``quant_method == "none"`` early-return because
# a checkpoint can advertise fp4 experts via top-level ``expert_dtype``
# while leaving ``quant_method`` unset.
from mobius.integrations._block_quant import BlockQuantScheme

scheme = BlockQuantScheme.from_quantization_config(
qc, expert_dtype=getattr(hf_config, "expert_dtype", None)
Comment on lines +87 to +90
)
if scheme is not None:
from mobius.integrations._block_quant import BlockQuantExportError

raise BlockQuantExportError(
"Block-scaled FP8 / packed-FP4 checkpoint is not loadable by the "
"INT4/per-tensor quantization path. Detected "
f"quant_method={scheme.quant_method!r}, "
f"weight_block_size={list(scheme.weight_block_size) or None}, "
f"expert_dtype={scheme.expert_dtype!r}: block-FP8 projections "
"(E4M3 weight + 2D UE8M0 block scale) and/or FP4-packed routed "
"experts (I8-packed E2M1 nibbles + UE8M0 micro-scale). Parse and "
"validate these by property with mobius.integrations._block_quant "
"(BlockQuantScheme / classify_tensor / QuantizedTensorDescriptor); "
"the routed-expert emission gate (plan_routed_expert_bank) reports "
"the exact onnx-genai nxrt ABI gap. Native export is blocked until "
"the runtime gains a block-FP8 / planar-FP4 BlockFormat."
)
if method == "none":
return None
# FP8 per-tensor quantization (float8_e4m3fn + scalar scale)
# is handled by dtype casting in _assign_weight(), not by
# QuantizedLinear block quantization.
# Per-tensor fp8 (float8_e4m3fn + a scalar scale) is handled by dtype
# casting in _assign_weight(), so it returns None here. (Block-scaled
# fp8 was already routed to the typed blocker above.)
if method == "fp8":
return None
return cls(
Expand Down
Loading
Loading