Repository navigation
[Perf] Add an eager fast path for FP8 per-token linear ops - #8038
ZLkanyo009 wants to merge 44 commits into
Conversation
Outside torch.compile, an unscaled tgemm.mm / gemm_a16w16 / gemm_a16w16_out whose tuned config is hipBLASLt now calls the hipBLASLt pybind entry directly. It skips both torch.ops dispatches (aiter::gemm_a16w16, then aiter::_hipb_mm), the routing in _gemm_a16w16, the gradlib wrapper and the develop-mode argument conversion, which together cost more host time than the C++ call. The config comes from the same lookup _gemm_a16w16 makes, through the module attribute on every call, so a replacement installed over get_GEMM_A16W16_config (ATOM's SGLang plugin installs one) is honoured and its answers are never cached. The solution index and the arguments are the ones the custom-op path passes, so results are bitwise identical. The custom ops still run every call the fast path declines: under torch.compile or jit tracing, inside dispatch / torch-function modes or functorch transforms, for tensor subclasses that take over dispatch, grad-tracked inputs, inputs _gemm_a16w16 does not simply reshape, shape recording (AITER_TUNE_GEMM) or AITER_LOG_MORE>=2, until the op path has created the hipBLASLt extension, and for every config that is not hipBLASLt. AITER_TUNE_GEMM is now read once. Co-authored-by: Cursor <[email protected]>
Converting B.t() to an aiter_tensor_t is the most expensive argument conversion of the fast path (the transposed view plus the pybind constructor). The handle depends only on the tensor's data pointer, shape, stride, dtype and device and holds no reference to the tensor, so it is cached under exactly that key: a hit is what a fresh conversion would build, even for memory that a new tensor reuses. The cache is a bounded LRU (1024 entries), so callers that pass activations as B only rotate entries out; weights stay resident. Co-authored-by: Cursor <[email protected]>
…ration hipblasLtMatmul_sol_wrapper created three matrix layouts and a matmul descriptor, looked the algorithm up by solution index and destroyed it all again on every call, and read HIP_ONLINE_TUNING with getenv each time. For an unscaled GEMM with a given solution index that work is the same on every call, so it is now done once per configuration (op_A, op_B, m, n, k, lda, ldb, ldc, in/out type, solution index, bpreshuffle, bias, gelu) and reused; only the bias pointer is set per call. Scaled calls, the heuristic path (solution index < 0) and online tuning still build descriptors per call. The kept set is bounded (dropped and rebuilt past 1024 configurations) and released with the extension. HIP_ONLINE_TUNING is read once. The descriptor construction moved verbatim into create_matmul_descs(), so a reused descriptor is the one a fresh call would build and results are bitwise identical. Co-authored-by: Cursor <[email protected]>
The plans kept by hipblasLtMatmul_sol_wrapper lived in one global map with no lock, and a hit sets the bias pointer on the kept descriptor before hipblasLtMatmul. The pybind binding of hipb_mm holds the GIL, so Python callers already take turns; a caller that does not hold it (free-threaded Python, a future binding that releases the GIL) could race on the map or hand one descriptor two bias pointers. The map is now thread_local: each thread builds, reuses and, when it exits, releases its own plans, so no descriptor is ever shared. A generation counter bumped by hipb_destroy_extension makes every other thread drop plans built for an older extension before its next lookup; the calling thread drops its own immediately, as before. Tests: threads interleaving several configurations (one of them with a bias per thread) match a single thread bit for bit; a worker thread that outlives a destroy/create rebuilds its plans; short-lived threads release theirs. Co-authored-by: Cursor <[email protected]>
ATOM's PTPC linear layer calls per_token_quant_hip and then gemm_a8w8_bpreshuffle for every FP8 projection. Both go through torch_compile_guard custom ops, so each eager call pays for the custom op dispatch plus the compile_ops wrapper before reaching the kernel. In plain eager mode, call the pybind kernels directly: - gemm_a8w8_bpreshuffle looks up the tuned config like before and calls the CK kernel with the same splitK. Rows tuned for another libtype, bias, non-bf16/fp16 output, padded K and gfx1250 untuned shapes keep the op path. - per_token_quant_hip allocates the same outputs, sets the HIP stream and calls dynamic_per_token_scaled_quant. A static scale keeps the op path. Graph capture, torch.compile, fake/functional tensors, dispatch and function modes, autograd, tensor subclasses, rebound inner ops, AITER_LOG_MORE>=2 and AITER_REBUILD all fall back to the op. The public names stay plain functions that end in the original ops, so compiled graphs still contain aiter.per_token_quant_hip and aiter.gemm_a8w8_bpreshuffle. Move the eager checks shared with tuned_gemm into aiter/jit/utils/eager_guard.py.
test_many_configurations failed on MI35X (gfx950): the first solution hipb_findallsols returned for the 64x64x64 problem gave different bits for two freshly built descriptors. Every view there has its own leading dimension, so both sides of that comparison were fresh builds and no descriptor was reused; the difference came from the kernel, not from the reuse. _solution now returns the first of up to 8 solutions whose results match across two freshly built extensions, for every input the test compares, and skips if none does. With that premise checked, the build-vs-reuse check in test_kept_descriptors_match_fresh_ones asserts instead of skipping.
|
Merged the latest #8030 into this branch (f9ddb25, no rebase). It brings be8b061, a test-only fix for the MI35X failure of This PR's base is #8030's branch, not main, so aiter CI reports no checks here; its tests ( cc @valarLip |
…t32 reference be8b061 did not fix test_many_configurations on MI35X (gfx950). The solution it kept there, 441462, is hipBLASLt's hand-written Custom_Cijk_Alik_Bljk_BBS_BH_MT256x256x64_MI16x16x1_UserArgs_shortname1_gfx950, tuned for 4096x4096x8192-class problems. For the test's 64x64x64 it runs one workgroup with GSU 1 and no workspace, so its arithmetic order is fixed: it is not a K-splitting kernel. With K equal to its depth (64) it skips the second iteration's 16 prefetch loads but still waits with vmcnt(24) and vmcnt(16), thresholds sized for 32 loads in flight, and never waits for vmcnt(0) before the MFMAs, so it can read LDS before its direct-to-LDS loads land. Its results then depend on load latency and stale LDS, with fresh descriptors as much as with kept ones. Two agreeing runs right after a synchronize said nothing about 1100 back-to-back calls. - test_many_configurations uses K = 512, which takes the kernel's regular prefetch path (the cases in this file with K >= 512 passed on MI35X with the same kernel). It also calls the checked views again past the drop, so descriptors kept across it and rebuilt after it are both compared. - Every comparison of kept results goes through _check_reuse. The same call on two freshly built extensions decides how to compare: if they agree bit for bit, kept results must too, and before failing it takes four more fresh samples, since two agreeing ones do not make a kernel reproducible. If fresh results vary, kept results are held to a float32 torch reference instead. Fresh results are always held to that reference (atol = rtol = 1e-2). Failures name the solution, its kernel and the differing elements. - _solution still prefers a solution that is reproducible across two fresh builds, but falls back to the first one instead of skipping. Mutation checks on MI308X: leaving the bias pointer unchanged on reuse fails both bias cases, and leaving ldb out of the plan key fails test_configurations_do_not_mix and test_many_configurations, both in the bitwise path and with the tolerance path forced. Co-authored-by: Cursor <[email protected]>
|
Merged the latest #8030 into this branch (c8004f4, no rebase). It brings aadb785, a test-only follow-up for #8030's MI35X failure in cc @valarLip |
…um) lookup - The fast path read torch._C._len_torch_dispatch_stack, _are_functorch_transforms_active and _is_tracing through getattr with a None default, and turned itself off for the run when one was missing. torch 2.1 and 2.4 have all three (the first is bound in torch/csrc/autograd/init.cpp, the third in torch/csrc/jit/python/init.cpp, and torch/autograd/function.py calls the second), so that branch could not run. They are now called directly. - `_gemm_a16w16` and the fast path each derived the (gfx, cu_num) the tuned-config lookup is keyed on. Both now call `_gemm_gfx_cu`, moved out of `_gemm_a16w16` unchanged; the fast path still keeps the result per device index (about 0.7 us of host time per call here). - The str(dtype) cache is gone: 45 ns uncached vs 28 ns cached per call on this host, two calls per GEMM. No change in behaviour. On MI308X (gfx942), op_tests/test_gemm_a16w16.py -t normal, -t compile and -t out and the tuned-config lookup test give the same results as at aadb785 (the same two asm accuracy prints in -t normal, the known asm case in -t out, the same 8 lookup errors). Co-authored-by: Cursor <[email protected]>
Both files are now plain aiter op tests: module-level helpers and test functions, a main() with the argument parser and the sweep, a markdown table per test function, and an arch gate on get_gfx_runtime() in main(). CI runs them as before, as `python3 <file>`. test_tuned_gemm_eager.py: - Each shape is routed to hipBLASLt (heuristic solution) by a function installed over get_GEMM_A16W16_config, the attribute both paths call through. The test no longer depends on the rows of the tuned CSVs, so on MI35X it runs the cases that skipped there before. - Which path ran is read from the profiler: a custom-op call is a dispatcher event (aiter::gemm_a16w16 / _out) and the fast path records none. The test no longer replaces the module's custom-op attributes. - The sweep (shapes x dtype x bias x out kind, plus otype and 3-D input) compares the fast path with the custom op bit for bit wherever the op reproduces itself, and both with a float32 reference. The table carries each path's device time, host time per call, TFLOPS, TB/s and error. - Path checks: the first call of a process, scales, grad, Parameter, dispatch / function modes, torch.set_default_device (a function mode, so the fast path declines under it), FakeTensor, a non-hipBLASLt config, a 3-D input view cannot flatten, a replaced lookup, weight handles, torch.compile, CUDA graph replay, a preshuffled weight on gfx942, and AITER_TUNE_GEMM=1 in a child process. test_hipb_mm_reuse.py: the same cases, _solution, _check_reuse and K = 512 as aadb785, so the MI35X fix stays; the kept call is also timed. On MI308X (gfx942): both files pass (34 s and 32 s). Each of these mutations makes the new tests fail: no grad check, the weight-handle key without the shape, bias dropped, no torch-function check, no libtype check (crash), no shape-recording check, and l24's two hipbsolgemm.cu mutants (stale bias pointer, ldb left out of the plan key). gfx950 is left to the MI35X CI run. Co-authored-by: Cursor <[email protected]>
…fast-path Co-authored-by: Cursor <[email protected]> # Conflicts: # aiter/tuned_gemm.py # op_tests/test_tuned_gemm_eager.py
`plain_eager` read torch._C._len_torch_dispatch_stack, _are_functorch_transforms_active and _is_tracing through getattr with a None default, and `probes_available` turned the FP8 GEMM and quant fast paths off when one was missing. torch 2.1 and 2.4 have all three, so that branch could not run (the same change as #8030's 674d326). The checks are now called directly, and `probes_available` is gone from the two callers. `plain_tensor_type` is private: only `plain_eager` uses it. No change in behaviour. On MI308X (gfx942): op_tests/test_a8w8_eager.py, test_quant.py, test_gemm_a8w8_bpreshuffle_out.py and test_gemm_a8w8_bpreshuffle_pad_k.py (84 passed, 21 skipped) pass. Co-authored-by: Cursor <[email protected]>
Same structure as #8030's test_tuned_gemm_eager.py: plain aiter op test functions, main() with the parser and the sweeps, a markdown table per test function, an arch gate on get_gfx_runtime(). - The GEMM shapes are routed by a function installed over get_GEMM_config_with_quant_type, the attribute both paths call through: each shape runs once as a CK row and once with no row, so the test no longer reads the tuned CSVs and runs the same cases on every card. A CKTile row and a K-padded weight check that the fast path declines. - Which path ran is read from the profiler, as in #8030's test. - GEMM results are compared with the custom op bit for bit and with a float32 dequantized product; quant results with the custom op bit for bit, their scales with aiter.pertoken_quant, and every dequantized value to within one quantization step of the input. The tables carry device time, host time per call, TFLOPS / TB/s and error. - AITER_LOG_MORE=2 is set in a child process instead of patching the module. On MI308X (gfx942) the file passes in 21 s. Host time per call, custom op vs fast path: GEMM 23.4-24.2 vs 14.7-15.0 us, quant 31.6-32.6 vs 21.1-21.4 us (the 2112-row shapes). Each of these mutations makes it fail: no grad check in plain_eager, a non-CK row taken as CK, no K check, a static quant scale ignored, the quant stream not set. Co-authored-by: Cursor <[email protected]>
…ast-path Co-authored-by: Cursor <[email protected]> # Conflicts: # aiter/tuned_gemm.py
…fast-path Co-authored-by: Cursor <[email protected]> # Conflicts: # aiter/tuned_gemm.py
|
@valarLip Pushed c8004f4..4541de3: two commits from a self-review against the maintainer guidelines, and three merges of #8030 (5a22814, ad156c2, 4541de3) that bring its cleanup, its tests without pytest and main. The diff against Self-review against the maintainer guidelines
Kept, and why: Verification (MI308X, gfx942, at ad156c2 with the image's prebuilt CK and quant modules; #8030's
This PR's base is #8030's branch, so aiter CI reports no checks here. These tests have run on gfx942 only; MI35X will cover them once #8030 merges and this PR targets main. The title now carries |
The path checks compared the custom op's torch-path results and the compiled graph's results with torch.equal. Those run hipBLASLt (through torch or the heuristic solution) on the CI card, which may pick a kernel that is not reproducible run to run. They now go through _check_bits like the rest of the file: the bits must match where the op reproduces itself, and every result is held to the float32 reference. MI308X (gfx942): the file passes (32 s), every one of these checks on the bit-for-bit path. Co-authored-by: Cursor <[email protected]>
The C++ change in gradlib/csrc/hipbsolgemm.cu (keep the hipBLASLt layouts, descriptor and algorithm per configuration and per thread) and its test, op_tests/test_hipb_mm_reuse.py, do not depend on the Python fast path of this PR, and the fast path does not depend on them. They are now #8116, so each can be reviewed and reverted on its own; this PR keeps the eager fast path in aiter/tuned_gemm.py and op_tests/test_tuned_gemm_eager.py. hipbsolgemm.cu is back to main's version and the test file is removed. Nothing in aiter/tuned_gemm.py or test_tuned_gemm_eager.py existed only for the plan reuse, so neither changes.
Main's #6828, merged in with #8030, adds signed-INT8 operands to gemm_a8w8_bpreshuffle and makes its FP8 path assert that XQ has WQ's dtype. The fast path checked only WQ's dtype, so an XQ of another dtype with an FP8 WQ ran the CK kernel where the custom op now raises. The fast path now declines unless XQ and WQ are both FP8. INT8 calls run FlyDSL kernels, which it never stands in for, and reach the custom op as before. #6828 also documents the INT8 contract on the custom op's body, which this PR keeps as the private _gemm_a8w8_bpreshuffle_op, while the public gemm_a8w8_bpreshuffle had a one-line, FP8-only docstring. The docstring moves unchanged to the public function. op_tests/test_a8w8_eager.py: a BF16 XQ with an FP8 WQ reaches the custom op and its "dtypes must match" assertion. With the new check removed, the call takes the fast path and the test fails.
… row check_gemm_declines ran the K-padded call with a CK row routed in, but called the custom op it compares against outside the routing, where the real table has no row for the shape and the op takes the default CKTile kernel for a K-padded WQ. CK and CKTile give the same bits for that input most of the time (19 of 20 random draws on MI308X), so the check failed now and then. Both calls now run under the same row, and the two checks in this block compare through _check_bits, like the rest of the file.
…function Which kernel a bpreshuffle GEMM runs was decided twice: in _gemm_a8w8_bpreshuffle_into for the custom op, and again in the eager fast path, which repeated the FP8 table lookup and the gfx1250 exception for untuned shapes. #6828 just changed that routing on main (INT8), and every such change had to be made in both places. _bpreshuffle_kernel(m, n, k, w_k, q_dtype) now makes the decision and returns it as data: the tuned row (a CK, CKTile or FlyDSL row runs that libtype with its splitK) and, without one, the FlyDSL kernel the shape falls back to (INT8's default 4-wave kernel, the closest fitting one on gfx1250); with neither, the default CK kernel runs. _gemm_a8w8_bpreshuffle_into launches what it returns, pads a K-padded XQ, logs the fallback warnings and wraps default-kernel errors as before. The fast path calls the CK entry directly for a CK row, or with splitK 0 when there is neither a row nor a fallback, and declines otherwise; it has no gfx1250 check of its own. The kernel choice, the warnings and the error text are unchanged: with the launchers, the table lookup and the arch replaced by recorders, the op path makes the same calls before and after this commit in all 168 cases of a grid of rows (CK with and without split-K, CKTile, FlyDSL, an unparsable FlyDSL name, asm, none) x FP8 / INT8 x K-padded or not x gfx942 / gfx1250 x a failing CK launch. Host time of one gemm_a8w8_bpreshuffle call on MI308X, weighted over the four tuned CK shapes of Qwen3.8-Flash-Next PTPC FP8 at TP2, three alternating runs each, before -> after this commit: fast path 13.89 -> 14.13 us warm, 29.16 -> 29.11 us cold; custom op through the dispatcher 21.84 -> 22.23 us warm, 44.57 -> 43.96 us cold. The public call on main is 22.59 / 45.56 us.
|
Pushed 4541de3..e68dca8: a merge of #8030's new head and three commits. #8030 now merges main b9e08da and has moved its C++ plan reuse to #8116, so
The routing duplicate. My last update (#issuecomment-6943260373) kept the CK routing duplicated in the fast path. #6828 changing that routing on main is exactly the drift a second copy invites, so e68dca8 replaces the copy with one function both paths call.
The custom op through the dispatcher goes 21.8 → 22.2 µs warm and 44.6 → 44.0 µs cold across the change. Quant is unchanged (30.3 → 20.1 µs warm, 63.4 → 39.1 µs cold against main). The output SHA-256 of every shape is the same for all three builds. Verification at e68dca8 (MI308X, gfx942):
Still waiting for: #8030 to land, and then aiter CI on this PR (it reports no checks while its base is not main). cc @valarLip |
test_fallback routes a decode-sized BF16 GEMM (4x64x1024) to the torch, skinny and Triton backends, checks that the public gemm_a16w16 reaches the custom op once and gives its bits, and times it against the custom op wrapper that was the public gemm_a16w16 before the fast path. The difference is what the declined fast path costs a call: its checks and its own config lookup. _host_us takes the median of five rounds, so one slow round does not set a row.
Brings in f5b8e74, the timing of the BF16 eager fallback to the other backends.
Conflict in aiter/tuned_gemm.py with ee71544 (#8075), which routes `_gemm_a16w16` through the kernel plugin interface (op "gemm_a16w16"). Both sides added an import at the same place and code right above `_gemm_a16w16`: this branch the eager fast path, main the @_route decorator. Kept both, with the decorator on `_gemm_a16w16`. The fast path calls hipBLASLt without reaching `_gemm_a16w16`, so it would skip the route. It now declines while any provider is enabled and the kill switch is off, and the call goes through the custom op to the route, which asks the providers and records its decision. It runs only in the state where the route's dispatch calls the native body and records nothing: AITER_PLUGINS=0 or nothing enabled by configure(). That is read from the same config snapshot the dispatch reads, once per call. op_tests/test_tuned_gemm_eager.py gains check_plugin_route: with a provider enabled for gemm_a16w16, `tgemm.mm` with and without out= runs the provider; when it declines, the custom op runs with its bits; with nothing enabled again the fast path takes the call. Without the new check in `_hipblaslt_eager` the first of these fails.
Brings in 84f7f18, the merge of main with ee71544 (#8075), which routes `_gemm_a16w16` and `gemm_a8w8_bpreshuffle` through the kernel plugin interface. Conflict in aiter/ops/gemm_op_a8w8.py: main gave the routed inner `gemm_a8w8_bpreshuffle` its contract docstring, this branch had rewritten the docstring there. Kept main's; the public wrapper's docstring points to it. The a8w8 GEMM fast path calls the CK kernel without reaching the routed op, so like the BF16 one it now declines while a provider may serve a routed op. Both read that from `unrouted()` in eager_guard. The quant ops are not routed, so their fast path is unchanged. op_tests/test_a8w8_eager.py gains check_plugin_route: with a provider enabled for gemm_a8w8_bpreshuffle, `gemm_a8w8_bpreshuffle` runs the provider; when it declines, the custom op runs with its bits; the quant fast path still takes its call; with nothing enabled again the GEMM fast path takes the call. Without the new check the first of these fails.
|
Merged #8030's 84f7f18 (main with #8075) as 75a407a: the a8w8 GEMM fast path now declines while a kernel plugin is enabled, so a provider for the routed |
Conflict in aiter/tuned_gemm.py with a3d7388 (#7514): main added `_opus_reads_layout` right above `_gemm_a16w16`, where this branch has `_gemm_gfx_cu`. Kept both. #7514 changes what the tuned lookup returns on gfx1250 (96-CU OPUS rows, the strict id's kid check) and, in `_gemm_a16w16`, sends an OPUS row whose operands OPUS cannot read to Triton or torch. The fast path asks the same lookup with the same (gfx, cu_num) key and runs only hipBLASLt rows, so it declines every OPUS row and the custom op makes those choices. op_tests/test_tuned_gemm_eager.py gains check_gfx1250_opus: with the device key stubbed to a 96-CU gfx1250 and the OPUS and Triton backends stubbed, the real lookup gives #7514's OPUS rows for two Kimi-K2 shapes; each call reaches the custom op, the fast path and the op ask the lookup with the same key, and the op runs OPUS with that row, or Triton when B is not K-contiguous. Keying the fast path's lookup by the runtime arch or by the 256-CU table, or dropping the layout fallback, makes it fail.
Keep main's CPU Torch fallback and FP32 CPU accumulation from #8251, using the existing shared architecture helper inside the guarded lookup. Retain #8099's rejection of borrowed OPUS rows on gfx1250-strict. The eager launch body is unchanged. CPU source-body checks cover 48 numerical/out-buffer cases against main and a Torch reference, the CPU eager decline, invalid output dtype, and architecture error propagation. Provider interface/contracts: 145 passed with GPUs hidden. Black, Ruff and diff-check pass. No new GPU or performance run.
Merge #8030 at be6286d, which incorporates main 2eb9ef3 and retains the CPU Torch fallback through the shared arch helper. The five-file patch against the stacked base has the same stable patch ID as before this merge. CPU GEMM resolution and Torch fallback bodies are identical to the validated #8030 parent. Black, Ruff, AST parsing and diff-check pass. No GPU or performance rerun; this remains stacked on lingzha/tgemm-eager-fast-path.
|
@valarLip Updated the stacked base after #8030's conflict resolution. Merged #8030 at The five-file diff against the stacked base has the same stable patch ID before and after this merge. The CPU GEMM resolution and Torch backend bodies are identical to the validated #8030 parent. AST parsing, Black, Ruff and diff-check pass. No new GPU or performance run was made; the earlier measurements keep their original revision labels. This PR still has no CI checks while stacked on #8030. |
…0-normal-path-20261126
Preserve the ordinary BF16 dispatch and cache changes from #8030. Keep the independent FP8 eager guard and clarify its module scope. The four-file FP8 delta passed independent source review and syntax/Black/Ruff/whitespace checks. No new GPU or performance result is claimed for this merged head.
Mock the actual TDM launcher for persisted gfx1250 policies and check its transposed operand view and launch arguments. Preserve strict-target rejection and all legacy assertions across the full 182 subcases.
Align the three affected legacy MoE golden snapshots with the explicit intermediate_pad=0 keyword introduced by #7611. Exact baseline and PR-head CPU snapshots are byte-identical across all four simulated architectures; all 2130 changed records only add this keyword. Preserve frozen tuning inputs, normalization, assertions and gfx1201.
|
Current-head GPU correctness is now verified for
The complete current source tree and four actually loaded native modules were bound and checked before/after the run. The unchanged op-test assertions ran through a correctness-only driver with the optional timing helpers disabled. This closes the current-head correctness gap for that environment; it is not a clean native build or a production-path performance measurement. Model TTFT/accuracy and other hardware remain unverified at this head. No product change or CI retry was needed. |
aiter PR #8038 — Add an eager fast path for FP8 per-token linear opsCalls loaded quantization and CK GEMM entries directly for eligible eager execution, preserving registered fallbacks and sharing GEMM kernel selection. Review (advisory):
📝 [inferred] Does compilation work when it is the first call in the process? Pinned source: head The original scanner and gate scripts ran unchanged under Python. The read-only GitHub/Git fetch steps used direct CLI equivalents because Bash is unavailable; This is a stacked PR targeting Actual scanner commands and output (local paths replaced by variables)Actual eight-gate output, including any retained artifact-format correctionEarlier malformed or incorrectly encoded local review artifacts, if present, remain in the log below. Only affected gate commands were rerun after correcting artifact format. The final card contains the findings recognized by the final card gate; no product code was changed by these corrections. |
Preserve the a8w8 eager selector and target split-K deferred APIs when resolving gemm_op_a8w8.py. Keep the stacked PR base branch unchanged.
|
The stacked-base conflict is resolved at The only manually resolved file is The description now separates this merge validation from the fixed-image GPU results at |
|
Current-head validation stopped at the CKTile build deadline. On All 428 raw files (214,363,748 bytes) and the complete archive were retained on host25 and their integrity was independently checked. The owned container and resources were released at 21:55:14 UTC. Full clean-build, ABI, normal package/cache resolution, fake-first and real Inductor acceptance remain pending. Next: retain the four completed artifacts and original failure evidence, inspect the existing Ninja/object state, and prepare a bounded CKTile-only continuation before finishing dependency-closure and ABI checks. The original executor owns this continuation; the four completed modules will be reused. |
d6ceec6 to
d0b7855
Compare
Stacked on #8030; review against
lingzha/tgemm-eager-fast-path.FP8 per-token linear layers pay Python dispatch and tensor-conversion costs for both quantization and GEMM. This PR adds guarded direct calls to the already-loaded pybind kernels for plain eager execution. A shared kernel-selection function keeps the registered GEMM route and eager route aligned.
Current head
cd40ba1ec75ad86321939a53147a7403a157fa61normally merges the actual #8030 targetdd13d73fd8cca12796b394e6c662f0e3245e79c3. The four-file FP8 delta remains separate from inherited BF16 changes. The single conflict inaiter/ops/gemm_op_a8w8.pypreserves both this PR's eager route and the target's new split-K deferred APIs. Independent source review, 14 CPU metadata cases, Black and Ruff passed. GPU evidence below remains bound to76e7469b; clean native builds, production-path performance and current-head model validation remain unverified.Changes
aiter/ops/gemm_op_a8w8.py:_bpreshuffle_kernelselects the tuned CK, CKTile or FlyDSL row, architecture fallback, or default kernel for both routes. The eager route accepts eligible FP8 CK calls, preservessplitKand output allocation, and invokes the loaded pybind entry. Unsupported cases continue through the registered op, including INT8, bias, unsupported output dtype, K-padded weights, non-2D inputs, and non-CK selections.aiter/ops/quant.py: without a static scale, eligibleper_token_quant_hipcalls allocate the same quantized output and fp32 scale, set the current HIP stream, and invokedynamic_per_token_scaled_quantwith the existing argument contract.aiter/jit/utils/eager_guard.py: the two FP8 consumers share mode, subclass and autograd checks. Compile/tracing, dispatch/function modes, functorch transforms, relevant overrides, rebound operations, logging/rebuild modes and unresolved first calls retain their registered paths. GEMM also declines while a kernel plugin can serve its routed op. BF16 tuned GEMM does not use this helper.op_tests/test_a8w8_eager.py: exercises numerical equality and route selection, including provider behavior, unsupported inputs, rebound lookups/ops, compile, graph replay and logging. The registered op names and schemas remain available for compiled graphs.The first call stays on the existing JIT route to load or build the module. The eager path only looks up a pybind entry after that initialization; it does not add a build path.
Current merge validation
At
cd40ba1e, the five PR selector/eager function groups (including both definitions ofgemm_a8w8_bpreshuffle) preserve their prior ASTs. The target's_bpreshuffle_configand six split-K deferred helpers preserve their target ASTs. The quantization, guard and test changes relative to the target preserve the prior PR's added/removed lines. No additional call is inserted in the eager hot path.Fourteen CPU scenarios execute the actual extracted selector, registered-path body, eager helper and deferred selector with metadata doubles. They cover missing/CK/CKTile/FlyDSL/unknown rows, padded logical/physical K lookup, valid/rejected INT8 rows, gfx1250 fallback and split-K 2/4/8/1. Configs and lookup order agree, and the eager/deferred paths do not select each other's cases. These are control-flow checks, not Torch/native/GPU execution. Black 26.10.1, Ruff 0.17.6 and staged diff-whitespace checks pass.
The earlier merge
76e7469bincorporated target6bf2b5cband retained the then-reviewed FP8 executable behavior. Its fixed-image GPU evidence is retained below with its original revision. It does not establish GPU or model acceptance for this new merge.GPU correctness at
76e7469bwas verified on 2026-11-27 using MI308X/gfx942, Torch 2.10/ROCm 7.2.4 and the fixed e8 image's existing native modules. The unchangedop_tests/test_a8w8_eager.pyassertions passed all 24 GEMM cases bit-for-bit plus numerical references, 12 quant cases bit-for-bit plus references, and 41 route checks. Those include first calls, provider/fallback behavior, modes, rebound operations, changed-input CUDA graph replay and logging. The Dynamo check uses agm.forwardbackend, not Inductor code generation.A correctness-only driver ran first-call checks before the numerical matrix and suppressed only the optional timing helpers. All 9,085 source files and the four actually loaded native modules were bound and unchanged before/after; exported evidence and resource release were independently checked. This is not a clean native build, production-path performance or current-head model-accuracy result. The op-test substitutes lookup results, so its timing tables do not establish full production-path performance.
Historical performance and correctness
These results describe earlier revisions only. Setup: MI308X (gfx942, 80 CU), ROCm 7.2.4, Torch 2.10 and prebuilt image modules.
Host time at
e68dca887versus mainb9e08daca: four model FP8 shapes at M=2112, tuned CK rows, median of three alternating runs on the same GPU and pinned CPU core; each run uses five rounds of 16-call bursts. Cold calls follow an 8 MiB sweep and unrelated Python work.For 96 GEMMs and 48 quants per prefill, those measurements correspond to 3.6 to 2.3 ms of warm host time and 7.4 to 4.7 ms cold. Quant/GEMM output hashes matched in all recorded runs. These values have not been remeasured on the current base.
Earlier model results compared this PR's first commit
1e08fa73fwith #8030 at74df116e7: TP2/EP2, MTP with three draft tokens, two MI308X,input_ids,max_tokens=1, a prefilled prefix and fresh tails. Every measured wave verified the stated prefix hit. Values are medians of eight measured rounds per run, with alternating server builds; most cells use two runs per build, and the SGLang 10240/concurrency-4 cell uses four.SGLang differences were within run-to-run spread. Native ATOM was faster in those recorded cells, but the machine was shared and the larger deltas included variance; the two Native 10240/concurrency-1 baseline runs differed by 44 ms. GSM8K 5-shot with 200 questions, temperature 0 and
max_gen_toks=4096was 0.985 flexible/strict for both builds and stacks. MTP acceptance was 0.720/0.719 for SGLang and 0.718/0.726 for Native, baseline/candidate respectively. None of these model results validates the current head.Historical tests:
dfa2694350on gfx942,op_tests/test_a8w8_eager.pypassed 41 path checks. The former BF16 eager test also passed.pytest -q testsreported 489 passed, 2 skipped, 1test_layoutfailure, also present on main42aab0f75.75a407a4ac, the four plugin rows passed; removing the GEMM plugin guard made the test fail because the provider did not run.e68dca887, three runs of the FP8 eager test passed 24 GEMM cases bit-for-bit, 12 quant cases and 37 path checks. Six guard/argument/stream mutations failed as intended. The recorded kernel-choice grid matched the original route in 168 cases.e68dca887versus mainb9e08daca, the existing bpreshuffle-out test reported 47 passed/7 skipped; the pad-K test reported 37 passed/14 skipped under pytest and 23 passed/4 skipped as a script.test_quant.pyandtest_gemm_a8w8.py -q fp8exited 0. All used prebuilt modules.The eager profiler currently omits the bypassed
aiter::dispatch events. Graph capture uses the same current-stream launches; the first historical commit message's claim that capture falls back was incorrect. gfx950/gfx1250 native behavior, a clean JIT build and the full op-test matrix remain unverified locally. A synthetic FlyDSL-fallback selection case does not replace hardware validation.PR Self-Review
Reviewed revision
cd40ba1
Behavior and intent
Reduce host dispatch and descriptor-conversion cost for eligible FP8 per-token quantization and CK GEMM by calling already-loaded native entries. Share GEMM selection with the registered route and retain fallback behavior for unsupported execution modes and inputs. The updated stacked base preserves ordinary BF16 registered dispatch.
Validation and unverified scope
The current
cd40ba1emerge has independent AST/diff review, 14 CPU metadata-double scenarios, Black, Ruff and diff-whitespace validation as detailed above. The earlier76e7469bpassed 24 GEMM, 12 quant and 41 route checks on gfx942 using fixed e8 prebuilt modules; those historical results retain that revision. Clean native builds, full production lookup performance, fresh-process compile/fake-first coverage and current-head model accuracy/performance remain open. No new native/GPU/model run is claimed for this merge.PR-specific question
The FP8 delta adds no dependency or cache/compilation policy. The helper reads Torch execution state; eligible direct calls require the existing JIT path to have initialized the native module, and
AITER_REBUILDdisables them. Historical existing-cache runs used prebuilt modules and first-call tests exercised the unresolved state. A clean build has not been run. The new base's BF16 metadata/descriptor caches are inherited byte-for-byte and are reviewed in #8030; they are outside this four-file FP8 delta.Changed op tests
op_tests/test_a8w8_eager.pychecks bitwise equality with the registered ops and numerical references, then distinguishes direct execution from fallback for plugin providers, CKTile rows, unsupported dtypes/shapes, bias, grad/static-scale cases, modes/subclasses, rebound operations, compile, graph replay and logging. Existingtest_gemm_a8w8.pyandtest_quant.pycheck numerical tolerance but do not establish route choice or exact equivalence with the registered op. The FP8 test is byte-identical during this merge. Its original assertions were executed at76e7469bthrough the correctness-only driver described above; optional timing was disabled. Earlier passing revisions remain listed above.