-
Notifications
You must be signed in to change notification settings - Fork 116
[torchlib] Fix aten_conv3d generating a 2D bias when bias is missing #2935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,6 +5,7 @@ | |
| import math | ||
| import unittest | ||
|
|
||
| import onnx | ||
| import parameterized | ||
|
|
||
| # TODO(pytorch/pytorch#129279): Migrate these tests to the PyTorch repo | ||
|
|
@@ -1004,6 +1005,32 @@ def forward(self, x): | |
| got = onnx_program.call_reference({"x": inputs[0]}) | ||
| torch.testing.assert_close(expected, got[0]) | ||
|
|
||
| def test_conv3d_without_bias_produces_1d_bias(self): | ||
| class Model(torch.nn.Module): | ||
| def __init__(self): | ||
| super().__init__() | ||
| self.conv = torch.nn.Conv3d(3, 4, kernel_size=2, bias=False) | ||
|
|
||
| def forward(self, x): | ||
| return self.conv(x) | ||
|
|
||
| onnx_program = torch.onnx.export( | ||
| Model().eval(), (torch.randn(1, 3, 8, 8, 8),), dynamo=True, optimize=False | ||
| ) | ||
| _testing.assert_onnx_program(onnx_program) | ||
|
|
||
| # The bias synthesized for a bias-less conv must be 1D ([out_channels]) to | ||
| # match the ONNX Conv spec. See https://github.com/microsoft/onnxscript/issues/2931. | ||
| inferred = onnx.shape_inference.infer_shapes(onnx_program.model_proto, data_prop=True) | ||
| shape_ranks = { | ||
| value_info.name: len(value_info.type.tensor_type.shape.dim) | ||
| for value_info in inferred.graph.value_info | ||
| if value_info.type.tensor_type.HasField("shape") | ||
| } | ||
| conv_nodes = [node for node in inferred.graph.node if node.op_type == "Conv"] | ||
| self.assertEqual(len(conv_nodes), 1) | ||
| self.assertEqual(shape_ranks[conv_nodes[0].input[2]], 1) | ||
|
Comment on lines
+1022
to
+1032
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok to review this part as assert_onnx_program will already run the model and validate the shapes.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before I drop it: the synthesized bias is all zeros, so |
||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| unittest.main() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.