[Hy4] support Hy4-preview model (#54160)

Signed-off-by: chengvjiang <chengvjiang@tencent.com>
Signed-off-by: Jee Jee Li <jeejeelee@inferact.ai>
Signed-off-by: Bugen Zhao <i@bugenzhao.com>
Signed-off-by: Jee Jee Li <pandaleefree@gmail.com>
Co-authored-by: chengvjiang <chengvjiang@tencent.com>
Co-authored-by: Jee Jee Li <jeejeelee@inferact.ai>
Co-authored-by: Bugen Zhao <i@bugenzhao.com>
Co-authored-by: russellfeng <russellfeng@tencent.com>
Co-authored-by: Jee Jee Li <pandaleefree@gmail.com>
This commit is contained in:
Cheng Jiang
2026-08-29 12:07:28 +08:00
committed by GitHub
co-authored by chengvjiang Jee Jee Li Bugen Zhao russellfeng Jee Jee Li
parent 6c18a54648
commit b2f685834a
47 changed files with 6260 additions and 217 deletions
+10 -2
View File
@@ -874,12 +874,20 @@ def _try_load_fp8_indexer_wk(
# We have both weight and scale: dequantize FP8 to BF16.
weight_fp8, scale_inv = entry["weight"], entry["scale"]
del buf[layer_prefix]
if scale_inv.dtype in (torch.uint8, torch.float8_e8m0fnu):
# MXFP8 checkpoints store power-of-two E8M0 scales, decode them to float.
scale_inv = scale_inv.view(torch.float8_e8m0fnu).to(torch.float32)
if scale_inv.ndim == 1:
# Per-channel scale: one scale per row of [out, in]
group_shape = GroupShape(1, weight_fp8.shape[1])
else:
block_size = weight_fp8.shape[1] // scale_inv.shape[1]
group_shape = GroupShape(block_size, block_size)
# Derive the block size independently per dim so that per-channel
# ([out, 1]), MX ([out, in / 32]) and 2D block ([out / 128, in / 128])
# scale layouts are all handled.
group_shape = GroupShape(
weight_fp8.shape[0] // scale_inv.shape[0],
weight_fp8.shape[1] // scale_inv.shape[1],
)
weight_bf16 = scaled_dequantize(
weight_fp8,
scale_inv,