← Back to Pull requests

fix(hipdnn): reject inconsistent operand shapes in frontend validation #16036

Closed
unknown closed this pull request without merging on Nov 25, 2026 14:36 UTC
View on GitHub
unknown unknown commented on Nov 16, 2026 21:38 UTC
Author

Summary


Graph::validate() accepted graphs that engines then read out of bounds (a matmul output larger than its inputs, layer-norm scales and statistics that disagree with X), crashed on zero or short dimensions in convolution backward and resample, and the graph builders crashed on a null tensor argument. Pointwise, reduction and layer-norm backward also rejected or mis-inferred shapes that cuDNN accepts. validate() also accepted graphs that lowering, the backend or every engine then rejected, and convolution and resample shape inference could overflow int64 into a wrong output shape. This change makes validate() reject the bad graphs with an error code, infer the shapes cuDNN infers, assign tensor UIDs deterministically, and corrects header examples and reference docs that contradicted the code.

JIRA ID : ALMIOPEN-3314
JIRA ID : ALMIOPEN-3320
JIRA ID : ALMIOPEN-3321
JIRA ID : ALMIOPEN-3331
JIRA ID : ALMIOPEN-3383
JIRA ID : ALMIOPEN-3384
JIRA ID : ALMIOPEN-3385
JIRA ID : ALMIOPEN-3389
JIRA ID : ALMIOPEN-3402
JIRA ID : ALMIOPEN-3403
JIRA ID : ALMIOPEN-3404
JIRA ID : ALMIOPEN-3405
JIRA ID : ALMIOPEN-3376
JIRA ID : ALMIOPEN-3342
JIRA ID : ALMIOPEN-3344
JIRA ID : ALMIOPEN-3333

Risk Assessment


Risk 3 of 5. Frontend validation is on every graph's path, and graphs that passed validate() before can now fail it when their operand shapes are inconsistent or when they use a value hipDNN cannot lower. A search of the samples, Python tests, test SDK, tools and provider tests found no in-repo graph that the new checks reject, apart from existing tests that relied on the old behavior: C++ and Python block-scale dequantize tests that sized the scale by the channel dimension, and resample node tests that set no mode. Those tests are updated. The NVIDIA samples fetched at build time were not searched. The layer-norm normalized dimension count comes from the scale: a lower-rank scale equal to X's trailing dimensions normalizes all of them, as before (x [2,1,14,14] with scale [1,14,14] gives 3), and any other scale is right-aligned to X's rank with leading 1s, so its first dimension that is not 1 starts the normalized range (x [2,3,4,5] with scale [1,5] gives 1). Layer-norm graphs with unit dimensions after the first normalized one (x [N,C,1,1], scale [1,C,1,1]) get a count of 3 instead of 1. A graph serialized with the old count fails validate() after deserialize(), with a message naming the count, and must be serialized again; count 1 normalized only a size-1 dimension, so such a graph never computed a layer norm. A channels-first scale (x [N,C,H,W], scale [1,C,1,1]), which cuDNN accepts, is now rejected with INVALID_VALUE, because no provider normalizes non-trailing axes and an earlier hipDNN read out of bounds.

Some failures move earlier with the same outcome. A pointwise mode, resample mode, padding mode or data type with no hipDNN backend value used to fail at build or plan creation and now fail in validate(). An SDPA forward graph with dropout but no seed or offset is now rejected in validate() rather than with "no engine". Graphs that set no tensor UIDs get them in node order, so their serialized form differs from what earlier builds produced, and graphs built with the same setter order and standard library now serialize to identical UIDs. A batch norm momentum without previous running statistics, and resample generate_index with a mode other than MAXPOOL, are accepted and ignored, as in cuDNN; resample lowers generate_index as false for those modes. INode::gather_hipdnn_tensors now takes detail::OrderedTensorSet& instead of a std::unordered_set; no node outside the frontend overrides it in this repository or the providers, but an out-of-tree node class that does must change its signature.

ASIC Coverage


No ASIC impact: every change is host-side graph validation, shape inference and UID assignment in the header-only frontend, plus documentation, and the tests are host-only. Passing PR CI is sufficient: the hipDNN Superbuild lanes build Linux and Windows and run the host tests. Multi-Arch CI ran the gfx94X GPU lanes (hipdnn, hipdnn-integration-tests, hipdnn-samples, hipdnn-cudnn-samples, hipblasltprovider, hipkernelprovider, miopenprovider, sanity) and all passed. The gfx950 and gfx110X test lanes were still running when this was written.

Testing Summary


  • Unit tests for each node cover every failing input in the tickets: the out-of-bounds matmul and layer-norm shapes, the zero-channel and short-vector crashes, a null argument in each tensor position of every builder that dereferenced one, int64 overflow in each convolution and resample shape term, every enum and data type value against the lowering mappers, the block-scale, MoE, batch-norm, resample and SDPA rejections, ragged-offset tensors in graph validation, engine configuration counts, equality, layer-norm scale inference and UID order. The cuDNN-sample pointwise and reduction graphs run through the cuDNN compatibility layer.

  • With the frontend headers reverted to develop and the new tests kept, 168 of 175 new or changed cases from the first commit fail or crash (45 with SIGFPE or SIGSEGV). The other 7 cover inputs that develop already handled.

  • Each later commit's new tests were run against the headers of the commit before it. In the second and third commits, 16 tests of new behavior fail there, and 15 tests of existing checks each fail under a mutation of the check they target. In the fourth commit, 54 tests fail on the previous headers, and the 11 guard tests that cover accepted inputs still pass; 20 tests of the new checked-arithmetic helper and custom-op equality do not compile against the previous headers. In the fifth commit, both UID-order tests fail in each of 3 runs when UIDs are assigned in hash order again. In the sixth commit, the batch-norm peer-stat and custom-op message tests fail on the previous headers, and each new test of an existing check (every overflow step of the checked arithmetic, the multiply bounds, the SDPA seed and query-side length requirements, the layer-norm one-sided scale rule and dequantize blocking of a non-last dimension) fails when that check is deleted.

  • In the second-to-last commit, the 6 tests of changed behavior (right-aligned layer-norm scale, rank-reduced backward scale, momentum without running statistics, including its lowering and match key) fail on the previous commit's headers, and the 5 guard tests still pass. Each of the 9 new tests of existing checks fails when its check is weakened (inverse variance, explicit count bound, surplus pointwise input, resample vector length, negative convolution channels).

  • In the last commit, the 4 tests of a lower-rank scale equal to X's trailing dimensions (forward, backward, the v8 compatibility layer) and of a lower-rank scale over a unit dimension of X fail on the previous commit's headers, and the 4 guard tests (all-ones scale, right-aligned scale, channels-first rejection) still pass. Removing the trailing-match rule fails the forward, backward and compatibility-layer tests.

  • Built on Linux with clang-tidy as errors, HIPDNN_ENABLE_SDPA, HIPDNN_ENABLE_CUDNN_COMPATIBILITY and HIPDNN_ENABLE_KERNEL_INGESTOR on.
  • Testing Checklist


  • hipDNN unit tests - ctest -L '^unit$' (Python tooling suites excluded) - Status: Passed (66/66 entries on the first commit; on the latest, the 9 entries that compile the frontend, merged with develop: 6909 cases, 4 skipped for missing hardware or data cases)

  • Frontend integration tests, host-only suites - hipdnn_public_frontend_tests without the GPU execute, autotune, plan-finding and handle suites - Status: Passed (534/534 cases)

  • Python frontend wheel tests - pytest in python/frontend_wheel_package/tests - Status: Passed in the automated GitHub checks (Windows Superbuild pytest: 676 passed, 125 skipped; the Linux Superbuild runs the same step and passed)

  • PR CI - GitHub PR checks - Status: Pending
  • Technical Changes


  • MatmulNode.hpp: a user-set C must have A's rank, the broadcast batch dimensions of A and B, A's rows and B's columns.

  • BatchnormNode.hpp: the forward scale's channel count must match X; it is read at index 1 for [1,C,...] and at index 0 for [C] and [C,1,1]. Momentum without the previous running mean and variance is accepted and not sent to the backend.

  • LayerNormNode.hpp, LayernormBackwardNode.hpp, detail/Utilities.hpp: one rule derives the normalized dimension count from the scale against X (a lower-rank scale equal to X's trailing dimensions normalizes all of them; any other lower-rank scale is right-aligned with leading 1s, then the first dimension that is not 1 starts the range), and an explicit count wins in the backward node, where a rank-reduced scale is accepted below it; scale and bias must match X's normalized dimensions; statistics have the rank of X or only its batch dimensions, in both directions; a rank-reduced scale [D] on X [B,S,D] infers statistics [B,S,1]. Unset scale and bias dimensions are inferred as cuDNN infers them, [1, X1..], or X's trailing dimensions when the count is set. All checks run on the first validate().

  • ConvolutionFpropNode.hpp, ConvolutionDgradNode.hpp, ConvolutionWgradNode.hpp, node/detail/CheckedShapeMath.hpp: shape terms use checked int64 arithmetic and a term that overflows is rejected; channel dimensions are checked before the group arithmetic divides by them.

  • ResampleFwdNode.hpp, ResampleBwdNode.hpp, detail/ResampleParamsValidation.hpp: supplied window, stride and padding vectors must have one value per spatial dimension, a window and stride of at least 1 and padding of at least 0; output extents use cuDNN's formula with checked arithmetic, and an inferred extent below 1 is rejected. Forward requires a padding mode and accepts and ignores generate_index for modes other than MAXPOOL, lowering it as false; both directions reject resample and padding modes with no backend value.

  • TensorAttributes.hpp, PointwiseNode.hpp: data types and pointwise modes with no backend value are rejected, through the same mappers lowering uses.

  • BlockScaleQuantizeNode.hpp, BlockScaleDequantizeNode.hpp: the scale has X's rank; dequantize block sizes align to the trailing dimensions and each scale dimension is at least ceil(X / block).

  • MoeGroupedMatmulNode.hpp: SCATTER requires as many routed rows as token rows. Routing tensors a mode does not use are documented as ignored.

  • SdpaFwdNode.hpp: a non-zero dropout probability needs seed and offset, and cannot be combined with a custom dropout mask (ATTRIBUTE_NOT_SET); padding_mask needs query and key/value lengths, where a ragged Q supplies the query lengths; bias leading dimensions broadcast against the batch and Q head counts.

  • Graph.hpp, node/Node.hpp, detail/GraphTensorIds.hpp: builders skip naming a null tensor argument instead of dereferencing it, so validate() reports ATTRIBUTE_NOT_SET. Ragged-offset tensors join the duplicate-UID check and are validated; custom ops and batch-norm peer statistics gather them. Tensors are collected in node order, so UIDs are assigned deterministically.

  • detail/GraphDetail.hpp: engine configurations are trimmed to the count the backend returns.

  • TensorAttributes.hpp, Attributes.hpp, SdpaAttributes.hpp, CustomOpNode.hpp, CustomOpAttributes.hpp: equality compares alignment and ragged layout, an absent optional tensor equals a null one, SDPA strict equality includes the fused-multiply-add hint, and custom ops support equality.

  • PointwiseNode.hpp, detail/Utilities.hpp: broadcasting aligns trailing dimensions (NumPy rules, as cuDNN); the operand check follows the mode's arity, surplus operands are accepted and left out of the operation and of its autotune match key; a null input reports ATTRIBUTE_NOT_SET.

  • ReductionNode.hpp: output strides are inferred from the output dimensions; an output without dimensions, already rejected, gets a message saying the dimensions must be set.

  • Header examples and docs (attributes/*.hpp, HeuristicPolicyInfo.hpp, hipdnn_backend.h, Environment.md, PluginDevelopment.md, miopen-plugin.rst, FlyDSL COVERAGE.md): convolution backward dilation, RMSNorm scale shape, Error::get_message, deprecated knobs, block sizes, pointwise mode names, reduction dimensions, heuristic policy order, engine plugin versions, plugin path changes with a live handle, MIOpen batch-norm running statistics and pass-by-value dropout seeds now match the code.

  • KNOWN_DIVERGENCES.md, PortingGuide.md, plugins.rst: the checks stricter than cuDNN; the layer-norm normalization rule. Reviewers approved the stricter checks (int64 overflow, matmul C, batch norm channel count, layer-norm trailing dimensions, channels-first layer-norm scale) on 2026-11-20 because each prevents an out-of-bounds read or a graph that is guaranteed to fail later.
  • Related: #13970

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: BrianHarrisonAMD Review duration: 12538m
    All Vouch review confidence checks passed
    Residual risk 0.21 = Change Risk (0.52) × (1 − Review Confidence (0.60)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    60%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #16036"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 60.5% · Lower = rushed or shallow review
    60.5%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 20.5% · Safe to merge
    20.5%