How do I convert this model to Onnx format

#14
by softwareweaver - opened

I tried
optimum-cli export onnx --model facebook/musicgen-large music.onnx

but it gave me
\optimum\exporters\tasks.py", line 1481, in get_model_from_task
if TasksManager._TASKS_TO_LIBRARY[task.replace("-with-past", "")] == "transformers":
KeyError: 'text-to-audio'

I also tried
processor = AutoProcessor.from_pretrained("facebook/musicgen-large")
model = MusicgenForConditionalGeneration.from_pretrained("facebook/musicgen-large")
model.eval()
inputs = processor(
text=["80s pop track with bassy drums and synth"],
padding=True,
return_tensors="pt",
)
dummy_input = torch.randint(low=0, high=processor.tokenizer.vocab_size, size=(1, 12))
torch.onnx.export(model, dummy_input,"model.onnx", verbose=True )

with resulted in an error
\transformers\models\encodec\modeling_encodec.py", line 791, in forward
padding_mask = torch.ones_like(input_values).bool()
TypeError: ones_like(): argument 'input' (position 1) must be Tensor, not NoneType

I also tried it with the code below but got the same error.

tensor_x = torch.ones((1, 24), dtype=torch.int, device="cpu")
torch.onnx.export(model, tensor_x,"model.onnx", verbose=True )

It looks to be the case that the MusicGen architecture is not supported by Optimum ONNX: https://huggingface.co/docs/optimum/exporters/onnx/overview#overview

Here's the advice for unsupported architectures: https://huggingface.co/docs/transformers/serialization#exporting-a-model-for-an-unsupported-architecture

This is a pretty popular text-to-audio model (peaked at >1M downloads / month). Would it make sense to add support for it in Optimum ONNX? cc @mohitsha @fxmarty

Sign up or log in to comment