Add FP8/FP4 MX dtype support in task_interface - #1473
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughThe runtime and Python bindings add four FP8/FP4 ChangesFP8 and FP4 DataType support
Estimated code review effort: 2 (Simple) | ~15 minutes Sequence Diagram(s)sequenceDiagram
participant Torch
participant EnsureTorchMap
participant torch_dtype_to_datatype
participant make_tensor_arg
Torch->>EnsureTorchMap: expose available dtype attributes
EnsureTorchMap->>torch_dtype_to_datatype: register DataType mappings
torch_dtype_to_datatype->>make_tensor_arg: provide converted DataType
make_tensor_arg-->>Torch: create tensor argument and report nbytes
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/ut/py/test_task_interface.py (1)
184-201: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winMake the all-unavailable case an explicit skip.
If every optional dtype is absent, this loop executes zero assertions and the test passes without validating any mapping or tensor construction. Collect supported cases and call
pytest.skip(...)when none are available so CI reports an inapplicable test rather than silently showing coverage.Suggested adjustment
+ supported_cases = [] for attr, expected in cases: torch_dt = getattr(torch, attr, None) if torch_dt is None: continue + supported_cases.append((torch_dt, expected)) + + if not supported_cases: + pytest.skip("No FP8/FP4 dtypes are available in this PyTorch build") + + for torch_dt, expected in supported_cases: assert torch_dtype_to_datatype(torch_dt) == expected🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the rest with a brief reason, keep changes minimal, and validate. In `@tests/ut/py/test_task_interface.py` around lines 184 - 201, The test_torch_dtype_fp8_fp4_and_make_tensor_arg method should collect cases whose torch dtype attributes are available, then explicitly call pytest.skip(...) when the collection is empty. Iterate over the collected supported cases afterward so the test still validates mappings and tensor construction whenever at least one optional dtype exists.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Nitpick comments:
In `@tests/ut/py/test_task_interface.py`:
- Around line 184-201: The test_torch_dtype_fp8_fp4_and_make_tensor_arg method
should collect cases whose torch dtype attributes are available, then explicitly
call pytest.skip(...) when the collection is empty. Iterate over the collected
supported cases afterward so the test still validates mappings and tensor
construction whenever at least one optional dtype exists.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 1af726db-0526-4c95-b7f9-e58a55449c7d
📒 Files selected for processing (4)
python/bindings/task_interface.cppsimpler_setup/torch_interop.pysrc/common/task_interface/data_type.htests/ut/py/test_task_interface.py
13f9b99 to
d55ad74
Compare
Hoist Acc alloc_tile with prologue-safe physical valid extents so loop-local valid_shape SSA cannot break dominate after Acc SSA sharing. Pin the runtime submodule to hw-native-sys/simpler#1473 (FP8/FP4 MX host dtypes). Co-authored-by: Cursor <cursoragent@cursor.com>
5bf1c4b to
cc003be
Compare
|
这几个 dtype 是 A5-only(被 A5 独有的 问题:没有任何 a5 / a5sim 的 scene test 真正让 FP8/FP4 张量走一遍 A5 上的 host↔device 往返。也就是说,这些 UT 证明的是"枚举注册了、host 映射对了",而不是"这些 dtype 在 A5 上真能用"。想确认两点:
|
ad87059 to
3e42362
Compare
|
针对 @ChaoZheng109 的两点确认,已在 torch 2.13.0(≥2.7,含 2) host 映射是否被静默跳过不再静默跳过:UT 在三个可选 dtype 全部缺失时才会 ( 1) a5 / a5sim ST host↔device 往返新增
tip: |
cacae8e to
ef79cda
Compare
ef79cda to
6e77148
Compare
|
关于新增的 建议挪到
(这个文件本身是合理的——之前的 dtype torch 原生就能算 golden,MX FP8/FP4 因为 torch 的 fp8/fp4 支持有限 + E8M0 scale 的 ZZ/NN 打包是 pto-isa 特有布局,才第一次需要手写 decode + 参考 matmul。只是归位问题。) |
6e77148 to
98b4222
Compare
Register the MX block-scale host dtypes so torch FP8/FP4 tensors can flow through the task interface (host<->device byte transfer and compute): - DataType::FP8E4M3FN / FP8E8M0 (1 byte each) and FP4E2M1 (1 byte = 2 packed E2M1 values, matches torch float4_e2m1fn_x2). FP8E5M2 is intentionally omitted (MX paths use E4M3FN + E8M0 scale). - get_element_size / get_dtype_name entries + nanobind enum bindings. - torch_interop maps float8_e4m3fn / float8_e8m0fnu / float4_e2m1fn_x2 -> DataType, guarded by getattr so an older torch silently skips the dtypes it lacks instead of failing at import. - UT: enum/size/name/make_tensor_arg; plus MX FP8/FP4 decode tables, MXFP8/MXFP4 golden with E8M0 block scales and ZZ/NN packing helpers under simpler_setup/goldens/mx_fp_gemm.py (shared golden package). Skip the torch-interop case only when none of the optional dtypes exist. - ST (a5 only) mx_fp_gemm: AIC kernel calls pto-isa TMATMUL_MX for host-prequant MXFP8 / MXFP4 (E8M0 scales, MX_A_ZZ / MX_B_NN) and checks FP32 output against the host golden. a5sim leftover: CPU stub has no GetScaleAddr and TLOAD does not support MX_A_ZZ / MX_B_NN, so this ST is onboard-a5 only for now. Unifying the sim path belongs in pto-isa (or a dual kernel), not this PR. Verified (torch 2.13): related UT passed; a5 MXFP8_TMATMUL_MX / MXFP4_TMATMUL_MX passed.
98b4222 to
c661e7a
Compare
|
@ChaoZheng109 已按建议调整:
感谢指正。 |
Register the MX block-scale host dtypes so torch FP8/FP4 tensors can flow through the task interface (host↔device transfer and native MX matmul).
Changes
DataType::FP8E4M3FN / FP8E8M0(1 byte each) andFP4E2M1(packed E2M1 ×2 / byte, matchestorch.float4_e2m1fn_x2) — A5 only.FP8E5M2intentionally omitted (MX paths use E4M3FN + E8M0 scale, not E5M2).get_element_size/get_dtype_name+ nanobind bindings.torch_interopmapsfloat8_e4m3fn / float8_e8m0fnu / float4_e2m1fn_x2(getattr-guarded).test_task_interface.py: enum / sizes / names /make_tensor_arg(skip only when none of the optional torch dtypes exist).test_mx_fp_numeric.py+simpler_setup/mx_fp_numeric.py: E4M3/E2M1/E8M0 decode, MXFP8/MXFP4 golden with E8M0 block scales and ZZ/NN packing helpers.tests/st/a5/tensormap_and_ringbuffer/mx_fp_gemm/(a5 only): AIC kernel calls pto-isaTMATMUL_MXfor host-prequant MXFP8 / MXFP4 (E8M0 scales,MX_A_ZZ/MX_B_NN) and checks FP32 output against the host golden.a5sim leftover
CPU stub has no
GetScaleAddr, andTLOADdoes not supportMX_A_ZZ/MX_B_NN, so this ST is onboard-a5 only for now. Unifying the sim path belongs in pto-isa (or a dual kernel), not this PR.Verified (torch 2.13.0 ≥ 2.7)
mx_fp_gemma5 (device 0):MXFP8_TMATMUL_MX/MXFP4_TMATMUL_MXPASSED