Failure to export torch.nn.functional.pad with int32 tensor
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
Convert does not seem to support torch pad with int32 input type
`ValueError: In op, of type pad, named val, the named input `constant_val` must have the same data type as the named input `x`. However, constant_val has dtype fp32 whereas x has dtype int32.
venv/lib/python3.9/site-packages/coremltools/converters/mil/mil/input_type.py:137: ValueError`
```python
import coremltools as ct
import torch
class Example(torch.nn.Module):
def forward(self, x):
x = torch.nn.functional.pad(x, (0, 2), value=0)
return x
module = Example().eval()
traced = torch.jit.trace(module, (torch.IntTensor([[1, 2], [3, 4]]),))
coremlmodel = ct.convert(traced,
source='pytorch',
convert_to='mlprogram',
inputs=[ct.TensorType(name="x", dtype=ct.converters.mil.mil.types.int32, shape=(2, 2)),],
outputs=[ct.TensorType(name="y", dtype=ct.converters.mil.mil.types.int32)],
compute_units=ct.ComputeUnit.ALL,
compute_precision=ct.precision.FLOAT16,
)
```
## System environment (please complete the following information):
coremltools version: 6.2
mac os x Ventura
torch: 1.13.1
python 3.9
Contributor guide
Research direction
Start with the provided torch.nn.functional.pad reproducer and the traceback location in coremltools/converters/mil/mil/input_type.py:137. Trace how the pad operation handles constant_val and x dtypes, then verify that converting the int32 example succeeds and preserves the expected output dtype.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100