Repository: pytorch
Issue: [ONNX] None as input to `aten::index_put` unsupported
Labels: module: onnx,triaged,onnx-triaged

Hey together,

I am having issues exporting a pytorch model to onnx via torch.onnx.dynamo_export.
I created a small code example for reproduction of the issue and have the following questions:
1. Why leads the expression in the forward pass to the shown error when exporting?
2. What would be the optimal solution to mitigate this error?

This is my first time exporting a model with dynamo_export and i would be happy for any explanations.
Thanks in advance!

Alex

## Issue description

The export fails because of this expression in the forward pass of the model:
```
tensor_1[:, indices] = tensor_2
```
## Code example

```
import torch
import torch.nn as nn

class MyModel(nn.Module):
  def __init__(self):
      super().__init__()

  def forward(self, indices:torch.Tensor, tensor_1:torch.Tensor, tensor_2:torch.Tensor):
    
      tensor_1[:, indices] = tensor_2

      return tensor_1

# create model
model = MyModel()
model.cuda()
model.eval()

# create inputs
tensor_1 = torch.rand((32, 100), dtype=torch.float32, device="cuda:0")
tensor_2 = torch.rand((32, 50), dtype=torch.float32, device="cuda:0")  
indices = torch.randint(low=0, high=100, size=(50,), dtype=torch.long, device="cuda:0")

# export model
export_options = torch.onnx.ExportOptions(dynamic_shapes=True)
onnx_model = torch.onnx.dynamo_export(model, indices, tensor_1, tensor_2, export_options=export_options)
```

## Error Message
```
Traceback (most recent call last):
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/exporter.py", line 1428, in dynamo_export
    return Exporter(
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/exporter.py", line 1186, in export
    onnxscript_graph = fx_interpreter.run(
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 151, in wrapper
    ctx.log_and_raise_if_error(diag)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/context.py", line 366, in log_and_raise_if_error
    raise diagnostic.source_exception
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 135, in wrapper
    return_values = fn(*args, **kwargs)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/fx/fx_onnx_interpreter.py", line 539, in run
    self.run_node(
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 151, in wrapper
    ctx.log_and_raise_if_error(diag)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/context.py", line 366, in log_and_raise_if_error
    raise diagnostic.source_exception
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/diagnostics/infra/decorator.py", line 135, in wrapper
    return_values = fn(*args, **kwargs)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/fx/fx_onnx_interpreter.py", line 433, in run_node
    self.call_function(
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/fx/fx_onnx_interpreter.py", line 665, in call_function
    ] = symbolic_fn(*onnx_args, **onnx_kwargs)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/onnxscript/values.py", line 529, in __call__
    return evaluator.default().eval_function(self, args, kwargs)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/onnxscript/function_libs/torch_lib/graph_building.py", line 392, in eval_function
    return self._graph.add_function_call(function, inputs, attributes)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/onnxscript/function_libs/torch_lib/graph_building.py", line 841, in add_function_call
    result = self._add_torchscript_op_call(
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/onnxscript/function_libs/torch_lib/graph_building.py", line 705, in _add_torchscript_op_call
    graph_inputs.append(self._add_constant_to_graph(input))
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/onnxscript/function_libs/torch_lib/graph_building.py", line 665, in _add_constant_to_graph
    raise TypeError(
TypeError: Constant input '[None, l_indices_ defined in (%l_indices_ : Long(*), %l_tensor_1_ : Float(*, *), %l_tensor_2_ : Float(*, *) = prim::Param()
)]' of type '<class 'list'>' is not supported

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "convert_to_onnx_test_script.py", line 29, in <module>
    onnx_model = torch.onnx.dynamo_export(model, indices, tensor_1, tensor_2, export_options=export_options)
  File "/home/labor/anaconda3/envs/view-of-delft-env/lib/python3.8/site-packages/torch/onnx/_internal/exporter.py", line 1444, in dynamo_export
    raise OnnxExporterError(
torch.onnx.OnnxExporterError: Failed to export the model to ONNX. Generating SARIF report at 'report_dynamo_export.sarif'. SARIF is a standard format for the output of static analysis tools. SARIF logs can be loaded in VS Code SARIF viewer extension, or SARIF web viewer (https://microsoft.github.io/sarif-web-component/). Please report a bug on PyTorch Github: https://github.com/pytorch/pytorch/issues
```



## System Info
```
PyTorch version: 2.2.0+cu118
Is debug build: False
CUDA used to build PyTorch: 11.8
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.3 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: version 3.25.0
Libc version: glibc-2.35

Python version: 3.8.17 | packaged by conda-forge | (default, Jun 16 2023, 07:06:00)  [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-6.5.0-15-generic-x86_64-with-glibc2.10
Is CUDA available: True
CUDA runtime version: 11.8.89
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 4070 Ti
Nvidia driver version: 525.147.05
cuDNN version: Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.3
/usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.3
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
Address sizes:                      48 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             16
On-line CPU(s) list:                0-15
Vendor ID:                          AuthenticAMD
Model name:                         AMD Ryzen 7 5700X 8-Core Processor
CPU family:                         25
Model:                              33
Thread(s) per core:                 2
Core(s) per socket:                 8
Socket(s):                          1
Stepping:                           2
Frequency boost:                    enabled
CPU max MHz:                        4661,7178
CPU min MHz:                        2200,0000
BogoMIPS:                           6800.32
Flags:                              fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 hw_pstate ssbd mba ibrs ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip pku ospke vaes vpclmulqdq rdpid overflow_recov succor smca fsrm
Virtualization:                     AMD-V
L1d cache:                          256 KiB (8 instances)
L1i cache:                          256 KiB (8 instances)
L2 cache:                           4 MiB (8 instances)
L3 cache:                           32 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-15
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: Mitigation; safe RET, no microcode
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Retpolines, IBPB conditional, IBRS_FW, STIBP always-on, RSB filling, PBRSB-eIBRS Not affected
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Not affected

Versions of relevant libraries:
[pip3] flake8==3.9.2
[pip3] mypy==1.4.1
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.24.4
[pip3] onnx==1.15.0
[pip3] onnxruntime==1.17.0
[pip3] onnxscript==0.1.0.dev20240125
[pip3] pytorch-utils==0.5.5
[pip3] separableconv-torch==0.1.0
[pip3] torch==2.2.0+cu118
[pip3] torch_scatter==2.1.2+pt22cu118
[pip3] torch-tensorrt==1.4.0
[pip3] torchaudio==2.2.0+cu118
[pip3] torchinfo==1.8.0
[pip3] torchvision==0.17.0+cu118
[pip3] triton==2.2.0
[conda] numpy                     1.24.4           py38h59b608b_0    conda-forge
[conda] pytorch-utils             0.5.5                    pypi_0    pypi
[conda] separableconv-torch       0.1.0                    pypi_0    pypi
[conda] torch                     2.2.0+cu118              pypi_0    pypi
[conda] torch-scatter             2.1.2+pt22cu118          pypi_0    pypi
[conda] torch-tensorrt            1.4.0                    pypi_0    pypi
[conda] torchaudio                2.2.0+cu118              pypi_0    pypi
[conda] torchinfo                 1.8.0                    pypi_0    pypi
[conda] torchvision               0.17.0+cu118             pypi_0    pypi
[conda] triton                    2.2.0                    pypi_0    pypi

```