Repository navigation
feat(pytorch): record the SDPA backend and GPU kernels of PyTorch rows - #137
Merged
Merged
Conversation
AITER's setup.py imports aiter/jit/core.py, which reads the HIP version from hipconfig on PATH, else from ROCM_HOME, else from ROCM_PATH, else from /opt/rocm. With ROCm wheel torch, setup_env.py sets ROCM_PATH to the hipDNN prefix (_rocm_sdk_libraries). That prefix has no bin/hipconfig, no include/hip/hip_version.h and no .info/version. On a host without /opt/rocm, the AITER stage stopped with "ROCm version file not found". Set ROCM_HOME to the toolchain prefix (rocm-sdk-devel in rocm torch mode) for the AITER build and prebuild, unless ROCM_HOME is already set. Keep ROCM_PATH unchanged for plugin discovery and the activation script.
rocm-libraries 1423e5c (#14901) collapses the gfx950 dense attention catalog to one variant per (head_size, dtype, mask, tile). Its descriptors do not record num_query_heads or num_kv_heads: the kernel reads them as arguments. catalog_kernels compared the missing fields with the graph's head counts, so no shipped variant matched and only rocke:auto ran. The gfx950 test test_rocke_rows_launch_hipdnn_kernels_and_match_pytorch failed on rocm-libraries develop. Compare the head counts only when the descriptor records them. Put the graph's head counts into the spec of each matched variant, as for batch and sequence lengths, so that rocKE's grid uses them.
tvy-amd
force-pushed
the
fm/dnnbench-pytorch-dispatch
branch
2 times, most recently
from
November 19, 2026 20:13
e885154 to
1670029
Compare
A PyTorch row did not record what PyTorch ran. Under default dispatch, PyTorch selects Flash, memory-efficient or math SDPA for each graph, and tuning (MIOpen find, TunableOp) can select other kernels. Each PyTorch plan now has a `dispatch` object, in `ootb` and in `oracle`: - `sdpa_backend`: the PyTorch SDPA op that the launch called. - `fa_library`: the preferred ROCm Flash library (aotriton or ck). - `kernels`: the distinct GPU kernel names, in order of first launch. After the timed loop, the executor runs one more launch of the primed timed path under torch.profiler. The device is drained first, so input-fill, warmup and flush kernels are not in the trace. The launch is not timed. A failed capture gives a null value and a row warning; it does not fail the row. The tuned child records its own launch for `oracle.dispatch`. The key is additive, so the schema version stays 2. `-v` shows the dispatch lines.
Kineto runs one profiler session at a time. A dispatch capture inside a caller's session stopped that session. The capture now refuses, and the row gets a dispatch warning.
tvy-amd
force-pushed
the
fm/dnnbench-pytorch-dispatch
branch
from
November 20, 2026 15:45
1670029 to
f2779aa
Compare
SamuelReeder
approved these changes
Nov 23, 2026
…ispatch # Conflicts: # tests/unit/reporting/test_schema_v3.py
The capture starts a torch.profiler session. Kineto runs one session per process, and a second session cancels the first. The same-thread check did not see a session that another thread started: the worker cancelled the caller's trace, and the later export could crash the process. - Add --pytorch-dispatch (off by default) and run.config.pytorch_dispatch. Without it, no capture runs and the plan's dispatch stays null. - Forward the option to the tuned PyTorch child. - Also check the process-wide flag of the Python profiler, so a Python torch.profiler session of another thread blocks the capture. - Document the option, the limit and the new run.config key.
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.
Problem
A PyTorch row did not record what PyTorch ran. Under
--pytorch-sdpa-backend default, the PyTorch dispatcher selects Flash, memory-efficient or math SDPA for each graph. Tuning (MIOpen find, TunableOp) can select other kernels. The result file kept only the requested selection, so a slow or wrong PyTorch row was hard to explain.Change
With the new opt-in option
--pytorch-dispatch(config keypytorch_dispatch, recorded asrun.config.pytorch_dispatch), each PyTorch plan (ootbandoracle) gets adispatchobject:sdpa_backendflash,efficient,math,cudnn,overrideable.nullwhen no SDPA op ran (no SDPA node, or the tool's own formula, for example the ALiBi backward).fa_libraryaotritonorck. A strict--pytorch-rocm-fa-libraryis applied as each call applies it.kernelsdispatchisnullwithout--pytorch-dispatch, and on hipDNN, rocKE and AITER rows.How the record is made (
PyTorchCudaExecutor.capture_dispatch,execution/pytorch_dispatch.py):torch.profiler(CPU and GPU activities) with the inputs that the timed loop primed. The first-call setup (fused-kernel probes, layout copies) does not run again.kernelevents only, so no copies or fills) and the SDPA backend (the ATen SDPAcpu_op).--oracle, the tuned child process records its own launch.oracle.dispatchthus shows the kernels after tuning. The child's capture warnings are copied to the row astuned run: dispatch not recorded: ....dispatch(ordispatch.kernelsfor an empty trace) isnull, and the row getsdispatch not recorded: <reason>.KINETO_LOG_LEVELis set to 6 when it is not set, so the profiler writes no lines on stderr.torch.profilersession is already active in the process, the capture does not start a second one: Kineto runs one session at a time, and a nested session stopped the caller's session (seen intest_sdpa_validation_grades_with_repeatable_math_on_gpu). The check covers a session of the same thread (_profiler_enabled()) and a Python session of any thread (the private process-wide flagtorch.autograd.profiler._is_profiler_enabled). The row then gets adispatch not recordedwarning.-vshowsdispatchlines (SDPA backend and kernels) in the detail block.Schema
The keys are additive inside schema 3 (
graph_idgeometry hash, from #138), so they need no version bump. Readers of schema 2 and 3 keep working. Files written before this change do not have the keys; read them asnull. Documented indocs/results-schema.md(run.config.pytorch_dispatch,plan, newdispatchsection, row warnings, version-history note),docs/methodology.md(PyTorch dispatch record) anddocs/usage.md(option table, "PyTorch dispatch record" section,-v).Tests
tests/unit/execution/test_pytorch_dispatch.py: kernel-list filtering and order, SDPA backend detection for each backend (forward and bound backward), mixed backends, a real CPU torch trace with a forced backend, and the ROCm Flash library rules (process preference, strict library, refused library, CUDA build).--pytorch-dispatchno capture runs anddispatchisnull.oracle.dispatchand its warnings come from the tuned child; the child gets--pytorch-dispatchonly when the run has it.torch.profilersession refuses and the caller's session keeps recording, for the same thread and for a session of another thread (fails without the guard).test_schema_v3.py) includedispatchandrun.config.pytorch_dispatch.gpumarker):test_pytorch_sdpa_row_records_its_backend_and_kernelsrunssample_sdpa.json(default, flash, efficient, math) andsample_sdpa_backward.json(default, efficient) withpytorch_dispatch=True. It checks a non-empty, distinct kernel list and that a strict selection is the recorded backend.Local:
pytest tests/unit -m "not gpu": 2148 passed, 17 skipped (no GPU on this host).Profiler cost on the gfx950 runner (torch 2.16 nightly, ROCm 7.18), measured in a fresh process: the first profiler start takes about 0.8 s, later sessions about 1 ms. CPU-only sessions cost the same. A full gfx950 suite run with this change took 176 s.