pytorch / android-demo-app

PyTorch android examples of usage in applications
1.48k stars 607 forks source link

I have a Whisper-based model. How can I convert it to fairseq.dict format ? #322

Open Roland-Du opened 1 year ago

Roland-Du commented 1 year ago

model https://huggingface.co/openai/whisper-large-v2

Roland-Du commented 1 year ago

After using the Tiny model for training, the saved model file is in pt format torch.save({"dims": asdict(dims), "model_state_dict": hf_state_dict}, "/root/tiny_v2.pt")

I am trying to convert the model to pt in jit format

import torch
model = torch.load('/root/tiny_v2.pt')

batch_size, channels, time = 32, 1, 16000
inputs = torch.rand(batch_size, channels, time) traced_model = torch.jit.script(model, inputs)

traced_model = torch.jit.trace(model, inputs)

torch.jit.save(traced_model, 'model_jit.pt')

traced_model.save('jit_model.pt')

/usr/local/lib64/python3.9/site-packages/torch/jit/_script.py:1241: UserWarning: optimize is deprecated and has no effect. Use `with torch.jit.optimized_execution() instead warnings.warn( Traceback (most recent call last): File "/home/duzg/asr/dzg.py", line 7, in traced_model = torch.jit.script(model, inputs) File "/usr/local/lib64/python3.9/site-packages/torch/jit/_script.py", line 1289, in script return create_script_dict(obj) File "/usr/local/lib64/python3.9/site-packages/torch/jit/_script.py", line 1020, in create_script_dict return torch._C.ScriptDict(obj) # type: ignore[attr-defined] torch.jit.Error: Unable to infer type of dictionary: Dictionary inputs to traced functions must have consistent type. Found Dict[str, int] and Dict[str, Tensor]