This is an automated email from the ASF dual-hosted git repository.

masahi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git


The following commit(s) were added to refs/heads/main by this push:
     new 8ebd598fcd [bugfix] [Relay] fix broadcast in PyTorch frontend  (#14885)
8ebd598fcd is described below

commit 8ebd598fcdf26b71066f00f595085f95383a5ec0
Author: Qingchao Shen <[email protected]>
AuthorDate: Sat May 20 17:09:25 2023 +0800

    [bugfix] [Relay] fix broadcast in PyTorch frontend  (#14885)
    
    * fix broadcast_tensors
    
    * Update pytorch.py
    
    * Update test_forward.py
    
    * Update test_forward.py
---
 python/tvm/relay/frontend/pytorch.py | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/python/tvm/relay/frontend/pytorch.py 
b/python/tvm/relay/frontend/pytorch.py
index e479dd097d..08bf5d517c 100644
--- a/python/tvm/relay/frontend/pytorch.py
+++ b/python/tvm/relay/frontend/pytorch.py
@@ -2260,7 +2260,12 @@ class PyTorchOpConverter:
         tensor_list = inputs[0]
         import torch
 
-        res_shape = list(torch.broadcast_shapes(*[self.infer_shape(t) for t in 
tensor_list]))
+        infer_shape_value = [self.infer_shape(t) for t in tensor_list]
+        # "torch.broadcast_shapes" is available after PyTorch 1.8.0
+        if hasattr(torch, "broadcast_shapes"):
+            res_shape = list(torch.broadcast_shapes(*infer_shape_value))
+        else:
+            res_shape = list(torch.broadcast_tensors(*map(torch.empty, 
infer_shape_value))[0].shape)
         return [_op.broadcast_to(tensor, res_shape) for tensor in tensor_list]
 
     def Bool(self, inputs, input_types):

Reply via email to