Repository navigation
Conversation
Three fixes from dphnAI/nf12 that the vendored RDNA4 kernels had not picked up.
Only the HIP sources change; the torch binding and the C ABI are untouched.
1. pick_splits split K four ways on any shape with at least 128 column blocks,
which includes launches already 6-7 waves deep. There the FP32 partial plane
(7-28 MB written and read again) costs more than the extra CTAs buy. A/B on
gfx1201, same binary otherwise:
4096x28672 m=16 333.6 -> 310.2 (-7.0%)
4096x28672 m=32 362.4 -> 321.7 (-11.2%)
4096x28672 m=64 417.2 -> 317.9 (-23.8%)
5120x25600 m=16 363.3 -> 375.8 (+3.4%)
5120x25600 m=32 388.1 -> 382.0 (-1.6%)
5120x25600 m=64 433.9 -> 385.2 (-11.2%)
Against dense BF16, 4096x28672 m=64 goes 0.96x -> 1.28x and 5120x25600 m=64
1.04x -> 1.21x, so neither is below parity at m=16/32/64 any more. One cell
loses 3.4% and still runs at 1.15x. 8192x57344 keeps its two-way split: it is
14 waves deep but the split still wins there at m=128.
Those shapes now need no split-K scratch: seven of the forty benchmark cells
split K, down from thirteen.
2. wmma_available() cached one process-wide bool captured from whichever device
was current on the first call. On a host exposing both gfx1201 and gfx1250
the second device inherits the first one's answer and is sent down a
matrix-core route it cannot run. Cached per device index now, with an atomic
slot so concurrent host threads stay safe.
3. The HIP entry points only checked n % 16. A k that is not a multiple of 64
was truncated by k / kSuperAtomCols, so encoding a 256x96 weight produced a
matrix covering 64 of the caller's 96 columns and the GEMM then read back as
garbage. encode_analyze/encode/decode/unpack_bf16t/linear_fused/linear_wmma
now reject the same bad geometry the torch binding already rejects.
Verified on R9700 (gfx1201): nf12 suites 240 passed, 1 skipped; workspace query
now returns 0 for both wide shapes; 4096x28672 m=64 measures 1.28x BF16.
The 6 test_rocm_kernel_contracts::test_rocm_device_contract[NF12ADLinear]
failures are pre-existing on upstream/main and unrelated (they assert
SUPPORTS_DEVICES against the ROCM_KERNELS list).
This was referenced Nov 9, 2026
Collaborator
Author
|
Superseded by #3676, which rebases this split-K/per-device commit onto current main and adds the review fixes. |
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.
Summary
Syncs three fixes from dphnAI/nf12 into the
vendored RDNA4 HIP kernels. Only
gptqmodel_ext/nf12_hip/*.hipchanges; thetorch binding, the C ABI and the Python layer are untouched.
kthat is not a multiple of 64 was silently truncated.1. Split-K
pick_splitshanded four K splits to any shape with at least 128 column blocks,which includes launches that are already 6–7 waves deep. There the extra FP32
partial plane (7–28 MB written and read back) costs more than the additional
CTAs buy. A/B on gfx1201, same binary otherwise:
Against dense BF16 on the R9700:
Neither shape is below parity at m=16/32/64 any more. One cell gives up 3.4% and
still runs at 1.15×.
8192×57344keeps its two-way split: it is 14 waves deep,but there the split still wins at m=128 (2601 → 2414 µs).
Side effect: both shapes now need no split-K scratch — seven of the forty
benchmark cells split K, down from thirteen.
2. Per-device capability cache
wmma_available()captured one process-wide bool from whichever device wascurrent on the first call. On a host exposing both
gfx1201andgfx1250thesecond device inherits the first one's answer and is sent down a matrix-core
route it cannot run — the same class of bug as a shared scratch buffer, just in
the capability check. Now cached per device index with an atomic slot.
3. Geometry validation
The HIP entry points only checked
n % 16. Akthat is not a multiple of 64was truncated by
k / kSuperAtomCols: encoding a 256×96 weight produced amatrix covering 64 of the caller's 96 columns, and the GEMM then read back as
garbage with
rc=0.encode_analyze,encode,decode,unpack_bf16t,linear_fusedandlinear_wmmanow reject the same bad geometry the torchbinding already rejects.
Verification
Radeon AI PRO R9700 (
gfx1201):test_nf12_ad_codec,test_nf12_ad_runtime_load,test_backend_naming,test_quant_bits_validation,test_rocm_llc).nf12_ad_wmma_workspace_bytesreturns 0 for both wide shapes; 7/40 cells split.4096×28672m=64 measures 1.28× dense BF16 throughnf12_ad_hip.linear.The 6
test_rocm_kernel_contracts::test_rocm_device_contract[NF12ADLinear]failures also fail on
upstream/mainwith this branch stashed; they assertSUPPORTS_DEVICESagainst theROCM_KERNELSlist and are unrelated to thischange.
Credits
NF12 format, reference codec and CUDA kernels: AlpinDale,
Apache-2.0. NyoomFloat12: Liberman, Fang, Zhang, Dao and Fu — Together AI (2026).