You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tvm.apache.org by GitBox <gi...@apache.org> on 2021/10/09 09:17:53 UTC

[GitHub] [tvm] Xuxue1 opened a new issue #9237: [Bug]

Xuxue1 opened a new issue #9237:
URL: https://github.com/apache/tvm/issues/9237


   ```python
   class DemoModel(torch.nn.Module):
   
       def __init__(self):
           super().__init__()
   
       def forward(self, data, input_scores):
           idx = input_scores > 0.7
           return data[idx], input_scores[idx]
   
   
   def vmobj_to_list(o, dtype="float32"):
       if isinstance(o, tvm.nd.NDArray):
           return [o]
       elif isinstance(o, tvm.runtime.container.ADT):
           result = []
           for f in o:
               result.extend(vmobj_to_list(f, dtype))
           return result
       else:
           raise RuntimeError("Unknown object type: %s" % type(o))
   
   
   def process_test():
       device = torch.device('cuda')
       model = DemoModel().to(device).eval()
       input = (torch.rand(2, 3, device=device), torch.tensor([0.1, 0.5], device=device))
       traced = do_trace(model, input)
       target = tvm.target.Target("cuda")
       shape_list = [("input", (input[0].shape)), ("input_scores", (input[1].shape))]    
       mod, params = relay.frontend.from_pytorch(traced, shape_list)
       with tvm.transform.PassContext(opt_level=3):
           vm_exec = relay.vm.compile(mod, target=target, params=params)
       des_vm = VirtualMachine(vm_exec, tvm.cuda())
       des_vm.set_input("main", input=input[0].cpu().numpy(), input_scores=input[1].cpu().numpy())
       res = vmobj_to_list(des_vm.run())
       
       print("data: {}".format(res[0]))
       print("scores: {}".format(res[1]))
   
   if __name__ == "__main__":
       process_test()
   ```
   
   ### Expected behavior
   
   output: [[][]]
   scores: []
   
   ### Actual behavior
   
   output: [[0.07791223 0.7198686  0.7642788 ]
    [0.07791223 0.7198686  0.7642788 ]]
   scores: [0.1 0.1]
   
   ### Environment
   
   os: ubuntu20.4  torch: 1.9.0+cu102   tvm:0.8.dev0
   
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057


   I am facing a similar problem running the script `from_torch.py` published with the tutorial https://tvm.apache.org/docs/how_to/compile_models/from_pytorch.html.
   
   When I run the script, I get a `TracerWarning` while tracing the pretrained ResNet18 model and the final output of the Relay is very different from the PyTorch output.
   
   The `TracerWarning` happens when `tvm` is imported before `torch` even if it not used. If `tvm` is imported after `torch`, then everything works fine.
   
   The following script works, but if `import tvm` is uncommented, the `TracerWarning` appears.
   ```
   # import tvm
   import torch
   import torchvision
   
   model = torchvision.models.resnet18(pretrained=True).eval()
   input_shape = [1, 3, 224, 224]
   input_data = torch.randn(input_shape)
   scripted_model = torch.jit.trace(model, input_data).eval() 
   ```
   
   I'm using the latest version of tvm and I have tested PyTorch 1.7.1, 1.8.2 and 1.9.1.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057


   I am facing a similar problem running the script `from_torch.py` published with the tutorial https://tvm.apache.org/docs/how_to/compile_models/from_pytorch.html.
   
   When I run the script, I get a `TracerWarning` while tracing the pretrained ResNet18 model and the final output of the Realy is very different from the PyTorch output.
   
   The `TracerWarning` happens when `tvm` is imported before `torch` even if it not used. If `tvm` is imported after `torch` then everything works fine.
   
   The following script works, but if `import tvm` is uncommented, the `TracerWarning` appears.
   ```
   # import tvm
   import torch
   import torchvision
   
   model = torchvision.models.resnet18(pretrained=True).eval()
   input_shape = [1, 3, 224, 224]
   input_data = torch.randn(input_shape)
   scripted_model = torch.jit.trace(model, input_data).eval() 
   ```
   
   I'm using the latest version of tvm and I have tested PyTorch 1.7.1, 1.8.2 and 1.9.1.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-939680047


   Thanks, I agree this looks like a bug. I'll take a look.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943113815


   The `TracerWarning` simply says that the output does not match.
   > TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error:
   With rtol=1e-05 and atol=1e-05, found 587 element(s) (out of 1000) whose difference(s) exceeded the margin of error (including 0 nan comparisons). The greatest difference was 10.456806659698486 (15.65342903137207 vs. 5.196622371673584), which occurred at index (0, 611).
     _check_trace(
   
   I'm working with a clean virtualenv on Arch Linux and I have compiled tvm using this [config.cmake](https://github.com/apache/tvm/files/7344233/config.cmake.txt).


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943106737


   @lucagrementieri That's very odd and not reproducible on my end (linux, PT 1.7 or 1.9). Note that the tutorial on the doc and many PyTorch tests run on every CI job, so our PyTorch integration shouldn't be fundamentally broken like something you are seeing. 
   
   What does the `TracerWarning` say?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057


   I am facing a similar problem running ,the script `from_torch.py` published with the tutorial https://tvm.apache.org/docs/how_to/compile_models/from_pytorch.html.
   
   When I run the script, I get a `TracerWarning` while tracing the pretrained ResNet18 model and the final output of the Realy is very different from the PyTorch output.
   
   The `TracerWarning` happens when `tvm` is imported before `torch` even if it not used.
   
   The following script works, but if `import tvm` is uncommented, the `TracerWarning` appears.
   ```
   import torch
   import torchvision
   # import tvm
   
   model = torchvision.models.resnet18(pretrained=True).eval()
   input_shape = [1, 3, 224, 224]
   input_data = torch.randn(input_shape)
   scripted_model = torch.jit.trace(model, input_data).eval() 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057






-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057


   I am facing a similar problem running the script `from_torch.py` published with the tutorial https://tvm.apache.org/docs/how_to/compile_models/from_pytorch.html.
   
   When I run the script, I get a `TracerWarning` while tracing the pretrained ResNet18 model and the final output of the Realy is very different from the PyTorch output.
   
   The `TracerWarning` happens when `tvm` is imported before `torch` even if it not used.
   
   The following script works, but if `import tvm` is uncommented, the `TracerWarning` appears.
   ```
   import torch
   import torchvision
   # import tvm
   
   model = torchvision.models.resnet18(pretrained=True).eval()
   input_shape = [1, 3, 224, 224]
   input_data = torch.randn(input_shape)
   scripted_model = torch.jit.trace(model, input_data).eval() 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943106737


   @lucagrementieri That's very odd and not reproducible on my end (linux, PT 1.7 or 1.9). Note that the tutorial on the doc and many PyTorch tests run on every CI job, so our PyTorch integration shouldn't be fundamentally broken like something you are seeing. 
   
   What does  `TracerWarning` say?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943113815


   The `TracerWarning` simply says that the output does not match.
   > TracerWarning: Output nr 1. of the traced function does not match the corresponding output of the Python function. Detailed error:
   With rtol=1e-05 and atol=1e-05, found 587 element(s) (out of 1000) whose difference(s) exceeded the margin of error (including 0 nan comparisons). The greatest difference was 10.456806659698486 (15.65342903137207 vs. 5.196622371673584), which occurred at index (0, 611).
     _check_trace(
   
   I'm working with a clean virtualenv on Arch Linux and I have compiled tvm using the following [config.cmake](https://github.com/apache/tvm/files/7344233/config.cmake.txt)


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
masahi commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943122022


   Interesting. The warning says the output is corrupted already at the traced model, so if we convert from the traced model TVM result would also be corrupted. It is likely that some of libraries TVM depends on might have some conflict with PyTorch libs, so if we import TVM first, something in PyTorch is broken. See a similar issue in https://github.com/onnx/onnx/issues/2394#issuecomment-581638840.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] lucagrementieri edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
lucagrementieri edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943090057


   I am facing a similar problem running the script `from_torch.py` published with the tutorial https://tvm.apache.org/docs/how_to/compile_models/from_pytorch.html.
   
   When I run the script, I get a `TracerWarning` while tracing the pretrained ResNet18 model and the final output of the Realy is very different from the PyTorch output.
   
   The `TracerWarning` happens when `tvm` is imported before `torch` even if it not used. If `tvm` is imported after `torch`, then everything works fine.
   
   The following script works, but if `import tvm` is uncommented, the `TracerWarning` appears.
   ```
   # import tvm
   import torch
   import torchvision
   
   model = torchvision.models.resnet18(pretrained=True).eval()
   input_shape = [1, 3, 224, 224]
   input_data = torch.randn(input_shape)
   scripted_model = torch.jit.trace(model, input_data).eval() 
   ```
   
   I'm using the latest version of tvm and I have tested PyTorch 1.7.1, 1.8.2 and 1.9.1.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] masahi edited a comment on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
masahi edited a comment on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-943122022


   Interesting. The warning says the output is corrupted already at the traced model, so if we convert from the traced model TVM result would also be corrupted. It is likely that some of libraries TVM depends on might have some conflict with PyTorch libs, so if we import TVM first, something in PyTorch will be broken. See a similar issue in https://github.com/onnx/onnx/issues/2394#issuecomment-581638840.
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] Xuxue1 commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
Xuxue1 commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-939403523


   @masahi Can you help


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [tvm] hgt312 commented on issue #9237: [Bug] [PYTORCH] [FRONTEND] Torch and tvm output different

Posted by GitBox <gi...@apache.org>.
hgt312 commented on issue #9237:
URL: https://github.com/apache/tvm/issues/9237#issuecomment-992428813


   The issue is about boolean indexing, see https://numpy.org/doc/stable/reference/arrays.indexing.html#boolean-array-indexing, while relay's op `adv_index` is integer array indexing.
   Seems boolean index is just nonzero + integer array indexing, we can fix it in pytorch frontend


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@tvm.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org