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/01/08 11:26:03 UTC

[GitHub] [tvm] t-vi commented on pull request #7231: Adding aten::unsqueeze_ and aten::copy_ ops to PT Frontend

t-vi commented on pull request #7231:
URL: https://github.com/apache/tvm/pull/7231#issuecomment-756705288


   @masahi can you elaborate a bit how you want to do that?
   
   So to my mind there are two parts to this. For slice assignments
   ```python
   @torch.jit.script
   def foo(x):
     x[:5] = 0
     return 2 * x
   ```
   we get
   ```
   graph(%x.1 : Tensor):
     %10 : bool = prim::Constant[value=0]()
     %6 : int = prim::Constant[value=1]()
     %1 : int = prim::Constant[value=0]()
     %4 : int = prim::Constant[value=5]()
     %14 : int = prim::Constant[value=2]()
     %7 : Tensor = aten::slice(%x.1, %1, %1, %4, %6)
     %8 : int = prim::dtype(%7)
     %9 : Device = prim::device(%7)
     %11 : Tensor = aten::tensor(%1, %8, %9, %10)
     %13 : Tensor = aten::copy_(%7, %11, %10)
     %16 : Tensor = aten::mul(%x.1, %14) # <string>:3:9
     return (%16)
   ```
   
   Note how `%x.1` and `%7` change their values in the line defining `%13`. In this sense, TorchScript with inplace isn't a true SSA form.
   
   So we need three things:
   - scatter (or some form of where) may provide us how to compute the tensor that is `%x.1` after the copy, 
   - we would still need to track views,
   - we would need to replace all tensors affected by the update with the new version.
   
   Note that while for this simple case, using the pattern
   ```
     out = copy_(slice(inp, ...), something)
   ```
   would be possible, but 
   ```python
   @torch.jit.script
   def foo(x):
     y = x[:2]
     y[:5] = 0
     return 2 * x
   ```
   
   P.S.: While you mention working on the TorchScript , I have a concrete plan (see my blog) to support more graph operations in TorchScript from python, so if you need something in particular, we might try to get that.


----------------------------------------------------------------
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:
users@infra.apache.org