Repository: pytorch
Issue: [mobile_optimizer] RuntimeError: We don't have an op for metal_prepack::conv2d_prepack
Labels: oncall: mobile,Stale

## 🐛 Bug

When trying to optimize a PyTorch model for running on iOS devices with Metal backend
```
traced_detector = torch.jit.trace(kp_detector, image_tensor, strict=False)
optimized_traced_detector = optimize_for_mobile(traced_detector, backend='metal')
```
I got the error:
```
RuntimeError: 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/alias_analysis.cpp":584, please report a bug to PyTorch. We don't have an op for metal_prepack::conv2d_prepack but it isn't a special case.  Argument types: Tensor, NoneType, int[], int[], int[], int, NoneType, NoneType, 
```

## To Reproduce

See [this Colab notebook](https://colab.research.google.com/drive/1X40mGa652BiJjVW_rT2uPBvcD2UAxeSa?usp=sharing) for steps to reproduce the error.
Here is the error for quick reference and text search:
```
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-18-6a416810c207> in <module>()
      1 kp_driving = kp_detector(image_tensor)
      2 traced_generator = torch.jit.trace(generator, (image_tensor, kp_driving, kp_driving), strict=False)
----> 3 optimized_traced_generator = optimize_for_mobile(traced_generator, backend='metal')
      4 optimized_traced_generator._save_for_lite_interpreter("/content/generator_metal.pt")

/usr/local/lib/python3.7/dist-packages/torch/utils/mobile_optimizer.py in optimize_for_mobile(script_module, optimization_blocklist, preserved_methods, backend)
     67         optimized_cpp_module = torch._C._jit_pass_vulkan_optimize_for_mobile(script_module._c, preserved_methods_str)
     68     elif backend == 'metal':
---> 69         optimized_cpp_module = torch._C._jit_pass_metal_optimize_for_mobile(script_module._c, preserved_methods_str)
     70     else:
     71         raise TypeError("Unknown backend, must be one of 'CPU', 'Vulkan' or 'Metal'")

RuntimeError: 0INTERNAL ASSERT FAILED at "../torch/csrc/jit/ir/alias_analysis.cpp":584, please report a bug to PyTorch. We don't have an op for metal_prepack::conv2d_prepack but it isn't a special case.  Argument types: Tensor, Tensor, int[], int[], int[], int, NoneType, NoneType, 
```

## Expected behavior

Code run without error.

## Environment

```
Collecting environment information...
PyTorch version: 1.10.0+cu111
Is debug build: False
CUDA used to build PyTorch: 11.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 18.04.5 LTS (x86_64)
GCC version: (Ubuntu 7.5.0-3ubuntu1~18.04) 7.5.0
Clang version: 6.0.0-1ubuntu2 (tags/RELEASE_600/final)
CMake version: version 3.12.0
Libc version: glibc-2.26

Python version: 3.7.12 (default, Sep 10 2021, 00:21:48)  [GCC 7.5.0] (64-bit runtime)
Python platform: Linux-5.4.104+-x86_64-with-Ubuntu-18.04-bionic
Is CUDA available: False
CUDA runtime version: 11.1.105
GPU models and configuration: Could not collect
Nvidia driver version: Could not collect
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.7.6.5
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.0.5
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.0.5
HIP runtime version: N/A
MIOpen runtime version: N/A

Versions of relevant libraries:
[pip3] msgpack-numpy==0.4.7.1
[pip3] numpy==1.19.5
[pip3] torch==1.10.0+cu111
[pip3] torchaudio==0.10.0+cu111
[pip3] torchsummary==1.5.1
[pip3] torchtext==0.11.0
[pip3] torchvision==0.11.1+cu111
[conda] Could not collect
```

## Additional context

There are 2 closed issues with same error. But trying what they stated did not work (use nightly build or save/load model from file)
https://github.com/pytorch/pytorch/issues/54377
https://github.com/pytorch/pytorch/issues/66307