yongwww edited a comment on pull request #6472:
URL: https://github.com/apache/incubator-tvm/pull/6472#issuecomment-692568164


   > > Seems PyTorch already has a set of passes to remove mutation
   > 
   > Note fat warning at the top of the class, though.
   > 
   > A typical use of copy is something like this:
   > 
   > ```
   > In [1]: import torch
   > 
   > In [2]: @torch.jit.script
   >    ...: def update(x, y):
   >    ...:     x[0] = y
   >    ...:     return x
   >    ...: 
   > 
   > In [3]: update.graph
   > Out[3]: 
   > graph(%x.1 : Tensor,
   >       %y.1 : Tensor):
   >   %7 : bool = prim::Constant[value=0]()
   >   %4 : int = prim::Constant[value=0]() # <ipython-input-2-e9bf1f9acfa9>:3:6
   >   %6 : Tensor = aten::select(%x.1, %4, %4) # 
<ipython-input-2-e9bf1f9acfa9>:3:4
   >   %8 : Tensor = aten::copy_(%6, %y.1, %7) # 
<ipython-input-2-e9bf1f9acfa9>:3:4
   >   return (%x.1)
   > ```
   
   just tested with a similar test case as the one you provided, the slicing 
assignment doesn't take effect in jit graph.
   
          ```
           # test case
           def forward(self, *args):
               a = args[0]
               b = args[1]
               a[0] = b
               return a
           ```
   related graph:
   
   ```
   graph(%self : __torch__.Copy,
         %a : Float(2, 3),
         %b : Float(1, 3)):
     %3 : int = prim::Constant[value=0]() 
     %4 : int = prim::Constant[value=0]() 
     %5 : Float(3) = aten::select(%a, %3, %4) # 
     %6 : int = prim::Constant[value=3]() 
     %7 : int[] = prim::ListConstruct(%6)
     %8 : Float(3) = aten::view(%b, %7) 
     %9 : bool = prim::Constant[value=0]()
     %10 : Float(3) = aten::copy_(%5, %8, %9) 
     return (%a)
   ```
   
   


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