Repository: pytorch
Issue: index_select op not implemented on Vulkan backend
Labels: triaged,module: embedding,module: vulkan

### 🐛 Describe the bug

I am trying to use embedding layer of PyTorch on Vulkan backend. The model was converted to TorchScript and further optimized for Vulkan backend using optimize_for_mobile function. However, the following issue due to non-existence of boxed_kernel for index_select on Vulkan backend seemingly preventing its execution.

1. Is there a way to redirect the index_select op to CPU in such case?
2. As an alternative, is there a way to implement this OP for Vulkan backend and register for making it available in dispatch table?

```
terminate called after throwing an instance of 'c10::NotImplementedError'
 what(): The following operation failed in the TorchScript interpreter.
Traceback of TorchScript, serialized code (most recent call last):
 File "code/__torch__/model/___torch_mangle_295.py", line 19, in forward
   _8 = ops.vulkan_prepack.run_linear_context(_7, CONSTANTS.c7)
   input = torch.to(torch.to(x, torch.device("vulkan")), 6)
   _9 = torch.embedding(CONSTANTS.c8, input)
        ~~~~~~~~~~~~~~~ <--- HERE
   _10 = ops.prim.NumToTensor(torch.size(input, 1))
   _11 = torch.slice(CONSTANTS.c10, 0, 0, int(torch.add(_10, CONSTANTS.c9)))
 
Traceback of TorchScript, original code (most recent call last):
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/functional.py(2267): embedding
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/sparse.py(163): forward
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1522): _slow_forward
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1541): _call_impl
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1532): _wrapped_call_impl
/home/user/torch_env/lib/python3.10/site-packages/model-20231117-py3.10.egg/custom_model/model.py(205): forward
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1522): _slow_forward
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1541): _call_impl
/home/user/torch_env/lib/python3.10/site-packages/torch/nn/modules/module.py(1532): _wrapped_call_impl
/home/user/torch_env/lib/python3.10/site-packages/torch/jit/_trace.py(1093): trace_module
/home/user/torch_env/lib/python3.10/site-packages/torch/jit/_trace.py(825): trace
/home/user/conversion_script.py(30): <module>
RuntimeError: Could not run 'aten::index_select' with arguments from the 'Vulkan' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorch on mobile, please visit https://fburl.com/ptmfixes for possible resolutions. 'aten::index_select' is only available for these backends: [CPU, Meta, QuantizedCPU, SparseCPU, BackendSelect, Python, FuncTorchDynamicLayerBackMode, Functionalize, Named, Conjugate, Negative, ZeroTensor, ADInplaceOrView, AutogradOther, AutogradCPU, AutogradCUDA, AutogradHIP, AutogradXLA, AutogradMPS, AutogradIPU, AutogradXPU, AutogradHPU, AutogradVE, AutogradLazy, AutogradMTIA, AutogradPrivateUse1, AutogradPrivateUse2, AutogradPrivateUse3, AutogradMeta, AutogradNestedTensor, Tracer, AutocastCPU, AutocastXPU, AutocastCUDA, FuncTorchBatched, BatchedNestedTensor, FuncTorchVmapMode, Batched, VmapMode, FuncTorchGradWrapper, PythonTLSSnapshot, FuncTorchDynamicLayerFrontMode, PreDispatch, PythonDispatcher].
```

### Versions

Collecting environment information...
PyTorch version: 2.4.0a0+gitb36e018
Is debug build: True
CUDA used to build PyTorch: None
ROCM used to build PyTorch: N/A

OS: Ubuntu 20.04.6 LTS (x86_64)
GCC version: (Ubuntu 9.4.0-1ubuntu1~20.04.2) 9.4.0
Clang version: 10.0.0-4ubuntu1
CMake version: version 3.29.2
Libc version: glibc-2.31

Python version: 3.10.8 (main, Nov  4 2022, 13:48:29) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-107-generic-x86_64-with-glibc2.31
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Byte Order:                         Little Endian
Address sizes:                      46 bits physical, 48 bits virtual
CPU(s):                             20
On-line CPU(s) list:                0-19
Thread(s) per core:                 1
Core(s) per socket:                 12
Socket(s):                          1
NUMA node(s):                       1
Vendor ID:                          GenuineIntel
CPU family:                         6
Model:                              151
Model name:                         12th Gen Intel(R) Core(TM) i7-12700
Stepping:                           2
CPU MHz:                            2100.000
CPU max MHz:                        4900.0000
CPU min MHz:                        800.0000
BogoMIPS:                           4224.00
Virtualization:                     VT-x
L1d cache:                          288 KiB
L1i cache:                          192 KiB
L2 cache:                           7.5 MiB
NUMA node0 CPU(s):                  0-19
Vulnerability Gather data sampling: Not affected
Vulnerability Itlb multihit:        Not affected
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Not affected
Vulnerability Retbleed:             Not affected
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS; IBPB conditional; RSB filling; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.26.0
[pip3] torch==2.4.0a0+gitb36e018
[pip3] torchvision==0.19.0a0+61d97f4
[pip3] triton==2.3.0
[conda] blas                      1.0                         mkl
[conda] executorch                0.3.0a0+37d65a9          pypi_0    pypi
[conda] mkl                       2021.4.0           h06a4308_640
[conda] mkl-service               2.4.0           py310h7f8727e_0
[conda] mkl_fft                   1.3.1           py310hd6ae3a3_0
[conda] mkl_random                1.2.2           py310h00e6091_0
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] numpy-base                1.22.3          py310h9585f30_0
[conda] numpydoc                  1.5.0           py310h06a4308_0
[conda] pytorch-lightning         2.2.3                    pypi_0    pypi
[conda] torch                     2.4.0.dev20240422+cpu          pypi_0    pypi
[conda] torchaudio                2.2.0.dev20240422+cpu          pypi_0    pypi
[conda] torchmetrics              1.3.2                    pypi_0    pypi
[conda] torchsr                   1.0.4                    pypi_0    pypi
[conda] torchvision               0.19.0.dev20240422+cpu          pypi_0    pypi
[conda] triton                    2.1.0                    pypi_0    pypi