Repository navigation
Conversation
Port the ASC SwiGLU forward and backward kernels to the VMI (PTO) backend following the PTOAS #1616 migration rules: keep the outer T.Kernel/T.Persistent/T.copy/tiling/SF layout unchanged and rewrite only the T.SimdVF bodies with logical T.vmi operations. Co-Authored-By: Claude Code <noreply@anthropic.com>
- Forward: assert packed UE8M0 requires round_sf, matching the backward kernel and the public config builder. - Make the vdiv precision dispatch explicit; raise on unknown modes instead of silently treating every non-ftz_true string as exact. - Rename the 0-ULP corrections to vdiv_exact_0ulp / sigmoid_vdiv_exact_0ulp and document that they start from the hardware quotient and intentionally do not use the slower built-in V.vdiv(precision="exact") expansion. Co-Authored-By: Claude Code <noreply@anthropic.com>
- forward exact vdiv uses the 'lt' tie-break of ASC's built-in vdiv_0ulp_ftz_true; backward keeps 'le' as in swiglu_backward_asc.py - spell out NOSAT for packed UE8M0 exponent bytes and FP8 output casts, matching ASC's truncation/NaN semantics for amax=inf and non-finite values - remove dead V.alloc_var locals, unused masks, reverse scratch traversal, the redundant packed/round_sf assert, and the no-op fast-math config - shrink the quant scratch to the compact layout and use scalar vmins/vmaxs - add vmi_swiglu_plugin.py and ASC-vs-VMI coverage/adversarial scripts Co-Authored-By: Claude Code <noreply@anthropic.com>
- keep FP8 output casts on saturate='SAT' (faithful ASC translation); the minimal repro shows ASC RS_ENABLE currently behaves like NOSAT for f32->e4m3/bf16 while VMI SAT really saturates (toolchain bug, issue draft) - add repro_fp8_saturate.py and extend adversarial coverage with backward e4m3 non-finite cases; document that the subnormal sweep does not cover the exact-midpoint tie branch - 5-run median benchmarks: forward geomean 1.023 (22/24 >= 0.90), backward 0.904 (8/24 >= 0.90); a concurrent MASBench container on the same NPU is the dominant noise source Co-Authored-By: Claude Code <noreply@anthropic.com>
- FP8 and bf16 output casts explicitly use saturate='NOSAT': ASC's RS_ENABLE is a no-op (bug A) and VMI SAT maps NaN to 0x00 (bug B); NOSAT matches ASC today and preserves NaN. Add explicit NOSAT to the fp->int clamp-count cast and separate the int-narrow comment from the fp-narrow decision. - extend repro_fp8_saturate.py to f32->bf16 and add bf16 non-finite adversarial cases (forward output, backward x_grad/y_grad/act_out); all adversarial checks are now full bitwise equality, with no "assert a difference exists" logic. - 5-run medians on a quiet device: forward 1.035 (20/24 >= 0.90), backward 0.904 (8/24), combined 0.967 (28/48); per-config CV median 0.2%, max 1.6% forward / 4.4% backward. Co-Authored-By: Claude Code <noreply@anthropic.com>
Move the reproduction/coverage scripts out of the repository. They remain available locally under deliverables/repro_scripts/ but are not part of the mainline change. Co-Authored-By: Claude Code <noreply@anthropic.com>
Zhendong404
requested changes
Oct 22, 2026
Comment on lines
+152
to
+159
| exponent = V.vand( | ||
| V.vadd(V.vinterpret_cast(clamped_amax, 'uint32'), exponent_carry, full), | ||
| exponent_mask, | ||
| full, | ||
| ) | ||
| scale = V.vinterpret_cast(V.vsub(exponent, scale_bias, full), 'float32') | ||
| inverse = V.vinterpret_cast(V.vsub(inverse_bias, exponent, full), 'float32') | ||
| return scale, inverse |
Comment on lines
+524
to
+527
| if out_config.use_tma_aligned_col_major_sf: | ||
| output_sf = T.Tensor((num_stored_groups * 2, num_expanded_tokens * 2), T.uint8, x_grad_fp8_sf.data) | ||
| else: | ||
| output_sf = T.Tensor((num_expanded_tokens, num_stored_groups * 4), T.uint8, x_grad_fp8_sf.data) |
There was a problem hiding this comment.
这个PR应该能解决T.copy src/dst类型不一致的问题,可以试试:codex/unify-asc-mte-pointer-lowering
Comment on lines
+235
to
+238
| # 256-element tile amax: two 32-channel groups per 64-lane vector. | ||
| for sub in T.unroll(4, explicit=True): | ||
| amax = V.vcmax(amax_acc[sub], full, group=2) | ||
| V.vstore(amax, amax_ub[tile_id * 8 + sub * 2]) |
Author
There was a problem hiding this comment.
已改。这里 vcmax 的 group 是输出组数,256-lane f32 / group=4 会得到 64 通道一组,与 sf_block=(1,32) 不符,所以 2048 用 256-lane/group=8;3584 用 128-lane/group=4(256-lane 时 num_vecs=14,tile 不满会触发 ptoas 的 layout 冲突)。clamp 计数保持 64-lane,避免宽计数器溢出寄存器。
- Drop redundant full masks on VMI ops that support unmasked forms; keep masks required by the API (vadds/vmuls/vmaxs/vmins/vshrs/vshls, vexpdif, vmula, vcmp/vsel, vcadd/vcmax, vgather and exact vdiv). - Forward amax: use the widest vector whose 4-vector tile stays full. 2048 -> 256-lane vcmax(group=8); 3584 -> 128-lane vcmax(group=4); clamp-count and non-quantized paths keep 64-lane vcmax(group=2). vcmax group is the output count, so 256-lane/group=4 would produce 64-channel groups, which is wrong for sf_block=(1,32). - ptoas 0.66 does not lower 256-lane full reductions (group=1); use grouped certificate/clamp reductions plus a scalar combine. - Document that tilelang PR PTO-ISA#14 (codex/unify-asc-mte-pointer-lowering) does not apply to the pinned 5f105e99 snapshot; keep the uint8-view workaround for packed SF copies. Validated: level-0 48/48, review_adversarial_ab.py ALL_OK, hidden=384 64-lane fallback passes. Co-Authored-By: Claude Code <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
quant: add SwiGLU forward/backward VMI kernels
概述
把 TileKernels 的 SwiGLU 前向/反向 ASC kernel 迁移到 VMI(PTO)后端。外层
T.Kernel/T.Persistent/T.copy/ tiling /num_stages/ buffer versions /SF 布局 / token 调度与 ASC 源码保持一致,只把
with T.SimdVF()内的向量数学改写为逻辑
T.vmi.*;fast-certificate → exact 重算路径完整保留。实现要点
dist=、PART、PK、INTLV、E2B_B32、ONEPT),改用 VMI 的逻辑
vload/vcvt/vstore、vcmax(group=...)和 compact scale。(
vadds/vmuls/vmaxs/vmins/vshrs/vshls、vexpdif、vmula、vcmp/vsel、vcadd/vcmax/vcmin、vgather以及 exactvdiv)保留。vcmax:hidden=2048 用 256-lane/group=8,hidden=3584 用128-lane/
group=4;带 clamp 计数和非量化输出保持 64-lane/group=2。vcmax的group是输出个数,因此 256-lane 不能用group=4(会得到每 64 通道一组,与
sf_block=(1,32)不符)。vcmin/vcmax/vcadd的group=1报VMI-RESIDUAL-OP),certificate 与 clamp 的最终归约使用 grouped reduction + 标量合并。元素宽度一致。上游 tilelang PR 11 Port mhc post kernels to VMI #14(
codex/unify-asc-mte-pointer-lowering)合入并升级快照后可以删除该 workaround。
NOSAT:复现 ASC 当前行为并保留 NaN。lt,backward 用le,与 ASC 源码一致;weight_grad使用vcadd(reassoc=True),按仓库 1e-4 标准验收。验证
(
weight_grad按 1e-4)。review_adversarial_ab.pyALL_OK,覆盖 f32/bf16 次正规数、amax=inf的 packed UE8M0、forward/backward 非有限输入。hidden=384(非 256/128 对齐)的 64-lane 回退路径单独通过。性能
测试条件:
num_send_tokens=4001、alignment=256、with_psum_layout=True。ASC 取 5 次运行 per-file 中位数;VMI 为同一公共 API 的实测值。
前向 24 配置明细(按 ratio 降序)
反向 24 配置明细(按 ratio 降序)