masahi commented on pull request #7231:
URL: https://github.com/apache/tvm/pull/7231#issuecomment-756693366


   cc @t-vi @yongwww 
   
   This is probably not how we should support `copy_`. We discussed this issue 
before.
   
   Later I found a promising way to support inplace copy: We first convert 
`aten::copy_` to `aten::index_put` (see 
https://pytorch.org/docs/stable/tensors.html#torch.Tensor.index_put_) using 
PyTorch jit passes, and then convert `aten::index_put` to relay `scatter_nd`. 
This is also how PyTorch ONNX export supports inplace assignment, see 
https://github.com/pytorch/pytorch/pull/26941
   
   Relay `scatter_nd` op was added in https://github.com/apache/tvm/pull/6854. 
You can convert `aten::copy_` to `aten::inplace_put` by adding the following 
after 
https://github.com/apache/tvm/blob/d1399f378e37e9e4d9bfadc5cdae57fdc5bcaf7f/python/tvm/relay/frontend/pytorch.py#L2643
   
   ```
   torch._C._jit_pass_onnx_prepare_inplace_ops_for_onnx(graph)
   torch._C._jit_pass_dce_allow_deleting_nodes_with_side_effects(graph)
   ```
   
   @t-vi Does this sound reasonable a way to support inplace assignment?


----------------------------------------------------------------
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.

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


Reply via email to