Repository navigation
[HIP] getPaddedM: fall back to the M=16 row for M<16 when no power-of-two row is tuned - #7552
afriedri-amd wants to merge 5 commits into
Conversation
Signed-off-by: Andy Friedrich <[email protected]>
🏷️ CI GuideRuns automatically on every PR:
Extended tests (opt-in via labels):
One backend per PR: PR title tags & labels: |
READY FOR HUMAN REVIEWPR Self-ReviewRevision Author self-review accepted. Readiness report: Author answers
Show the author's self-review answersBehavior and intentValidation and unverified scopePR-specific questionChanged op testsPR state
Copilot findings
Code and op-test hygiene
Required CI
Shadow mode reports what would block but keeps the status successful. Set |
|
Thanks for this — the At current The reproducer below imports nothing from AITER and needs no GPU. Run it from a checkout root with Python 3 and a host C++ compiler; it reads the tuned tables for one E8M0 key ( """Run from an unpatched AITER checkout; needs Python 3 and a host C++ compiler."""
import ast
import csv
import ctypes
from pathlib import Path
import subprocess
import tempfile
root = Path.cwd()
family = "a8w8_blockscale_mxscale_bpreshuffle_tuned_gemm"
configs = root / "aiter/configs"
paths = [configs / f"{family}.csv"] + sorted(
p for p in (configs / "model_configs").glob(f"*{family}*.csv")
if "untuned" not in p.name
)
# Only M <= 16 can be reached by this example. This key has no duplicates
# in the canonical-plus-model input tables, so no merge tie-break is needed.
rows = {}
for path in paths:
with path.open() as stream:
for row in csv.DictReader(stream):
if (row.get("gfx"), row["cu_num"], row["N"], row["K"],
row.get("w_scale_block") or "128x128") != (
"gfx950", "256", "7168", "21504", "128x128"):
continue
m = int(row["M"])
if m <= 16:
assert m not in rows, "Duplicate key: inspect the merge policy"
rows[m] = row
assert sorted(rows) == [16]
print("Available M <= 16:", sorted(rows))
# Extract the real finder without importing AITER or loading GPU libraries.
common = root / "aiter/ops/gemm_op_common.py"
finder = next(node for node in ast.parse(common.read_text()).body
if isinstance(node, ast.FunctionDef)
and node.name == "find_padded_m_row")
with tempfile.TemporaryDirectory(prefix="padded-m-repro-", dir=root) as scratch:
scratch = Path(scratch)
cpp = scratch / "helper.cpp"
cpp.write_bytes((root / "csrc/py_itfs_cu/gemm_common.cu").read_bytes())
library = scratch / "helper.so"
subprocess.run(["c++", "-shared", "-fPIC", "-O0", str(cpp),
"-o", str(library)], check=True)
padded = ctypes.CDLL(str(library)).getPaddedM
padded.argtypes = [ctypes.c_int] * 4
padded.restype = ctypes.c_int
namespace = {"get_padded_m": padded}
exec(compile(ast.Module(body=[finder], type_ignores=[]), str(common), "exec"),
namespace)
for m in (1, 8, 9, 15):
row, selected_m = namespace["find_padded_m_row"](
rows, lambda pm: pm, m, 7168, 21504
)
print(f"M={m}: " + ("MISS" if row is None else f"padded_M={selected_m}"))Without the change it reports One thing for reviewers to weigh, not a blocker: restoring the M16 fallback also makes BF16 split-K M16 rows reachable for the small M that currently miss them. Those rows are implicated in the nondeterminism tracked in #6114, and the open drafts #7053 and #5362 propose fp32 reduction for them. The newly restored small-M points inherit that behaviour until it is fixed, so it may be worth deciding explicitly whether to take the full fallback or restrict it to non-split-K rows. |
… patching main replaced tuned_gemm.get_gfx with get_gfx_runtime and gave get_GEMM_A16W16_tuned_config explicit gfx= / cu_num= arguments, so the mock.patch of tuned.get_gfx raised AttributeError after the merge. Co-Authored-By: Claude Opus 5.5 <[email protected]>
| // 16-row bucket. Tables tuned only at M = 1 / 16 keep serving 2..15. | ||
| if (M > 0 && M < 16) { | ||
| padded_m = 16; | ||
| } else if (M > 8192 && N > 4096) { |
There was a problem hiding this comment.
why we need n>4096? m>8192 should be fine?
There was a problem hiding this comment.
That logic was pre-existing, I just moved it below the 0 < M < 16 branch that I added. Not sure of the original reasoning; making the change here would change behavior on main so inclined not to change in this PR.
There was a problem hiding this comment.
I don't think add padded_m=16 is a good idea since every m will probably make great effort when conc is low.
|
@aiter-bot review |
|
aiter-bot — queued behind 6 review(s); expect to start in about 73 min. The box reviews up to 4 PRs at a time. |
aiter-bot
left a comment
There was a problem hiding this comment.
[ROCm/aiter] PR #7552 — [HIP] getPaddedM: fall back to the M=16 row for M<16 when no power-of-two row is tuned
Review (advisory):
Validation (deterministic): NOT RUN — target op_tests/test_padded_m_lookup.py exists, but this review box has no usable GPU (rocminfo cannot open /dev/kfd, torch is CPU-only, all 8 GPUs at 96% use) and auto-validation is disabled (REVIEW_AUTO_VALIDATE=0); the run was attempted in a /tmp sandbox and blocked by the environment — an environment gap, not a PR defect
Perf (advisory): NOT RUN — target op_tests/test_padded_m_lookup.py exposes no benchmark entry point, and the PR's e2e numbers (802 → 940 tok/s, +17.4%) were measured with a Python-equivalent of this change, not this C++ diff
Size: 77 lines / 2 files
Design (advisory): whether the restored gl=1 M=16 fallback for 0<M<16 should also serve split-K tuned rows — the class open issue #6114 tracks as nondeterministic bf16 split-K accumulation — or be restricted to non-split-K rows
Human: recommend valarLip review whether PR #7552's restored getPaddedM M=16 fallback at gl=1 should include the split-K rows that #6114 tracks as nondeterministic, given valarLip's #6079 chose nextPow2(M) at gl=0 for small M
📝 [verified] The e2e gain (+17.4%, 802 → 940 tok/s) was measured with a Python-side equivalent of this change rather than this C++ diff, and the a8w8/a4w4/opus/CK lookups that share getPaddedM are unmeasured — the PR discloses both, but no base-vs-head timing of this diff exists and op_tests/test_padded_m_lookup.py ships no benchmark entry point. Reviewer should ask for one e2e or lookup-level run with the actual C++ build to confirm the Python-equivalence claim.
1 finding(s) posted inline, on the lines they are about:
csrc/py_itfs_cu/gemm_common.cu:46— restores M=16-row reachability for M=2..8 in every tuned-GEMM walk, and the motivating table…
| if (M > 8192 && N > 4096) { | ||
| // M < 16: gl = 0 already tried nextPow2(M), so fall back to the | ||
| // 16-row bucket. Tables tuned only at M = 1 / 16 keep serving 2..15. | ||
| if (M > 0 && M < 16) { |
There was a problem hiding this comment.
Summary
getPaddedM(gl=1)now returns 16 for0 < M < 16. The tuned-config walk (exact → gl=0 → gl=1) used to stop atnextPow2(M)for small M. It is now exact →nextPow2(M)→ 16, so a tuned M=4/8 row is still preferred (as #6079 intended), and the M=16 row still serves M=2..8 when no power-of-two row exists.Motivation
#6079 changed
gl=0for0 < M < 16from "round up to 16" tonextPow2(M).gl=1was alreadynextPow2(M), so for small M both levels give the same value, and nothing in the walk reaches an M=16 row any more. Any tuned table with M=1/16 rows but no M=2/4/8 rows misses at decode batch 2..8 and silently falls back to the untuned default.Most gfx950 tables in 0.1.26 have that shape: bf16, a8w8 (+ blockscale/bpreshuffle) and a4w4, across the llama70B/405B, qwen, dsv3/dsv4, glm, kimi and minimax model_configs.
End-to-end example: vLLM v0.33.0 (aiter 0.1.26) running BF16 Llama-3.3-70B-Instruct at TP8, conc 8, 1k/1k on MI355X loses 13% throughput vs vLLM v0.32.0 (aiter 0.1.24.post1).
llama70B_bf16_tuned_gemm.csvis identical in both. The decode GEMMs move from FlyDSLhgemm_bf16_*to hipBLASLt.Changes
csrc/py_itfs_cu/gemm_common.cu:getPaddedM(gl=1)returns 16 for0 < M < 16.gl=0and everyM >= 16are unchanged.op_tests/test_padded_m_lookup.py(new): covers the level table and the a16w16 walk against the real compiled op.Performance
Reference: vLLM v0.32.0 + aiter 0.1.24.post1 = 925 tok/s.
The "After" rows were measured with the equivalent Python-side change: an M→16 candidate appended to the walk in
tuned_gemm.get_GEMM_A16W16_tuned_config. It produces the same lookup sequence as this C++ change for the bf16 path. Each figure is 2 server restarts × 2 runs; TTFT is flat.Testing
python3 op_tests/test_padded_m_lookup.py. With the fix: 3/3 pass, run against aiter 0.1.26 with thisgemm_common.cuJIT-rebuilt. Without the fix: 15 sub-test failures (M = 1..8 levels, M = 2..8 fallback).Documentation
Dependencies
Breaking Changes
None. Shapes that hit an exact or power-of-two row resolve exactly as before. Shapes that previously fell to the default at M = 2..8 now use their M=16 row, which is how they resolved before #6079.
PR Self-Review
Reviewed revision
3a92b87b477dBehavior and intent
Restores the pre-#6079 reachability of M=16 rows for small M, while keeping #6079's preference for finer power-of-two rows.
Validation and unverified scope
The
gemm_common.cuchange is unchanged since770e9931de62. Later commits mergemain, andcd5aaf827updates the test:mainreplacedtuned_gemm.get_gfxwith explicitgfx=/cu_num=arguments, so the test now passes those instead of patching module globals.mainstill hasgl=0andgl=1both returningnextPow2(M)for0 < M < 16, andfind_padded_m_rowstill walks exact →gl=0→gl=1.PR-specific question
Boundaries. No arch or dtype condition is involved.
getPaddedMis arch-independent integer logic shared by every tuned-GEMM lookup: the C++ CK and cktile a8w8 bpreshuffle lookups, and the Python a16w16 (tuned_gemm), a8w8, a4w4, opus and a8w4 lookups. The only change is atgl=1with0 < M < 16, and that level is reached only after the exact-M andgl=0(nextPow2(M)) keys have both missed. ForM >= 16, and for any shape that has an exact or power-of-two row, the selected row is unchanged.Invariant. The padded M is used only as a lookup key. Every caller runs the GEMM at the real M, and inputs and outputs are not padded (see the
gemm_op_a8w4docstring). A row is used only when (gfx, cu_num, padded M, N, K, plus the dtype/bias/preshuffle key fields) matches exactly, so the change never selects a kernel for a different arch, dtype or N/K. It only lets an M=16 row serve M in 1..15. That is the pre-#6079 behavior:gl=0roundedM < 16up to 16, so these rows served M=1..15 through aiter 0.1.24. a8w4 also re-checks each row against the actual shape before using it. When no row matches, the default path is unchanged.Changed op tests
op_tests/test_padded_m_lookup.py(new). Existing lookup tests mockget_padded_mto the identity, so none of them covers the real level table. This test does, and it fails on current main.Prepared with AI assistance (Claude Code); reviewed and validated by the submitter.