Skip to content

Commit 4e76a3f

Browse files
[hipdnn] Warn when conv wgrad/dgrad infers output dims assuming groups=1 (#7263)
Closes #5259. The two `infer_properties_node()` implementations silently assume `groups = 1` when computing `dw[1]` / `dx[1]`, which gives the wrong channel count for grouped convolutions unless the caller passes `dw` / `dx` shapes explicitly. This PR makes the assumption visible. Each `infer_properties_node()` now emits a `HIPDNN_FE_LOG_WARN` describing what was assumed and how to override it, and the inline comments are rewritten to match. The same caveat is added as a `@note` on `conv_dgrad` and `conv_wgrad` in `Graph.hpp` so the limitation shows up in the public docs. No behavior change for non-grouped convolutions or for callers that pass explicit `dw` / `dx` dimensions. Grouped convolutions that previously relied on inference now log a warning; the inferred channel count itself is unchanged by this PR, since fixing it would require a separate API discussion. --------- Co-authored-by: BrianHarrisonAMD <169072757+BrianHarrisonAMD@users.noreply.github.com>
1 parent c07faaa commit 4e76a3f

3 files changed

Lines changed: 32 additions & 6 deletions

File tree

projects/hipdnn/frontend/include/hipdnn_frontend/Graph.hpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2890,6 +2890,12 @@ class Graph : public INode
28902890
* (must match forward pass)
28912891
* @return dx: Gradient w.r.t. input (same shape as forward input)
28922892
*
2893+
* @note If `dx` dimensions are not provided, the channel count is
2894+
* inferred assuming `groups = 1`. For grouped convolutions,
2895+
* set dimensions on the returned `dx` tensor before graph
2896+
* validation/finalization to avoid an incorrect channel count
2897+
* on the inferred input-gradient tensor.
2898+
*
28932899
* @see hipdnn_frontend::graph::ConvDgradAttributes
28942900
*/
28952901
// NOLINTBEGIN(readability-identifier-naming)
@@ -2942,6 +2948,12 @@ class Graph : public INode
29422948
* (must match forward pass)
29432949
* @return dw: Gradient w.r.t. filter weights (same shape as forward weights)
29442950
*
2951+
* @note If `dw` dimensions are not provided, the channel count is
2952+
* inferred assuming `groups = 1`. For grouped convolutions,
2953+
* set dimensions on the returned `dw` tensor before graph
2954+
* validation/finalization to avoid an incorrect channel count
2955+
* on the inferred weight tensor.
2956+
*
29452957
* @see hipdnn_frontend::graph::ConvWgradAttributes
29462958
*/
29472959
// NOLINTBEGIN(readability-identifier-naming)

projects/hipdnn/frontend/include/hipdnn_frontend/node/ConvolutionDgradNode.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Node.hpp"
66
#include <hipdnn_data_sdk/utilities/ShapeUtilities.hpp>
77
#include <hipdnn_frontend/Error.hpp>
8+
#include <hipdnn_frontend/Logging.hpp>
89
#include <hipdnn_frontend/attributes/ConvolutionDgradAttributes.hpp>
910
#include <hipdnn_frontend/attributes/GraphAttributes.hpp>
1011
#include <hipdnn_frontend/detail/ConvolutionDgradPacker.hpp>
@@ -258,9 +259,15 @@ class ConvolutionDgradNode : public BaseNode<ConvolutionDgradNode, NodeType::CON
258259

259260
dxDims[0] = dyDims[0]; // N (batch) matches dy
260261

261-
// Impossible to infer group count without dx dimensions.
262-
// Therefore, assume groups = 1.
263-
dxDims[1] = wDims[1]; // C (input channels)
262+
// Group count cannot be inferred from dy and w alone, so the
263+
// inferred dx[1] uses w[1] (i.e. assumes groups = 1). For
264+
// grouped convolutions, callers should set dx dimensions
265+
// explicitly to avoid an incorrect channel count on the
266+
// inferred input-gradient tensor.
267+
HIPDNN_FE_LOG_WARN("ConvolutionDgradNode: inferring dx dimensions without an "
268+
"explicit dx shape; assuming groups=1. For grouped "
269+
"convolutions, set dx dimensions explicitly.");
270+
dxDims[1] = wDims[1]; // C (input channels), assuming groups=1
264271

265272
// We calculate spatial dimensions (i_2, ..., i_n)
266273
for(size_t i = 2; i < dyDims.size(); ++i)

projects/hipdnn/frontend/include/hipdnn_frontend/node/ConvolutionWgradNode.hpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Node.hpp"
66
#include <hipdnn_data_sdk/utilities/ShapeUtilities.hpp>
77
#include <hipdnn_frontend/Error.hpp>
8+
#include <hipdnn_frontend/Logging.hpp>
89
#include <hipdnn_frontend/attributes/ConvolutionWgradAttributes.hpp>
910
#include <hipdnn_frontend/attributes/GraphAttributes.hpp>
1011
#include <hipdnn_frontend/detail/ConvolutionWgradPacker.hpp>
@@ -254,9 +255,15 @@ class ConvolutionWgradNode : public BaseNode<ConvolutionWgradNode, NodeType::CON
254255

255256
dwDims[0] = dyDims[1]; // Output channels match dy channels
256257

257-
// Impossible to infer group count without dw dimensions.
258-
// Therefore, assume groups = 1.
259-
dwDims[1] = xDims[1]; // Input channels (per group)
258+
// Group count cannot be inferred from x and dy alone, so the
259+
// inferred dw[1] uses x[1] (i.e. assumes groups = 1). For
260+
// grouped convolutions, callers should set dw dimensions
261+
// explicitly to avoid an incorrect channel count on the
262+
// inferred weight tensor.
263+
HIPDNN_FE_LOG_WARN("ConvolutionWgradNode: inferring dw dimensions without an "
264+
"explicit dw shape; assuming groups=1. For grouped "
265+
"convolutions, set dw dimensions explicitly.");
266+
dwDims[1] = xDims[1]; // Input channels (per group), assuming groups=1
260267

261268
// Calculate kernel spatial dimensions (k_2, ..., k_n)
262269
for(size_t i = 2; i < dyDims.size(); ++i)

0 commit comments

Comments
 (0)