Repository navigation
[ROCm] Use MIOpen immediate mode for convs first seen in graph capture - #201481
pablo-garay wants to merge 1 commit into
Conversation
A MIOpen convolution whose shape is first seen inside `torch.cuda.graph` capture fails with `hipErrorStreamCaptureInvalidated`, with `cudnn.benchmark` on or off and with `cudnn.deterministic` set (pytorch#188338). On a benchmark-cache miss, `findAlgorithm` in `Conv_miopen.cpp` calls `miopenFind*Algorithm`, which launches timing runs of candidate kernels on the capturing stream. Shapes already run in eager are found in the cache and capture fine. The forward, backward-data and backward-weight paths now take MIOpen's immediate mode (`miopenConvolution*GetSolution` plus `miopenConvolution*Immediate`, which picks a solution without launching anything) when the stream is capturing and the shape is not in the benchmark cache, in addition to when `torch.backends.miopen.immediate` is set. A shape warmed in eager keeps its Find result under capture, so captured graphs match eager numerics and speed; the capture-time choice is not inserted into the cache, so a later eager call still runs Find. Eager behaviour is unchanged. Alternatives considered: returning `DEFAULT_ALGO` from the `deterministic && !benchmark` branch (which currently falls through to Find) only helps users who set `cudnn.deterministic`; `MIOPEN_FIND_MODE=FAST` is a process-wide setting and still fails with `cudnn.benchmark=True`; using immediate mode for every non-benchmark call would change eager algorithm choice for all ROCm users. This mirrors cuDNN, where the non-benchmark path uses heuristics that do not launch. Test Plan: Validated on MI300X (gfx942) and Radeon AI PRO R9700 (gfx1201), MIOpen 3.6.1, HIP 7.16. The new test fails without the fix (capture invalidated) and passes with it, three runs each with a fresh MIOpen user find-db: ``` python test/nn/test_convolution.py -v -k test_conv_cuda_graph_new_shape python test/nn/test_convolution.py -v -k cuda ``` The `-k cuda` subset passes on gfx942 (638 run); on gfx1201 the only failure is `test_cudnn_not_mutate_stride_cuda`, which fails identically without this change. A wider script covering conv1d/conv2d/conv_transpose1d/conv_transpose2d in fp32/fp16/bf16 with `cudnn.benchmark` and `cudnn.deterministic` on and off, the reproducer from the issue, and a captured SGD training step all capture at a new shape and match eager to within one ulp (immediate mode and Find can choose different solvers). Authored with Claude.
🔗 Helpful Links🧪 See artifacts and rendered test results at hud.pytorch.org/pr/201481
Note: Links to docs will display an error until the docs builds have been completed. ✅ You can merge normally! (28 Unrelated Failures)As of commit d523816 with merge base ad0210d ( NEW FAILURES SUPPRESSED BY AI (non-blocking) - The following jobs failed, but the AI CI Advisor judged the failures not to be evidence against this change:
FLAKY - The following jobs failed but were likely due to flakiness present on trunk:
BROKEN TRUNK - The following jobs failed but were present on the merge base:👉 Rebase onto the `viable/strict` branch to avoid these failures
UNSTABLE - The following jobs are marked as unstable, possibly due to flakiness on trunk:
This comment was automatically generated by Dr. CI and updates every 15 minutes. |
|
@pytorchbot merge -i |
## Linked issue or supporting maintainer Follow-up to #201481 (author has write access). ## BC-breaking? No ## Summary (human written only) Test-only follow-up to #201481: pin the new graph-capture conv test to deterministic MIOpen solvers so it stops failing on the ROCm preview image. Details below. ## Agent details (if applicable) `test_conv_cuda_graph_new_shape` (from #201481) fails on the rocm-preview mi350 job for its transposed fp16 variants. Only `grad_weight` differs, and it is not the capture: replaying the same graph twice gives different results, and so do two eager calls. From ROCm 10.2 (MIOpen 3.6.2), MIOpen's default config for these small fp16 weight-gradient convs is the global split-K variant of `ConvAsmImplicitGemmGTCDynamicWrwXdlopsNHWC`, whose reduction order is not fixed; ROCm 10.1 picked a non-split config of the same solver, which happened to be exact. The test compares two runs of a conv it never asked to be deterministic, at the fp16 default tolerance. Passing `deterministic=True` to `cudnn.flags` makes MIOpen use a deterministic solver (CK `ConvHipImplicitGemmGroupWrwXdlops`), so replay, eager immediate and eager Find agree bit for bit. The capture failure #201481 fixes does not depend on deterministic, so the test still catches it. Loosening the tolerance instead would need about atol 0.2 for fp16 `grad_weight`. Test Plan: on MI355X (gfx950), at the same commit, ROCm 10.2.0a20261014 and 10.3.0a20261027 fail 3 of 12 variants before this change and pass 12/12 after (3 runs each); ROCm 10.1 passes both before and after; against a torch without #201481 the changed test fails with the capture error. ``` python test/nn/test_convolution.py -k test_conv_cuda_graph_new_shape -v ``` Authored with Claude. Pull Request resolved: #202451 Approved by: https://github.com/jbschlosser
) ## Linked issue or supporting maintainer Follow-up to pytorch#201481 (author has write access). ## BC-breaking? No ## Summary (human written only) Test-only follow-up to pytorch#201481: pin the new graph-capture conv test to deterministic MIOpen solvers so it stops failing on the ROCm preview image. Details below. ## Agent details (if applicable) `test_conv_cuda_graph_new_shape` (from pytorch#201481) fails on the rocm-preview mi350 job for its transposed fp16 variants. Only `grad_weight` differs, and it is not the capture: replaying the same graph twice gives different results, and so do two eager calls. From ROCm 10.2 (MIOpen 3.6.2), MIOpen's default config for these small fp16 weight-gradient convs is the global split-K variant of `ConvAsmImplicitGemmGTCDynamicWrwXdlopsNHWC`, whose reduction order is not fixed; ROCm 10.1 picked a non-split config of the same solver, which happened to be exact. The test compares two runs of a conv it never asked to be deterministic, at the fp16 default tolerance. Passing `deterministic=True` to `cudnn.flags` makes MIOpen use a deterministic solver (CK `ConvHipImplicitGemmGroupWrwXdlops`), so replay, eager immediate and eager Find agree bit for bit. The capture failure pytorch#201481 fixes does not depend on deterministic, so the test still catches it. Loosening the tolerance instead would need about atol 0.2 for fp16 `grad_weight`. Test Plan: on MI355X (gfx950), at the same commit, ROCm 10.2.0a20261014 and 10.3.0a20261027 fail 3 of 12 variants before this change and pass 12/12 after (3 runs each); ROCm 10.1 passes both before and after; against a torch without pytorch#201481 the changed test fails with the capture error. ``` python test/nn/test_convolution.py -k test_conv_cuda_graph_new_shape -v ``` Authored with Claude. Pull Request resolved: pytorch#202451 Approved by: https://github.com/jbschlosser
) ## Linked issue or supporting maintainer Follow-up to pytorch#201481 (author has write access). ## BC-breaking? No ## Summary (human written only) Test-only follow-up to pytorch#201481: pin the new graph-capture conv test to deterministic MIOpen solvers so it stops failing on the ROCm preview image. Details below. ## Agent details (if applicable) `test_conv_cuda_graph_new_shape` (from pytorch#201481) fails on the rocm-preview mi350 job for its transposed fp16 variants. Only `grad_weight` differs, and it is not the capture: replaying the same graph twice gives different results, and so do two eager calls. From ROCm 10.2 (MIOpen 3.6.2), MIOpen's default config for these small fp16 weight-gradient convs is the global split-K variant of `ConvAsmImplicitGemmGTCDynamicWrwXdlopsNHWC`, whose reduction order is not fixed; ROCm 10.1 picked a non-split config of the same solver, which happened to be exact. The test compares two runs of a conv it never asked to be deterministic, at the fp16 default tolerance. Passing `deterministic=True` to `cudnn.flags` makes MIOpen use a deterministic solver (CK `ConvHipImplicitGemmGroupWrwXdlops`), so replay, eager immediate and eager Find agree bit for bit. The capture failure pytorch#201481 fixes does not depend on deterministic, so the test still catches it. Loosening the tolerance instead would need about atol 0.2 for fp16 `grad_weight`. Test Plan: on MI355X (gfx950), at the same commit, ROCm 10.2.0a20261014 and 10.3.0a20261027 fail 3 of 12 variants before this change and pass 12/12 after (3 runs each); ROCm 10.1 passes both before and after; against a torch without pytorch#201481 the changed test fails with the capture error. ``` python test/nn/test_convolution.py -k test_conv_cuda_graph_new_shape -v ``` Authored with Claude. Pull Request resolved: pytorch#202451 Approved by: https://github.com/jbschlosser
Linked issue or supporting maintainer
Fixes #188338
Supported by @jeffdaily
BC-breaking?
No.
Summary (human written only)
MIOpen convolutions fail hipGraph capture when the shape was not seen before capture. This uses MIOpen immediate mode for those convolutions during capture.
Agent details (if applicable)
Problem: a MIOpen convolution whose shape is first seen inside
torch.cuda.graphcapture fails withhipErrorStreamCaptureInvalidated, regardless ofcudnn.benchmark/cudnn.deterministic.Cause: on a benchmark-cache miss,
findAlgorithminConv_miopen.cppcallsmiopenFind*Algorithm, which launches timing runs of candidate kernels on the capturing stream.Change: forward, backward-data and backward-weight take the existing immediate-mode path (
GetSolution+*Immediate, no launches) when the stream is capturing and the shape is not in the benchmark cache. Warmed shapes keep their Find result under capture; the capture-time choice is not cached, so eager is unchanged. ReturningDEFAULT_ALGOearly from thedeterministic && !benchmarkbranch was measured and rejected: MIOpen then fails eager convs with "No invoker was registered ... Was find executed?".Test plan (MI300X gfx942 and R9700 gfx1201, MIOpen 3.6.1), done with Claude: new
test_conv_cuda_graph_new_shapefails without the fix and passes with it;python test/nn/test_convolution.py -v -k cudapasses (gfx1201: only the pre-existingtest_cudnn_not_mutate_stride_cudafailure, which also fails without the patch). A wider matrix (conv1d/2d/transpose x fp32/fp16/bf16 x benchmark x deterministic, the issue reproducer, and captured training steps) captures at a new shape and matches eager to within 1 ulp.cc @jeffdaily @sunway513 @jithunnair-amd @pruthvistony @ROCmSupport @jataylo @hongxiayang @naromero77amd @pragupta @jerrymannil @xinyazhang