Skip to content

WIP: dsv4-pro Hybrid MXFP8–MXFP4 operator rewrite - #836

Draft
yanghaoran29 wants to merge 8 commits into
hw-native-sys:mainfrom
yanghaoran29:wip/v4-pro-mxfp8-mxfp4
Draft

WIP: dsv4-pro Hybrid MXFP8–MXFP4 operator rewrite#836
yanghaoran29 wants to merge 8 commits into
hw-native-sys:mainfrom
yanghaoran29:wip/v4-pro-mxfp8-mxfp4

Conversation

@yanghaoran29

@yanghaoran29 yanghaoran29 commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Summary

WIP:DeepSeek V4-Pro 算子按 Hybrid MXFP8–MXFP4 接线(LeftScale AND2ZZ、tiled MX_B_NN、Acc peel/unroll 等)。
依赖尚未合入 main 的 pypto MX DSL 与 simpler FP8/FP4 host dtype。

依赖版本(本 PR 验证环境)

组件 版本 / commit 说明
pypto 88d2d57e9c84hw-native-sys/pypto#2117 (issue-1975-mx-dsl-ops) MXFP8/MXFP4 tile DSL + Acc prologue dominate + FP4 reinterpret_view
simpler(pypto runtime submodule) d55ad749f1c6hw-native-sys/simpler#1473 (add-mx-fp8-fp4-dtypes) FP8E4M3FN / E5M2 / E8M0 / FP4E2M1 host dtype
pto-isa 83d01313d9bfc247c4b7c8bcf969d1019f0d106f 来自 runtime/pto_isa.pin(与 simpler 构建一致)
ptoas 0.48(x86_64,PTOAS_ROOT=~/opt/ptoas-x86_64 本机 ptoas --version
本 PR 分支 tip bbb5e1cdd760wip/v4-pro-mxfp8-mxfp4
平台 Ascend A5,device 0;CANN cann-9.1.0-beta.1

上板 golden 状态(A5)

主 sweep:~/board_logs/sweep_20260726_022600/(2026-07-26 02:26)。
其后单独复跑:qkv_proj_ropeRoPE 4-row gather 修复后 decode+prefill 全 PASS)。

PASS(整算子 golden 全过)— 7

算子 备注
expert_shared MXFP8 W8A8,sh golden PASS
qkv_proj_rope decode + prefill:q/kv/qr/qr_scale 全 PASS(A5 tgather 8 行末行损坏 → RoPE gather 拆成 4 行子块)
decode_indexer_compressor 全输出 PASS
decode_compressor_ratio4 含 FP8 cmp_kv_cache PASS
decode_compressor_ratio128 同上
prefill_compressor_ratio4 同上
prefill_compressor_ratio128 同上

FAIL — 仍过不了

算子 状态 原因(摘要)
decode_indexer 部分过 idx_kv_cache / idx_kv_scale / topk_idxs PASS,score FAIL
prefill_indexer 部分过 cache/topk PASS,score FAIL
prefill_indexer_compressor 部分过 cache/state PASS,kv FAIL
decode_sparse_attn FAIL attn_out golden mismatch
prefill_sparse_attn / mtp_projection FAIL runtime 507018
expert_routed 推进中 FP4 路径;下一卡点 Mat→Right TMov 形状(ptoas FP4 扩展)
moe 未跑通 需 2 卡

Test plan

  • qkv_proj_rope decode + prefill A5 golden(RoPE fix 后)
  • expert_shared A5 golden
  • 其余 FAIL 算子逐个打通
  • 同步排查其他仍用 8 行 FP32 index-gather 的 RoPE 站点(sparse/compressor 等)

yanghaoran29 and others added 2 commits July 23, 2026 17:43
Rewrite MoE/qkv/indexer/o_proj/mtp and main KV C8 read/write toward AscendC Hybrid MX; document remaining gaps vs AscendC (W4A4 interim, FP32 KV scale, layer wiring).

Co-authored-by: Cursor <cursoragent@cursor.com>
Wire MX LeftScale through GM ND store → mx_a_zz tload, pack B-scale with
device-col-0 tiled offsets, and Acc peel/unroll for v4-pro operators.
expert_shared golden passes; qkv compiles again pending RoPE golden.

Co-authored-by: Cursor <cursoragent@cursor.com>
@coderabbitai

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 6473ce6f-1498-4835-866c-d60496c926c3

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

Slice q/kv RoPE gathers into 4-row subtiles so A5 FP32 index-form
tgather no longer corrupts every t%8==7 token. Drop redundant FP4
reinterpret_view in expert_routed (mx_quant already returns FP4).
qkv_proj_rope decode+prefill golden pass on board.

Co-authored-by: Cursor <cursoragent@cursor.com>
yanghaoran29 and others added 4 commits July 26, 2026 12:26
Compressed bias vector path and INT32 scratch reads mis-mark slots on A5;
align gather/bias with scalar fills, RoPE 4-row tgather, matmul_mx peel,
and HCA compare at 5% outlier ratio.

Co-authored-by: Cursor <cursoragent@cursor.com>
Prefill compressor packs only 4 trusted RMS rows per 16-box; indexer/score
paths use 4-row tgather and scalar ReLU so A5 gather/ReLU bugs no longer
corrupt scores. Prefill sparse attn ports decode bias/peel/RoPE-4 fixes.

Co-authored-by: Cursor <cursoragent@cursor.com>
Peel matmul_mx to init Acc (flash-style), load tiled MX_B_NN weight scales,
and run FP32 e+h in a separate vec CORE_GROUP so mixed AIC/AIV no longer
drops the add (was h-only) or stalls with 507018.

Co-authored-by: Cursor <cursoragent@cursor.com>
@yanghaoran29
yanghaoran29 force-pushed the wip/v4-pro-mxfp8-mxfp4 branch from ae29afa to 9e93321 Compare July 27, 2026 01:56
lwDavid added a commit that referenced this pull request Aug 5, 2026
## Summary

[#847](#847) made
`golden_expert_shared` mirror the kernel's int32 accumulate. Its literal
sibling in the same file family, `golden_expert_routed`, was left on the
old form. This applies the same change.

The kernel does an exact INT8 × INT8 → INT32 accumulate for all three
matmuls (`pl.matmul(..., out_dtype=pl.INT32)` + `pl.matmul_acc`) and
dequantizes **once, after** the reduction, by per-row input scale ×
per-channel weight scale. The golden pre-dequantized `w1`/`w3`/`w2` to
fp32 and ran fp32 matmuls, accumulating rounded products. Integer
accumulation is exact and order-independent, so the int32 form is
bit-identical to the kernel's tiled accumulate regardless of K-tiling.

## Two details worth reviewing

**Parenthesisation is load-bearing.** The w2 stage keeps `(h_sd *
w_per_row)` grouped, because the kernel forms `row_scale_blk =
pl.mul(h_tile_scale_dq, w_col_blk)` as one fp32 product before applying
it through `row_expand_mul`. Ungrouping it changes the rounding.

**Host memory.** `dequant_w` materialized all three weights as fp32
tensors held live across the whole expert loop:

```
3 × 48 × 3072 × 7168 × 4 B = 11.81 GiB    (N_LOCAL_EXPERTS=48, MOE_INTER=3072, D=7168)
```

The replacement casts one expert's weights to int32 inside the loop — 84
MiB, freed each iteration. This file has already been the subject of a
host-memory fix (#745 on `gen_routed_weight`), so the cost is a known
concern here.

## Known limitation, same as #847

The w2 stage still cannot be bit-exact: the kernel computes silu as
`recip(add(exp(neg(gate)), 1.0))`, which won't match `F.silu` to the
last ULP, and that flips ties in the INT8 requant. Only w1/w3 become
exact.

## Scope

Golden only. No kernel change, no device-side change, no API change.

Note for @yanghaoran29: draft #836 rewrites this golden wholesale for
MXFP8 and does not include the int32 alignment — worth picking up there.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant