torch.ones(0) does not work.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 850
- Avg merge
- 4d 5h
- Merged PRs (30d)
- 10
Description
## 🐞Describing the bug
## Stack Trace
```
Converting PyTorch Frontend ==> MIL Ops: 86%|████████▌ | 6/7 [00:00<00:00, 3241.77 ops/s]
Running MIL Common passes: 0%| | 0/37 [00:00 NeuralNetwork Ops: 100%|██████████| 2/2 [00:00<00:00, 32768.00 ops/s]
/Users/ryosukefukatani/work/HMERModel/venv/lib/python3.9/site-packages/coremltools/models/model.py:149: RuntimeWarning: You will not be able to run predict() on this Core ML model. Underlying exception message was: Error compiling model: "Error reading protobuf spec. validator error: LoadConstantNDLayer 'var_8' has empty constants.".
_warnings.warn(
Traceback (most recent call last):
File "/Users/ryosukefukatani/work/HMERModel/atnBTTR/d17.py", line 19, in
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.float32)})
File "/Users/ryosukefukatani/work/HMERModel/venv/lib/python3.9/site-packages/coremltools/models/model.py", line 545, in predict
raise self._framework_error
File "/Users/ryosukefukatani/work/HMERModel/venv/lib/python3.9/site-packages/coremltools/models/model.py", line 147, in _get_proxy_and_spec
return (_MLModelProxy(filename, [compute_units.name](http://compute_units.name/)), specification, None)
RuntimeError: Error compiling model: "Error reading protobuf spec. validator error: LoadConstantNDLayer 'var_8' has empty constants.".
```
## To Reproduce
```python
import torch
import coremltools as ct
import numpy
class Net(torch.nn.Module):
def forward(self, x):
return torch.ones(0)
torch_model = Net()
x = torch.randn(3)
traced_model = torch.jit.trace(torch_model, x)
model_ct = ct.convert(traced_model,
inputs=[ct.TensorType(shape=x.shape, name='x')])
out_dict = model_ct.predict({'x': x.detach().numpy().astype(numpy.float32)})
```
## System environment (please complete the following information):
- coremltools version 6.0:
- MacOS: 12.4
Contributor guide
Research direction
Start with the provided Python reproduction, especially the torch.ones(0) return value and the ct.convert call. Trace how this empty tensor is represented during conversion, then run the example through model_ct.predict. Done means the conversion and prediction no longer fail with an empty constants validation error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- machine-learning, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 38/100