Skip to content

Commit

Permalink
[torchlib] Fix wrong bias shape of ConvTranspose (#1901)
Browse files Browse the repository at this point in the history
Previously, the bias shape of ConvTranpose was wrong since, unlike Conv,
it should using the 1st dimension of weight shape and not the 0th. See
described in #1299

In other words,
```
    if bias is None:
        weight_dim_0 = op.Shape(weight, start=0, end=1)
        bias_shape = op.Expand(weight_dim_0, op.Constant(value_ints=[1]))
        zero = op.CastLike(0.0, input)
        bias = op.Expand(zero, bias_shape)
```
should be changed to something like:
```
weight_dim_0 = op.Shape(weight, start=1, end=2) if transposed else op.Shape(weight, start=0, end=1)
```

However, I think it's more efficient to just eliminate bias altogether
if it's not provided instead of filling it with zeros, since the ONNX
spec allows bias to be absent.

Signed-off-by: Yuan Yao <[email protected]>
  • Loading branch information
yuanyao-nv authored Oct 10, 2024
1 parent a7c797d commit 12f9209
Showing 1 changed file with 0 additions and 6 deletions.
6 changes: 0 additions & 6 deletions onnxscript/function_libs/torch_lib/ops/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -2030,12 +2030,6 @@ def aten_convolution(
stride = (stride, stride)
strides = list(stride)

if bias is None:
weight_dim_0 = op.Shape(weight, start=0, end=1)
bias_shape = op.Expand(weight_dim_0, op.Constant(value_ints=[1]))
zero = op.CastLike(0.0, input)
bias = op.Expand(zero, bias_shape)

result = _aten_convolution_onnx(
input,
weight,
Expand Down

0 comments on commit 12f9209

Please sign in to comment.