Pytorch on iOS (iPhone X & XR) throwing can't allocate memory exception. Ref Logs:
Labels: oncall: mobile, module: ios

### 🐛 Describe the bug

The following operation failed in the TorchScript interpreter.
 
Traceback of TorchScript, serialized code (most recent call last):
 
  File "code/__torch__/ai360_net.py", line 34, in forward
 
    confidences = []
 
    locations = []
 
    x0 = (self.base_net).forward(x, )
 
          ~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
 
    _1 = self.extras
 
    _2 = getattr(_1, "0")
 
  File "code/__torch__/torch/nn/modules/container/___torch_mangle_189.py", line 47, in forward
 
    input0 = (_0).forward(input, )
 
    input1 = (_1).forward(input0, )
 
    input2 = (_2).forward(input1, )
 
              ~~~~~~~~~~~ <--- HERE
 
    input3 = (_3).forward(input2, )
 
    input4 = (_4).forward(input3, )
 
  File "code/__torch__/ai360_net/___torch_mangle_16.py", line 13, in forward
 
      _0 = torch.add(x, (self.conv).forward(x, ), alpha=1)
 
    else:
 
      _0 = (self.conv).forward(x, )
 
            ~~~~~~~~~~~~~~~~~~ <--- HERE
 
    return _0
 
  File "code/__torch__/torch/nn/modules/container/___torch_mangle_15.py", line 23, in forward
 
    _6 = getattr(self, "6")
 
    _7 = getattr(self, "7")
 
    input0 = (_0).forward(input, )
 
              ~~~~~~~~~~~ <--- HERE
 
    input1 = (_1).forward(input0, )
 
    input2 = (_2).forward(input1, )
 
  File "code/__torch__/torch/nn/modules/conv/___torch_mangle_10.py", line 9, in forward
 
  def forward(self: __torch__.torch.nn.modules.conv.___torch_mangle_10.Conv2d,
 
    input: Tensor) -> Tensor:
 
    _0 = (self).conv2d_forward(input, self.weight, )
 
          ~~~~~~~~~~~~~~~~~~~~ <--- HERE
 
    return _0
 
  def conv2d_forward(self: __torch__.torch.nn.modules.conv.___torch_mangle_10.Conv2d,
 
  File "code/__torch__/torch/nn/modules/conv/___torch_mangle_10.py", line 29, in conv2d_forward
 
      _11 = _4
 
    else:
 
      _11 = torch.conv2d(input, weight, None, [1, 1], [0, 0], [1, 1], 1)
 
            ~~~~~~~~~~~~ <--- HERE
 
    return _11
 
 
 
Traceback of TorchScript, original code (most recent call last):
 
  File "/home/tony/anaconda3/envs/pytorch1.4/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
 
    def forward(self, input):
 
        for module in self:
 
            input = module(input)
 
                    ~~~~~~ <--- HERE
 
        return input
 
  File "/home/tony/anaconda3/envs/pytorch1.4/lib/python3.6/site-packages/torch/nn/modules/container.py", line 100, in forward
 
    def forward(self, input):
 
        for module in self:
 
            input = module(input)
 
                    ~~~~~~ <--- HERE
 
        return input
 
  File "/home/tony/anaconda3/envs/pytorch1.4/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 345, in forward
 
    def forward(self, input):
 
        return self.conv2d_forward(input, self.weight)
 
               ~~~~~~~~~~~~~~~~~~~ <--- HERE
 
  File "/home/tony/anaconda3/envs/pytorch1.4/lib/python3.6/site-packages/torch/nn/modules/conv.py", line 341, in conv2d_forward
 
                            weight, self.bias, self.stride,
 
                            _pair(0), self.dilation, self.groups)
 
        return F.conv2d(input, weight, self.bias, self.stride,
 
               ~~~~~~~~ <--- HERE
 
                        self.padding, self.dilation, self.groups)
 
**RuntimeError: [enforce fail at CPUAllocator.cpp:68] . DefaultCPUAllocator: can't allocate memory: you tried to allocate 4860032 bytes. Error code 12 (Cannot allocate memory)**
 


### Versions

Pytorch 3.0