coremltools icon indicating copy to clipboard operation
coremltools copied to clipboard

AttributeError during conversion with flexible shape

Open marius-verdier opened this issue 1 year ago • 4 comments

🐞Describing the bug

I get the AttributeError: 'list' object has no attribute 'val' error when I am converting a model with flexible shape.

To Reproduce

  • Please add a minimal code example that can reproduce the error when running it.
import torch.hub
import torchaudio
from denoiser import pretrained
from denoiser.dsp import convert_audio

import coremltools as ct

def get_input(path):
    example, sr = torchaudio.load(path)
    wav = convert_audio(example, sr, model.sample_rate, model.chin)
    return wav[None]

model = pretrained.master64()
model.eval()
wav = get_input('data/p287_001.wav')

trace = torch.jit.trace(model, wav)
print(wav.shape)

shape = (1, 1, ct.RangeDim(lower_bound=1, upper_bound=5000, default=1600))
print(shape)
mod = ct.convert(
    trace,
    convert_to='mlprogram',
    inputs=[ct.TensorType(shape=shape)],
    outputs=[ct.TensorType()]
)

mod.save("denoiser.mlpackage")

System environment (please complete the following information):

  • coremltools version: 7.1
  • OS (e.g. MacOS version or Linux type):
  • Any other relevant version information (e.g. PyTorch or TensorFlow version): torch 2.1.0

Additional context

  • Add anything else about the problem here that you want to share.

marius-verdier avatar Feb 29 '24 12:02 marius-verdier

I tried this PR #2050 but it did not work

marius-verdier avatar Feb 29 '24 14:02 marius-verdier

@marius-verdier - in order to move forward here, we need a minimal self-containded example, one which doesn't require loading a model from an untrusted 3rd party (i.e. denoiser).

TobyRoseman avatar Mar 01 '24 18:03 TobyRoseman

@TobyRoseman I understand, but I was not able to reproduce this bug with a self made model :(

marius-verdier avatar Mar 01 '24 19:03 marius-verdier

@TobyRoseman But the denoiser source is here, maybe it could help :

https://github.com/facebookresearch/denoiser

marius-verdier avatar Mar 04 '24 07:03 marius-verdier