torch.index_put conversion error
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
Hi!
I am trying to convert NN with the following operation inside:
```python
accum = torch.zeros((N, C, self.numangle, self.numrho), dtype=torch.float32)
...
accum.index_put_(indices=[n_i_t, c_i_t, angls, accum_idxs],
values=img[n_i_t, c_i_t, y_idxs, x_idxs],
accumulate=True)
```
**jit.trace** goes well, but on **ct.convert** step I've got the following error:
```bash
File "/Users/user/opt/anaconda3/envs/retech_dht/lib/python3.8/site-packages/coremltools/converters/mil/mil/ops/defs/iOS15/tensor_operation.py", line 1282, in value_inference
return np.stack(values, self.axis.val)
File "<__array_function__ internals>", line 180, in stack
File "/Users/user/opt/anaconda3/envs/retech_dht/lib/python3.8/site-packages/numpy/core/shape_base.py", line 429, in stack
axis = normalize_axis_index(axis, result_ndim)
numpy.AxisError: axis 3 is out of bounds for array of dimension 2
```
Conversion performed well if I comment line with **index_put_**
python: 3.8
torch version: 1.12.1
coremltools version: 6.1
Contributor guide
Research direction
Reproduce the conversion using the reported torch.index_put_ operation and ct.convert call, then inspect coremltools/converters/mil/mil/ops/defs/iOS15/tensor_operation.py around line 1282. Trace why value_inference calls np.stack with axis 3 for a two-dimensional result. Done means the model converts without the reported AxisError and the index_put_ behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100