From db8399b62c952cb9add685158ed2c09b4cbf6b8f Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 3 Sep 2026 12:42:35 +0000 Subject: [PATCH] Update models.py: fp4 support --- BMM/BMM_Theory/bmm_theory/models.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/BMM/BMM_Theory/bmm_theory/models.py b/BMM/BMM_Theory/bmm_theory/models.py index 9ba3e57..280813b 100644 --- a/BMM/BMM_Theory/bmm_theory/models.py +++ b/BMM/BMM_Theory/bmm_theory/models.py @@ -28,13 +28,15 @@ DTYPE_BYTES = { "fp8_e4m3": 1, "fp8_e5m2": 1, "int8": 1, + "fp4": 0.5, # 半字节 (对齐 bmmv3, 2026-09-03) + "fp4_e2m1": 0.5, } -# Cube 累加器 (L0C) 中元素字节数: 16bit 输入 -> fp32 累加; fp8 输入 -> fp32 累加 +# Cube 累加器 (L0C) 中元素字节数: 16bit 输入 -> fp32 累加; fp8/fp4 输入 -> fp32 累加 L0C_DTYPE_BYTES = 4 -def dtype_bytes(dtype: str) -> int: +def dtype_bytes(dtype: str) -> float: key = dtype.strip().lower() if key not in DTYPE_BYTES: raise ValueError(f"不支持的 dtype: {dtype!r}, 支持 {sorted(DTYPE_BYTES)}") @@ -109,12 +111,13 @@ class BmmCase: return max(self.batch_a, self.batch_b) @property - def dtype_in_bytes(self) -> int: + def dtype_in_bytes(self) -> float: # A/B 输入元素字节数 (要求 A/B 同 dtype, 不一致时取较大者并在校验中报 warning) + # 返回 float 以兼容 fp4 (0.5B) return max(dtype_bytes(self.dtype_a), dtype_bytes(self.dtype_b)) @property - def dtype_out_bytes(self) -> int: + def dtype_out_bytes(self) -> float: return dtype_bytes(self.dtype_c) @property