Skip to content

crash in rewriter/broadcast_to_matmul.py (proposed fix) #1541

Closed

Description

My model fails during torch.onnx.dynamo_export here with "AttributeError: 'NoneType' object has no attribute 'numpy'":

shape_c = shape_c_value.const_value.numpy() # type: ignore[union-attr]

Obviously, "if shape_c is None:" check should have been before that line, not after.
Here is a one-line diff that fixes the problem. Resulting ONNX then works and compares with PyTorch results:

--- broadcast_to_matmul.bak     2024-05-14 19:22:51.489899788 +0000
+++ broadcast_to_matmul.py      2024-05-14 19:49:17.761779925 +0000
@@ -28,9 +28,10 @@
     input_b_shape = input_b.shape
     # TODO: Get a helper func to get const_value
     shape_c_value = _ir_utils.propagate_const_value(shape_c)
-    shape_c = shape_c_value.const_value.numpy()  # type: ignore[union-attr]
+    shape_c = shape_c_value.const_value  # type: ignore[union-attr]
     if shape_c is None:
         return False
+    shape_c = shape_c.numpy()  # type: ignore[union-attr]
     if not isinstance(shape_c, np.ndarray):
         logger.info("Unexpected shape_c value. Expected np.ndarray, got %s", type(shape_c))
         return False
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions