From 2d2f638fa82833d7b899db8cb9dfc49b1954bcf4 Mon Sep 17 00:00:00 2001 From: Constantin Date: Sun, 25 Oct 2026 06:57:16 -0400 Subject: [PATCH] Document HYV3 support and add conversion recipes Add BF16-source W4/W8/block-FP8/MXFP4, native FP8-source and GGUF-to-W4 recipes. Document supported sources, precision/KV limits and unvalidated paths without calibration environment switches or performance claims. --- .../recipes/hy-memory-30b-a3b-bf16-fp8.recipe | 19 +++++++ .../hy-memory-30b-a3b-bf16-mxfp4.recipe | 18 +++++++ data/recipes/hy-memory-30b-a3b-bf16-w4.recipe | 22 ++++++++ data/recipes/hy-memory-30b-a3b-bf16-w8.recipe | 17 ++++++ data/recipes/hy-memory-30b-a3b-fp8.recipe | 34 ++++++++++++ .../hy-memory-30b-a3b-gguf-q4k-to-w4.recipe | 30 +++++++++++ docs/ARCHITECTURES.md | 54 +++++++++++++++++++ docs/GUIDE.md | 3 ++ 8 files changed, 197 insertions(+) create mode 100644 data/recipes/hy-memory-30b-a3b-bf16-fp8.recipe create mode 100644 data/recipes/hy-memory-30b-a3b-bf16-mxfp4.recipe create mode 100644 data/recipes/hy-memory-30b-a3b-bf16-w4.recipe create mode 100644 data/recipes/hy-memory-30b-a3b-bf16-w8.recipe create mode 100644 data/recipes/hy-memory-30b-a3b-fp8.recipe create mode 100644 data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe diff --git a/data/recipes/hy-memory-30b-a3b-bf16-fp8.recipe b/data/recipes/hy-memory-30b-a3b-bf16-fp8.recipe new file mode 100644 index 00000000..ffbd207d --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-bf16-fp8.recipe @@ -0,0 +1,19 @@ +# HYV3 from the BF16 checkpoint, with attention, dense/shared projections and routed experts rounded +# to block FP8. F32 scale planes are intentional: MoeFP8 format 9 consumes a 128x128 grid with +# F32 scales. Activations are dynamically quantized to E4M3 at runtime; the BF16 output head, router, +# norms and embeddings stay as stored. +# +# rad-convert \ +# --recipe data/recipes/hy-memory-30b-a3b-bf16-fp8.recipe -o hy-memory-30b-a3b-fp8.rad + +blk.*.attn_q.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.*.attn_k.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.*.attn_v.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.*.attn_output.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 + +blk.0.ffn_gate_up.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.0.ffn_down.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.*.ffn_gate_up_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 +blk.*.ffn_down_shexp.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 + +blk.*.ffn_*_exps.*.weight rtn codes=fp8_e4m3 block=128x128 scale=f32 diff --git a/data/recipes/hy-memory-30b-a3b-bf16-mxfp4.recipe b/data/recipes/hy-memory-30b-a3b-bf16-mxfp4.recipe new file mode 100644 index 00000000..770e0f9d --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-bf16-mxfp4.recipe @@ -0,0 +1,18 @@ +# HYV3 from BF16 with OCP MXFP4 weights: e2m1 codes and one e8m0 scale per 32 values of K. Quantize +# attention, dense/shared projections and routed experts; router, norms, embeddings and output head +# stay BF16. Both the regular linears and MoeFP8's expert format-8 path consume this encoding. +# +# rad-convert \ +# --recipe data/recipes/hy-memory-30b-a3b-bf16-mxfp4.recipe -o hy-memory-30b-a3b-mxfp4.rad + +blk.*.attn_q.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.*.attn_k.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.*.attn_v.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.*.attn_output.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 + +blk.0.ffn_gate_up.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.0.ffn_down.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.*.ffn_gate_up_shexp.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 +blk.*.ffn_down_shexp.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 + +blk.*.ffn_*_exps.*.weight rtn codes=fp4_e2m1 group=32 scale=e8m0 diff --git a/data/recipes/hy-memory-30b-a3b-bf16-w4.recipe b/data/recipes/hy-memory-30b-a3b-bf16-w4.recipe new file mode 100644 index 00000000..f593bc41 --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-bf16-w4.recipe @@ -0,0 +1,22 @@ +# Hy-Memory-30B-A3B from Tencent's BF16 safetensors checkpoint. Quantize attention projections, +# the dense first MLP and routed experts to native INT4. Keep shared MLPs, routers, norms, embeddings +# and the output head at BF16. Routed experts use signed INT4 with BF16 group scales; other linears +# use asymmetric U4 with F16 scales and U8 zero points. The byte-sized zero points keep TP2 column +# shards aligned even when a projection has an odd number of 128-value groups per rank. +# +# rad-convert \ +# --recipe data/recipes/hy-memory-30b-a3b-bf16-w4.recipe -o hy-memory-30b-a3b-w4.rad +# +# The W4 GEMMs consume dynamic INT8 activations. Routed/shared outputs are reduced independently at +# TP2 then combined in FP32. Use --tp 2 at serve time if one device cannot hold the .rad weights and +# KV cache. + +blk.*.attn_q.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_k.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_v.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_output.weight rtn codes=u4 zero=u8 group=128 scale=f16 + +blk.0.ffn_gate_up.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.0.ffn_down.weight rtn codes=u4 zero=u8 group=128 scale=f16 + +blk.*.ffn_*_exps.*.weight rtn codes=i4 group=128 scale=bf16 diff --git a/data/recipes/hy-memory-30b-a3b-bf16-w8.recipe b/data/recipes/hy-memory-30b-a3b-bf16-w8.recipe new file mode 100644 index 00000000..5c3152ba --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-bf16-w8.recipe @@ -0,0 +1,17 @@ +# HYV3 from BF16 with signed INT8 W8A8 linears. Attention, the dense first MLP, shared MLPs and +# output head are quantized on the 128-value K grid. Routed experts stay BF16: the current MoE block +# has no INT8 expert kernel, so this recipe does not pretend the expert weights are W8. +# +# rad-convert \ +# --recipe data/recipes/hy-memory-30b-a3b-bf16-w8.recipe -o hy-memory-30b-a3b-w8.rad + +blk.*.attn_q.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.*.attn_k.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.*.attn_v.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.*.attn_output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym + +blk.0.ffn_gate_up.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.0.ffn_down.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.*.ffn_gate_up_shexp.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +blk.*.ffn_down_shexp.weight rtn codes=i8 group=128 scale=bf16 clamp=sym +output.weight rtn codes=i8 group=128 scale=bf16 clamp=sym diff --git a/data/recipes/hy-memory-30b-a3b-fp8.recipe b/data/recipes/hy-memory-30b-a3b-fp8.recipe new file mode 100644 index 00000000..2b294f01 --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-fp8.recipe @@ -0,0 +1,34 @@ +# hy-memory-30b-a3b-fp8.recipe -- Tencent's Hy-Memory-30B-A3B-FP8 release. +# +# rad-convert \ +# --recipe data/recipes/hy-memory-30b-a3b-fp8.recipe --kv-cache-dtype fp8 \ +# -o hy-memory-30b-a3b-fp8.rad +# +# The checkpoint stores E4M3 projection codes with one F32 weight scale per tensor. Import keeps +# those codes and expands each scalar to the 128x128 F32 scale grid read by Radiance's FP8 GEMMs. +# Runtime activation quantization is dynamic; source `.input_scale` calibration scalars are ignored. +# The attention/MLP norms and router projection are widened to F32 (exact for BF16 source values), +# as required by their RMSNorm and FP32 sigmoid-router kernels. Embeddings, lm_head, and the model's +# BF16 activations remain BF16; expert correction biases are already F32. +# +# The indexed kv_cache_scales.safetensors tensors are carried into model metadata during import. +# The plugin can use those per-layer K/V descales for an E4M3 KV cache (`--kv-cache-dtype fp8`), +# or use a BF16 cache for higher precision. + +blk.*.attn_q.weight import block=128x128 scale=f32 +blk.*.attn_k.weight import block=128x128 scale=f32 +blk.*.attn_v.weight import block=128x128 scale=f32 +blk.*.attn_output.weight import block=128x128 scale=f32 +blk.0.ffn_gate_up.weight import block=128x128 scale=f32 +blk.0.ffn_down.weight import block=128x128 scale=f32 +blk.*.ffn_gate_up_exps.*.weight import block=128x128 scale=f32 +blk.*.ffn_down_exps.*.weight import block=128x128 scale=f32 +blk.*.ffn_gate_up_shexp.weight import block=128x128 scale=f32 +blk.*.ffn_down_shexp.weight import block=128x128 scale=f32 + +blk.*.attn_norm.weight cast dtype=f32 +blk.*.attn_q_norm.weight cast dtype=f32 +blk.*.attn_k_norm.weight cast dtype=f32 +blk.*.ffn_norm.weight cast dtype=f32 +blk.*.glm_router.weight cast dtype=f32 +output_norm.weight cast dtype=f32 diff --git a/data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe b/data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe new file mode 100644 index 00000000..8fb82d80 --- /dev/null +++ b/data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe @@ -0,0 +1,30 @@ +# Convert the local llama.cpp Hy-Memory Q4_K_M GGUF into native Radiance encodings. Q4_K/Q6_K +# source blocks are decoded to f32, then the attention, dense-first MLP and routed experts are +# requantized to Radiance W4; embeddings, output head, routers, norms and shared MLPs are cast to +# BF16. This adds loss to an already-quantized source; for best quality, quantize the BF16 +# safetensors checkpoint with hy-memory-30b-a3b-bf16-w4.recipe instead. +# +# rad-convert Hy-Memory-30B-A3B-Q4_K_M.gguf \ +# --tokenizer /tokenizer.json \ +# --recipe data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe -o hy-memory-30b-a3b-gguf-w4.rad + +# The model matrices have 120832 rows while the GGUF tokenizer lists 120818 strings. +token_embd.weight cast dtype=bf16 +output.weight cast dtype=bf16 + +blk.*.attn_norm.weight cast dtype=bf16 +blk.*.attn_q_norm.weight cast dtype=bf16 +blk.*.attn_k_norm.weight cast dtype=bf16 +blk.*.ffn_norm.weight cast dtype=bf16 +blk.*.ffn_gate_up_shexp.weight cast dtype=bf16 +blk.*.ffn_down_shexp.weight cast dtype=bf16 + +blk.*.attn_q.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_k.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_v.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.*.attn_output.weight rtn codes=u4 zero=u8 group=128 scale=f16 + +blk.0.ffn_gate_up.weight rtn codes=u4 zero=u8 group=128 scale=f16 +blk.0.ffn_down.weight rtn codes=u4 zero=u8 group=128 scale=f16 + +blk.*.ffn_*_exps.*.weight rtn codes=i4 group=128 scale=bf16 diff --git a/docs/ARCHITECTURES.md b/docs/ARCHITECTURES.md index bbb802b0..ea93ce74 100644 --- a/docs/ARCHITECTURES.md +++ b/docs/ARCHITECTURES.md @@ -11,6 +11,9 @@ plugin claims. | `arch/llama_dense_fp8` | `llama` | *(empty)* | the same graph from a bf16 checkpoint, linears made block fp8 by a recipe or kept bf16. MiniCPM5-2B | | `arch/qwen35_bf16` | `qwen35` | *(empty)* | the Qwen3.5/3.6/3.8 dense hybrid, served bf16 | | `arch/qwen35_fp8` | `qwen35` | `fp8_e4m3` | the same, block-scaled FP8 weights and activations | +| `arch/hyv3_bf16` | `hyv3` | *(empty)* | Tencent Hy-Memory-30B-A3B BF16 safetensors; BF16, W4, W8A8, block-FP8 or MXFP4 weights by recipe; TP1/2, BF16 KV | +| `arch/hyv3_fp8` | `hyv3` | `fp8` | Tencent Hy-Memory-30B-A3B-FP8; imported per-tensor E4M3 weights, one dense layer then sigmoid-routed MoE; TP1/2, BF16 or static-scaled E4M3 KV | +| `arch/hyv3_gguf` | `hyv3` | `gguf_ftype_15` | llama.cpp Hy-Memory Q4_K_M GGUF, dequantized and recipe-converted to native Radiance weights; TP1/2 | | `arch/qwen35_w8a8` | `qwen35` | `w8a8_fwht128` | `qwen35_fp8` with an int8 trunk: i8 weights with a bf16 scale per 128 of K, rotated by a 128-wide Hadamard, against int8 activations under the same rotation (`data/recipes/q38-27b-w8a8-df2.recipe`) | | `arch/qwen35moe_fp8` | `qwen35moe` | `fp8_e4m3` | `qwen35_fp8` with the feed-forward routed | | `arch/qwen4exp_fp8` | `qwen4exp` | *(empty)* | Qwen4-Exp (Qwen3.8-Flash-Next), a bf16 checkpoint quantised at convert | @@ -286,6 +289,57 @@ head (393 against 282 tok/s on two R9700s). `sage-a1.5-mxfp4-df2.rad` is the sam the experts and the drafter's linears at MXFP4. `--num-speculative-tokens auto` takes the depth the drafter states. +## `hyv3` + +`arch/hyv3_bf16` supports the Tencent BF16 safetensors checkpoint, and `arch/hyv3_fp8` supports +Tencent's FP8 checkpoint. Both use the same graph: 48 layers, with a dense first +MLP followed by 47 layers routing top-8 of 128 experts. The routed and shared MLP widths are both +768 in the checkpoint tensors. Attention applies per-head Q/K RMSNorm before NeoX RoPE. Routing selects +with sigmoid scores plus the correction bias, but normalizes the selected unbiased scores and +multiplies them by 2.826. Routed and shared BF16 outputs are reduced independently at TP2, then added +in FP32 and rounded once to BF16 before the residual add. + +Convert the public FP8 checkpoint with +`data/recipes/hy-memory-30b-a3b-fp8.recipe`; it preserves the E4M3 codes and expands the checkpoint's +scalar F32 scales to the 128x128 F32 scale planes the GEMMs read. Norms and the router projection +are widened to F32. Linear activations use Radiance's dynamic FP8 quantization; the checkpoint's +static `.input_scale` calibration scalars are ignored, so numerical parity with vendor quantization +is not established. The checkpoint index includes scalar per-layer K/V descales from +`kv_cache_scales.safetensors`; conversion carries them into metadata for `kv_store` and paged +attention. Use `--kv-cache-dtype fp8` for the checkpoint's static-scaled E4M3 cache, or `bf16` for a +higher-precision cache. The plugin refuses the unrelated `fp8_v4` and `k6_v4` cache layouts. +The vendor FP8-source import and static-scaled FP8 KV path have structural/unit coverage only; +an end-to-end conversion and serving run of Tencent's FP8 checkpoint is not yet validated. +This is distinct from the BF16-derived block-FP8 artifact tested below. + +The BF16 checkpoint can be converted without quantizing any weights, or with +`data/recipes/hy-memory-30b-a3b-bf16-w4.recipe`, which quantizes attention projections, the first +dense MLP and routed experts to INT4. Shared MLPs, router, norms, embeddings and the output head stay +BF16. The asymmetric linear W4A8 and signed expert W4A8 kernels use dynamic INT8 activations. +BF16-source block-FP8 and MXFP4 recipes quantize experts and regular linears; the W8 recipe quantizes +regular linears and the output head while routed experts remain BF16. Use TP2 at serve time if one +device cannot hold the model and cache. + +The local llama.cpp Q4_K_M source is supported by `arch/hyv3_gguf` and +`data/recipes/hy-memory-30b-a3b-gguf-q4k-to-w4.recipe`. It decodes Q4_K/Q6_K source tensors and +re-quantizes them to native Radiance encodings; this adds loss to an already-quantized checkpoint. +The GGUF's `hunyuan-dense` pre-tokenizer name is not in Radiance's tokenizer table, so pass the +matching BF16 repository's `tokenizer.json` with `--tokenizer`. Prefer the BF16 source recipe when +available. Both the BF16 W4 and GGUF-to-W4 artifacts passed a short TP2 generation smoke test; the +BF16-source W8, block-FP8 and MXFP4 variants did too. These checks establish basic loading and +inference only, not numerical parity or broad quality. + +The plugins declare the native OpenAI tool-call format: an outer `` section, +`NAME` calls, and tagged ``/`` arguments. The parser and +grammar preserve that section in non-streaming and streaming responses and accept replayed +OpenAI tool results through the checkpoint's chat template. When `reasoning_effort` is `low` or +`high`, the template opens `` in the generation prompt and the parser returns that block +as reasoning rather than answer text. The default template effort is `no_think`. + +Architecture tests cover geometry, GGUF tensor maps, dense-to-MoE scheduling, TP1/TP2 graph lint, +and FP32 combine order; checkpoint tests cover Q4_K/Q6_K block decoding. Numerical parity against Tencent/llama.cpp +remains untested. + ## `qwen35_w8a8` The dense build again, behind `#if QWEN35_W8A8`, for a container `data/recipes/q38-27b-w8a8-df2.recipe` diff --git a/docs/GUIDE.md b/docs/GUIDE.md index c60e384e..699f0888 100644 --- a/docs/GUIDE.md +++ b/docs/GUIDE.md @@ -273,6 +273,9 @@ and runs. | `qwen35_fp8` | the same, block-scaled fp8 | | `qwen35_w8a8` | the same, an int8 trunk rotated by a 128-wide Hadamard | | `qwen35moe_fp8` | Qwen3.5 / 3.6 MoE (35B-A3B), 256 experts, 8 a token | +| `hyv3_bf16` | Tencent Hy-Memory-30B-A3B BF16 checkpoint; BF16, W4, W8A8, block-FP8 and MXFP4 recipes, TP1/2 | +| `hyv3_fp8` | Tencent Hy-Memory-30B-A3B FP8 checkpoint: imported FP8 weights, dense-first MoE, TP1/2, BF16 or static-scaled E4M3 KV | +| `hyv3_gguf` | llama.cpp Hy-Memory Q4_K_M input converted via `hy-memory-30b-a3b-gguf-q4k-to-w4.recipe`; requires `--tokenizer /tokenizer.json` | | `qwen4exp_fp8` | Qwen4-Exp / Qwen3.8-Flash-Next: hybrid Gated DeltaNet + gated attention, 512 experts | | `gemma4` | Gemma 4 text decoders (26B-A4B MoE and the dense members): bf16 trunk, routed experts bf16 or block fp8, and the DFlash drafter | | `gemma4_bf16` | Gemma 4 dense in bf16, with its vision tower |