Skip to content

Kyojin: open-source engine that runs 100 GB-class open models (GLM-5.3, Qwen3.8, DeepSeek V4.1) on one desktop machine. AMD Strix Halo, NVIDIA RTX and Apple Mac. OpenAI API, built on ExLlamaV3.

Read MXFP8 inputs (FP8 weights with U8 E8M0 weight_scale_inv, block 1x32) in the shared reader and in Linear

YanissAmz60746bb01446
diff --git a/exllamav3/foreign_quant/vendor_input.py b/exllamav3/foreign_quant/vendor_input.py
index 8d6f245..9956a6f 100644
--- a/exllamav3/foreign_quant/vendor_input.py
+++ b/exllamav3/foreign_quant/vendor_input.py
@@ -12,6 +12,7 @@ Formats (value = decoded payload x scale, all in float32):
`P.weight_scale_inv` DeepSeek / Qwen3-FP8 / GLM / MiniMax: 2D grid, block 128x128, ceil-div
`P.weight_scale` per-tensor ([] or [1]), per-channel ([out] / [out,1]) or 2D grid
`P.scale` DeepSeek-V4: F8_E8M0 grid (32x32 in that checkpoint)
+ a U8 / F8_E8M0 scale on FP8 weights is MXFP8 (MiniMax-M3): E8M0 exponent per 32 inputs, [out, in/32]
no scale tensor -> scale 1 (plain cast).
mxfp4 OCP microscaling E2M1 + E8M0 per 32 inputs, two nibbles per byte, LOW nibble first:
linear: `P.weight` I8/U8 [out,in/2] + `P.scale` F8_E8M0 or `P.weight_scale` U8/E8M0 [out,in/32]
@@ -160,6 +161,11 @@ class SafetensorsFile:
return m["dtype"], tuple(m["shape"]), a.reshape(m["shape"])
+def scale_to_f32(tag, a):
+ """Decode a scale tensor: U8 scales (MXFP8 `weight_scale_inv`, MXFP4 `weight_scale`) are E8M0 exponent bytes."""
+ return e8m0_to_f32(a) if tag == "U8" else to_f32(tag, a)
+
+
def to_f32(tag, a):
"""Decode a raw storage array of safetensors dtype `tag` to float32."""
if tag == "F32":
@@ -205,6 +211,10 @@ class Checkpoint:
tag, _, a = self.raw(name)
return to_f32(tag, a)
+ def scale_f32(self, name):
+ tag, _, a = self.raw(name)
+ return scale_to_f32(tag, a)
+
def close(self):
for st in self.files.values():
st.close()
@@ -405,10 +415,10 @@ def load_linear(ck, prefix, block=None):
if fmt == "mxfp4_blocks":
return dequant_mxfp4_blocks(w, ck.raw(c["scale"])[2])
if fmt.startswith("fp8_"):
- s = None if fmt == "fp8_noscale" else ck.f32(c["scale"])
+ s = None if fmt == "fp8_noscale" else ck.scale_f32(c["scale"])
return dequant_fp8(w, tag, s, block)
if fmt == "mxfp4":
- return dequant_mxfp4_linear(w, e8m0_to_f32(ck.raw(c["scale"])[2])) # U8 scales are E8M0 bytes
+ return dequant_mxfp4_linear(w, ck.scale_f32(c["scale"]))
if fmt == "nvfp4":
if c["scale2"] is None:
raise ValueError(f"{prefix}: NVFP4 without a global scale tensor")
diff --git a/exllamav3/modules/linear.py b/exllamav3/modules/linear.py
index dee7257..1db1ef0 100644
--- a/exllamav3/modules/linear.py
+++ b/exllamav3/modules/linear.py
@@ -294,6 +294,11 @@ class Linear(Module):
scale = self.config.stc.get_tensor(key + ".weight_scale", dev, transpose = self.transposed_load, optional = True, no_defer = True)
scale_inv = self.config.stc.get_tensor(key + ".weight_scale_inv", dev, transpose = self.transposed_load, optional = True, no_defer = True)
assert scale is None or scale_inv is None
+ # MXFP8 (MiniMax-M3): FP8 weights with a U8 weight_scale_inv of E8M0 exponent bytes, one per 32 inputs
+ if scale_inv is not None and scale_inv.dtype == torch.uint8:
+ scale_inv = (scale_inv.float() - 127.0).exp2()
+ if scale is not None and scale.dtype == torch.uint8:
+ scale = (scale.float() - 127.0).exp2()
no_defer = self.no_defer_load or scale is not None or scale_inv is not None or self.weight_scale != 1.0
weight = self.config.stc.get_tensor(key + ".weight", dev, float2half = True, transpose = self.transposed_load, pad_to = pad2, no_defer = no_defer)
bias = self.config.stc.get_tensor(key + ".bias", dev, float2half = True, optional = True, pad_to = pad1, no_defer = no_defer)
diff --git a/tests/test_linear_vendor_load_cpu.py b/tests/test_linear_vendor_load_cpu.py
index 9807fbb..d1d0072 100644
--- a/tests/test_linear_vendor_load_cpu.py
+++ b/tests/test_linear_vendor_load_cpu.py
@@ -131,3 +131,11 @@ def test_gpt_oss_fused_mxfp4_experts(tmp_path, interleaved):
lin.load(torch.device("cpu"))
rows = full[e, 0::2] if interleaved and lo == 0 else full[e, 1::2] if interleaved else full[e, lo:hi]
check(lin.inner.weight, np.ascontiguousarray(rows))
+
+
+def test_mxfp8_u8_scale_inv(tmp_path):
+ wb = H.e4m3_bytes((48, 128), 0, 0x70)
+ sb = H.rng.integers(118, 134, size=(48, 4)).astype(np.uint8)
+ cfg = {"quantization_config": {"quant_method": "mxfp8", "weight_block_size": [1, 32]}}
+ w = make_linear(tmp_path, {"l.weight": H.t("F8_E4M3", wb), "l.weight_scale_inv": H.t("U8", sb)}, cfg, "l", 48, 128)
+ check(w, vi.dequant_fp8(wb, "F8_E4M3", vi.e8m0_to_f32(sb), (1, 32)))
diff --git a/tests/test_vendor_input_cpu.py b/tests/test_vendor_input_cpu.py
index f77ea14..90aeb42 100644
--- a/tests/test_vendor_input_cpu.py
+++ b/tests/test_vendor_input_cpu.py
@@ -325,3 +325,16 @@ def test_truncated_file_is_rejected(tmp_path):
p.write_bytes(p.read_bytes()[:-4])
with pytest.raises(ValueError):
vi.SafetensorsFile(str(p))
+
+
+def test_mxfp8_u8_weight_scale_inv_is_e8m0(tmp_path):
+ """MiniMax-M3-MXFP8 / nvidia MiniMax-M3-NVFP4 attention: F8_E4M3 weight + U8 weight_scale_inv [out, in/32] (block [1,32])."""
+ wb = e4m3_bytes((48, 128), 0, 0x70)
+ sb = rng.integers(118, 134, size=(48, 4)).astype(np.uint8)
+ T = {"a.q.weight": t("F8_E4M3", wb), "a.q.weight_scale_inv": t("U8", sb)}
+ ck = vi.Checkpoint(make_ckpt(tmp_path, T, {"quantization_config": {"quant_method": "mxfp8", "weight_block_size": [1, 32]}}))
+ assert vi.detect_checkpoint(ck.info(), ck.config)["block_size"] == (1, 32)
+ w = torch.from_numpy(wb).view(torch.float8_e4m3fn).float()
+ s = torch.from_numpy(sb.view(ml_dtypes.float8_e8m0fnu).astype(np.float32)).repeat_interleave(32, 1)
+ assert same(vi.load_linear(ck, "a.q"), (w * s).numpy())
+ ck.close()