Question about pytorch inplace operation

  1. Can you list the inplace operations in Pytorch?
  2. Whether the inplace operations are encouraged in Pytorch?
  3. How to avoid using inplace operations which I may not know?
  1. All inplace operations have a trailing underscore (e.g. tensor.add_, tensor.mul_), are using the “inplace syntax” (e.g. tensor += 1), or are directly accessing the data (e.g. tensor[0] = 1.).
  2. While inplace ops can save memory, they could disallow fused ops if your model is scripted. Their usage might depend on your actual use case, but you could stick to the default out-of-place ops.
  3. Don’t use ops mentioned in 1.