Repository navigation
feat(sdpa): validate SDPA dropout in the PyTorch reference (ALMIOPEN-3178) - #128
Open
GarbyGilbertAMD wants to merge 55 commits into
Open
GarbyGilbertAMD wants to merge 55 commits into
GarbyGilbertAMD wants to merge 55 commits into
Conversation
…run (ALMIOPEN-3178)
… keyword (ALMIOPEN-3178)
…v, seed and offset (ALMIOPEN-3178)
…ry check (ALMIOPEN-3178)
…nst its own reference (ALMIOPEN-3178)
…he SDPA reference (ALMIOPEN-3178)
…PEN-3178) run_hipdnn_tuned now takes a validate callable instead of the tensor infos and reference outputs. The tuned child saves its outputs when a callable is given and fills the rng_dump buffer with NaN first. For a Philox graph the callable checks the tuned child's own dump and builds a reference from it. ALMIOPEN-3178
…nce (ALMIOPEN-3178) The backward reference now accepts dropout_mask and dropout_scale with an optional dropout_scale_inv. It applies the mask to dP, scales D by dropout_scale_inv and builds dV from the dropped and scaled P. The cases the hipDNN references decline stay declined. ALMIOPEN-3178
…MIOPEN-3178) Remove the rng_dump output row and the dropout_mask and dropout_scale input rows from the tests that pinned the old rejections. The new dropout decline tests cover the same rules. ALMIOPEN-3178
…t/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
…EN-3178) A Philox graph whose rng_dump is not FLOAT made the NaN fill raise, so the engine row became an error row and lost its timings. The reference now declines such a graph before the fill, as the hipDNN references do, so with --validate the engine rows fail and keep their timings. ALMIOPEN-3178
…/ALMIOPEN-3178/sdpa-dropout-validate
…IOPEN-3178) The CPU reference size estimate now counts an SDPA dropout forward (explicit mask, or rng_dump with a non-null probability) like a sink forward: three score-block temporaries, plus the float32 band when bounds apply. ALMIOPEN-3178
…MIOPEN-3178) Name the host memory exception for declined graphs, limit the p = 0 rule for backward nodes, scope the dropout_scale graph error to the hipdnn and pytorch runtimes, and list every decline rule. ALMIOPEN-3178
…nce (ALMIOPEN-3178) Grade a Philox engine row with the real PyTorch reference provider and fake hipDNN buffers: the row passes with its own dump and output, and fails with a flipped output or the dump complement. A strict SDPA backend selection does not affect the per-row reference. ALMIOPEN-3178
…/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
…ALMIOPEN-3178) The mask-without-scale and scale-without-mask decline cases now check that the message names both keys, and a rank-1 mask case covers the rank check. Without them, removing either gate still passed because a later lookup declined the graph. ALMIOPEN-3178
…/ALMIOPEN-3178/sdpa-dropout-validate
The dump check shows that the dump is a 0/1 mask at the expected keep rate and that the outputs match a reference built from it within the output data type tolerance. It cannot tell the dumped mask from another mask at bf16 with many keys. Also split the sentences that were longer than 25 words. ALMIOPEN-3178
…t reference (ALMIOPEN-3178) A query row whose keys are all masked, for example with a bottom-right causal mask and more queries than keys, made the dropout reference return NaN. It now returns zero output for such a row, as the reference without dropout and the hipDNN reference do. The stats stay -inf. ALMIOPEN-3178
…PEN-3178) A backward node with a nonzero dropout_probability was declined with the forward message, which asks for an rng_dump output that a backward node cannot have. The backward rules now run first and say that Philox backward dropout is not supported (rocm-libraries #15643, draft). ALMIOPEN-3178
…/ALMIOPEN-3178/sdpa-dropout-validate
…t/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
Give the real reason Philox backward rows fail, note that backward dropout_probability 0 is accepted as no dropout, add the missing-scale limit of the Philox check and the rng_dump without seed or offset decline, carve out the Philox exception from the reference row text, and use active voice. ALMIOPEN-3178
…f range (ALMIOPEN-3178) check_rng_dump raised a math domain error for a probability below 0 or above 1, which turned the engine row into an error row, and it passed NaN. It now returns a mismatch that names dropout_probability for NaN and for any value outside [0, 1), so the row fails with exit code 3. ALMIOPEN-3178
…roadcast shapes (ALMIOPEN-3178) The backward explicit-mask dropout tests fitted in one score block and used only the full mask shape. A new test shrinks the score block so the query rows span several blocks, with full, head-broadcast and batch-broadcast masks. ALMIOPEN-3178
The decline message no longer claims a pull request state. It says that the hipDNN backward graph has no dropout mask output, so the reference has no mask to apply. The comments that cite hipDNN reference rules now name the rocm-libraries pull requests that added them, which postdate the submodule pin. ALMIOPEN-3178
A graph-supplied dropout_scale of 1.0 is a keep rate of exactly 1. It is accepted and gives an all-ones mask. No test covered that boundary. ALMIOPEN-3178
…/ALMIOPEN-3178/sdpa-dropout-validate
…/ALMIOPEN-3178/sdpa-dropout-validate
GarbyGilbertAMD
marked this pull request as ready for review
November 13, 2026 21:29
Bring in SDPA backward support with dBias and the rocm-libraries bump (#120), ragged and variable-length SDPA (#118), the aiter runtime (#119) and the oracle follow-ups (#110, #111). The dropout reference now composes with the backward dBias: dBias is the dropout-scaled dS before the attention scale, as hipDNN's CPU reference defines it. Dropout with paged or ragged K/V stays declined. The dropout tests use the new left_bound rule. ALMIOPEN-3178
…(ALMIOPEN-3178) The keep-rate check compared rates against 6 * sqrt(keep * (1 - keep) / n) + 1 / n. At p = 0 a dump with exactly one zero sits on that bound, and the division by n rounded it one ULP past the bound for many sizes, so a valid dump failed. The check now compares the count of ones with keep * n against 6 * sqrt(keep * (1 - keep) * n) + 1, which is exact at p = 0. hipDNN's harness keeps the rate form, so it can still reject such a dump. ALMIOPEN-3178
The dBias bullet applied the dropout mask and dropout_scale_inv twice. It now says dBias is the dS above, taken before the attention scale and summed over the bias's broadcast dims, as hipDNN's CPU reference does. A wrong dropout_scale_inv also shows in dBias. ALMIOPEN-3178
… (ALMIOPEN-3178) After the merge, test_oracle.py builds its own validate callable, so no test checked that suite_runner hands the tuned run a validator built from the graph's resolved tensor infos. The new test calls the captured validator on matching -inf SDPA stats with matching_infinities set, and on a mismatch as the control. ALMIOPEN-3178
…PEN-3178) The merge of main dropped the explicit-mask checks and the Philox dump lookup from compile_sdpa, so every dense forward SDPA graph raised a NameError. Restore them, and run the paged and ragged dropout decline before main's paged checks again so its message names the layout. The decline tests now use graphs that are valid without dropout, a backward variable-length case covers the backward decline, and a test shows a dropout backward never takes the fused path. ALMIOPEN-3178
…ernel (ALMIOPEN-3178) On CPU torch the backward probe never reports a fused kernel, so the test passed whether or not a dropout backward bypasses the fused path. The test now simulates a host where a fused kernel is available, which returns gradients without dropout, and checks that the dropout closed form still holds. ALMIOPEN-3178
…id (ALMIOPEN-3178) read_dropout did not look under "parameters" for the dropout tensor uids, so a backward node with seed_tensor_uid stored there was not declined, although every other optional-uid lookup in the handler reads that section. The Philox ragged decline case now gives a length source on both sides, so main's padding rule passes and the dropout decline is what fires. ALMIOPEN-3178
…ne as tool limits (ALMIOPEN-3178) The docs now give the keep-rate bound in the count form the check uses and note that hipDNN's harness, which keeps the rate form, can reject a dump this check accepts at the one-element edge. The dropout decline for paged, ragged or variable-length K/V is described as a limit of the PyTorch reference: hipDNN's own reference densifies these layouts. ALMIOPEN-3178
…rect decline wording (ALMIOPEN-3178) sdpa_dropout.py kept its own copy of the optional-uid reader, and that copy drifted from the shared one once already. It now calls the shared torch-free node_value reader. The paged, ragged and variable-length dropout declines say they are a limit of the PyTorch reference, not a hipDNN rule. The backward Philox decline cites rocm-libraries #14358 (no backward rng_dump), and the comments no longer say the submodule pin predates the dropout rules. ALMIOPEN-3178
…MIOPEN-3178) A backward graph with dropout_probability 0 and no dropout mask, scale or scale_inv is no dropout, with or without seed and offset, as in hipDNN's backward references (rocm-libraries #15643). Philox backward with p above 0 stays declined: the backward graph has no rng_dump (rocm-libraries #14358). The dBias note names the current rocm-libraries pin. ALMIOPEN-3178
…eed and offset (ALMIOPEN-3178) hipDNN's backward references now read a backward graph with dropout_probability 0 and no dropout mask, scale or scale_inv as no dropout, with or without seed and offset (rocm-libraries #15643, now in the pin). The PyTorch reference follows: such a graph gives the gradients of the graph without dropout fields. Philox backward with a probability above 0 stays declined, because the backward graph has no rng_dump. ALMIOPEN-3178
…IOPEN-3178) Since a backward probability of 0 is no dropout, _decline_backward_philox only has to decline a probability above 0. Its seed and offset decline only replaced the messages of the forward dropout rules and the scale_inv check, which decline the same graphs and name the key. Its probability-0 early return then guarded nothing. ALMIOPEN-3178
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
The PyTorch reference (
--validate pytorch) now validates SDPA dropout: explicit-mask dropout (forward and backward, with dBias when the graph has a bias gradient), Philox dropout through the engine's ownrng_dumpoutput (forward), and probability 0 as no dropout (forward and backward). The tool also fills the dropout inputs. hipDNN engines now serve Philox dropout (rocm-libraries #15066) and the hipDNN references validate explicit-mask dropout, but the tool declined all of it, so engine rows failed or stayed unchecked for the wrong reason.JIRA ID : ALMIOPEN-3178
Risk Assessment
Risk level 3. The change is a new validation path in the tool. It does not touch the timed loop (
timing.pyis unchanged) and does not change any graph without SDPA dropout. Behaviour does change for SDPA dropout graphs: rows that used to be declined are now graded, and some graphs now fail with--validatewhere they wereuncheckedbefore (see Technical Changes). The tuned-plan oracle path changes its internal interface (run_hipdnn_tunedtakes avalidatecallable), and the one caller is migrated.ASIC Coverage
The code is host-side Python, independent of the architecture. The engine rows that it grades depend on the architecture, so the hardware runs below use gfx950 (FlyDSL, ASM SDPA) and gfx942 (ASM SDPA, hip_flash2). Passing unit CI is enough for the code. The hardware runs are evidence of the grading, not a merge gate for other architectures. The hipDNN scratch builds that served them used a rocm-libraries build with the FlyDSL and kernel-ingestor options on. The tool pin (rocm-libraries 28f91cf, after the merge of
main) includes the hipDNN dropout reference rules and engines (rocm-libraries #14358, #15066 and #15643).Testing Summary
test_input_dropout.py,test_sdpa_dropout.py): mask is exactly 0 or 1 at the keep rate and repeats for a seed; scale and scale_inv follow the keep rate; a keep rate outside (0, 1] is refused; seed and offset are nonzero; the other inputs do not change; a nulldropout_probabilitycounts as absent.test_pytorch_provider.py,test_pytorch_ops.py): closed-form explicit-mask forward and the backward gradient check withdropout_scale_inv(a mutant that drops the factor fails it); dBias of an explicit-mask backward graph as the dropout-scaled dS before the attention scale; Philox reference from a given 0/1 dump at p other than 0.5 (the1/pbug); composition with causal, sliding window, bias, ALiBi and sinks; one decline test per hipDNN decline rule; paged and ragged dropout declined by name; host-memory estimate counts the dropout temporaries. The tests that pinned the old rejections are replaced.test_correctness.py,test_buffer_manager_torch.py): values outside {0, 1} fail; the count-based keep-rate bound (a dump with one zero at p = 0 passes, as the bound allows one element; an all-zero dump at p = 0 fails); the NaN fill covers strided padding and rejects a non-FLOAT output; therng_dumpoutput is not compared.test_suite_runner.py,test_oracle.py): each engine row is graded against its own dump; an engine that never writes the dump fails; a dump that is bad fails before any reference runs; Philox withoutrng_dumpfails and names it, also when a CPU reference would not fit; a non-FLOAT dump fails and keeps its timings; a dump that does not fit host memory givesuncheckedbefore any fill; device out-of-memory retry on the host; the tuned child fills its dump with NaN and the parent validates the tuned plan from the child's saved dump; one row runs end to end against the real reference, also under a strict backend.main: 2257 passed. Every failure needs files outside the test archive (setup_env.py,sample_configs/) or a permission check, as on the base; none is in the changed code.main, each outcome as expected:rng_dumpon the FlyDSL engine: the rows pass (three graphs), and the tuned plan validates with--oracle.rng_dump: the engine rows fail (exit 3) and the message namesrng_dump.O(exit 3).rng_dump: the engine leaves the dump unwritten and the row fails the dump check (message: "rng_dump value check failed: element 0 is nan", exit 3).dropout_scale_invfactor, reused dump, zero instead of NaN fill, null read as 0, skipped value or rate check, each decline gate removed in turn, shortfall check moved first, strict backend scope, missing tuned validation, missing memory budget, missing out-of-memory retry, and others). At the final tip the unit tests kill all 66 mutants, including mutants for dBias with dropout, the fused-path bypass of a dropout backward, the backward variable-length decline and a backward seed or offset decline at p = 0.main, each outcome as expected:O(exit 3).rng_dump: the dump is left unwritten and the row fails the dump check (exit 3).test_oracle_times_a_knob_built_planruns the hipDNN--oraclepath, which does not import torch.test_pytorch_runtime_imports_torch_before_optional_hip_timerran with the ROCm nightly torch that CI uses. The later commits do not reach either test. On that CI run the whole suite was slow, not only these two tests.Testing Checklist
pytest tests/unit -m "not gpu"- Status: Passed (2257 passed; failures only where files are outside the test archive, as on the base)rng_dump, explicit mask on ASM, p = 0 on ASM and FlyDSL,--oracleon FlyDSL - Status: Passed (all outcomes as expected)Technical Changes
execution/sdpa_dropout.py(new, no torch import): reads the dropout attributes (a nulldropout_probabilitycounts as absent) and findsrng_dump.execution/buffer_manager.py: fillsdropout_maskwith 0 and 1 at keep rate 0.9,dropout_scaleas 1 / keep rate,dropout_scale_invas the keep rate, andseedandoffsetwith nonzero values, from a separate generator so other inputs do not change; fillsrng_dumpwith NaN before each validation run.execution/correctness.py: checks an engine'srng_dump(values in {0, 1}; keep rate within 6 sigma plus one element, counted on the number of ones; first bad index named);check_correctnesscan ignore listed outputs.execution/pytorch_ops/handlers/sdpa.py,_sdpa_backend.py,_warnings.py,__init__.py: explicit-mask dropout forward and backward as separate ops (an explicit-mask backward graph with a bias gradient also gives dBias, the dropout-scaled dS before the attention scale, as the hipDNN CPU reference and SEM-014 define); p = 0 as no dropout, also in the backward, where a graph withdropout_probability0 and no dropout mask, scale or scale_inv is no dropout, with or withoutseedandoffset, as in hipDNN's backward references; dropout with causal, sliding window, bias, ALiBi and sinks; a Philox reference built from a given dump; declines for each hipDNN decline rule and for paged and ragged dropout; a reference warning for--runtime pytorch.execution/suite_runner.py,validation/providers/pytorch_provider.py,validation/reference_provider.py: a scoped Philox dump channel; each Philox engine row is graded against its own dump and reference after the timed loop; Philox withoutrng_dumpis decided before the host-memory check; the host-memory estimate (_sdpa_scratch_bytes) counts the dropout temporaries.execution/oracle.py,cli/hipdnn_tuned_child.py:run_hipdnn_tunedtakes avalidate(outputs)callable; the tuned child fills its dump with NaN and the parent validates the tuned plan from the saved outputs.main(first e31db1d, now through 61dc475): SDPA backward (feat(sdpa): support SDPA backward graphs and bump rocm-libraries (ALMIOPEN-2975, ALMIOPEN-2977) #120), ragged (feat(sdpa): support ragged and variable-length SDPA tensors #118), aiter (feat(runtime): add --runtime aiter for direct AITER SDPA benchmarking against hipDNN (ALMIOPEN-3222) #119), fix: overhaul review follow-ups: telemetry device, setup checks, CLI and compare errors, test gaps (ALMIOPEN-2866) #110 and fix(oracle): one timing mode for the PyTorch child, flush release, env warning (ALMIOPEN-2866) #111, then fix(setup, rocke): AITER build without /opt/rocm; gfx950 dense variants without head counts #136, feat(results): schema 3 with a geometry-hash graph_id #138 (result schema 3) and feat: move Workloads/ to a tag-addressed graph store (migration, --tag, s3:// source, Workloads removal) #139 (Workloads store), then feat(pytorch): record the SDPA backend and GPU kernels of PyTorch rows #137 (PyTorch SDPA backend record), chore(deps): bump rocm-libraries from4577381to28f91cf#142 and fix(deps): bump rocm-libraries to 4577381 for the 10.3.0a20261123 MIOpen #144 (rocm-libraries pin to 28f91cf, which fixes the MIOpen plugin load with the current ROCm nightly) and chore(deps): bump ROCm/rocm-security-gh/.github/workflows/security-baseline.yml from 1.0.8 to 1.0.9 in the github-actions group across 1 directory #140. The dropout handlers sit beside the new backward and ragged code.docs/usage.md,docs/methodology.md,docs/results-schema.md,AGENTS.mddescribe the formulas, the fill, the declined graphs and the new module.rng_dump, with a non-FLOATrng_dump, with paged or ragged dropout, or a Philox backward graph now fails its engine rows with--validate(timings stay). A bad or unwritten dump fails the row. A Philoxdropout_probabilitythat is NaN or outside [0, 1) also fails the row with a dump, and the message namesdropout_probability.dropout_scalein the graph JSON whose1 / dropout_scaleis outside (0, 1] is a graph error for thehipdnnandpytorchruntimes.unchecked(exit 0): a Philox row whose dump fill and read would not fit in 80 % of the available host memory, or whose reference does not fit; its tuned plan is not validated. A bad dump still fails.referencerow. Its rows are graded per row. A Philox row timed withrng_dumpincludes the dump write in each launch, so it is not a training-step time.--runtime pytorchruns explicit-mask graphs and declines Philox graphs.--runtime rockestill declines dropout. A strict--pytorch-sdpa-backendfails the rows of an explicit-mask graph (no native SDPA call), but not Philox rows withrng_dump.Omatches a reference built from that dump within the tolerance of the output data type. With bf16 outputs and thousands of keys, that tolerance cannot tell the dumped mask from another mask, or detect a softmax normalised again after the mask (docs/methodology.md). An engine that writes a correct dump but omits the1 / (1 - p)scale passes whenpis below about the relative tolerance (0.03 for bf16).seedoroffsetis now no dropout, as in hipDNN's backward references; backward Philox (p above 0 withseedandoffset) stays declined, as in hipDNN's references.main(the pin is rocm-libraries 28f91cf and includes #14358, #15066 and #15643).rng_dump(#14358), so the reference has no mask. The FlyDSL backward engines (#15643) serve it, but no reference validates it.--runtime rockedropout decline. Until then the explicit-mask evidence is failing rows (ASM and hip_flash2 ignore the mask, ALMIOPEN-3123).HIPKERNELPROVIDER_ENABLE_FLYDSLinsetup_env.pyand pull the FlyDSL descriptors, so gfx950 CI runs Philox rows.rng_dump.