Check existence of the array ref when tracing resize_ (#81422)
When `.resize_` takes an empty `torch.Size` or ints, tracing it would result in a `RuntimeError: _Map_base::at` (key not found in map).
In
https://github.com/pytorch/pytorch/blob/0d124fc6961f5b39f1a46722dab2d88f23686783/torch/csrc/jit/frontend/tracer.h#L126-L129
- This change updates `TraceType::resize_` to check the mapping first.
- It also updates the warning message when tracing `resize_` to suggest using reshape or view.
Repo:
```python
import torch
class M(torch.nn.Module):
def forward(self, x, y):
print(y.shape)
x = x.resize_(y.shape)
return x, y
x = torch.tensor(1.2)
y = torch.tensor(4.2)
M()(x, y)
torch.jit.trace(M(), (x, y))
```
Related: https://github.com/pytorch/pytorch/issues/76486
Pull Request resolved: https://github.com/pytorch/pytorch/pull/81422
Approved by: https://github.com/BowenBao, https://github.com/malfet