facebookresearch / seamless_communication

Foundational Models for State-of-the-Art Speech and Text Translation
Other
10.53k stars 1.02k forks source link

After downloading the seamless-m4t-large model file, How to load and inference them locally? #123

Closed jiafuz closed 10 months ago

jiafuz commented 10 months ago

After downloading all the files listed in the Files and versions? How to load them locally? When passing the folder name, I got the error:

ValueError: name must be a valid filename, but is './pretrained_models/seamless-m4t-large' instead.

The code I used are:

model_path = './pretrained_models/seamless-m4t-large' vocoder_path = './pretrained_models/vocoder' translator = Translator(model_name_or_card=model_path, vocoder_name_or_card=vocoder_path, device=torch.device('cuda:0'), dtype=None)

I also tried the following code, but no luck: model_path = './pretrained_models/seamless-m4t-large/multitask_unity_large.pt' vocoder_path = './pretrained_models/vocoder/vocoder_36langs.pt' translator = Translator(model_name_or_card=model_path, vocoder_name_or_card=vocoder_path, device=torch.device('cuda:0'), dtype=None)

Ori-Replication commented 10 months ago

Having the same problem. I can not load local models with translater function either. It always throw a ValueError like name must be a valid filename when I include slash in the string.

huangwei2913 commented 10 months ago

Having the same problem, the model pt file is over 10GB, and there is no demo about how to launch with local pt file

zachNA2 commented 10 months ago

114

Check my comment

dsp6414 commented 10 months ago

How to use local checkpoint for inference? #99

see the topic closed #99

mohsenoon commented 4 months ago

@jiafuz

After downloading all the files, you should load model and vocoder retrieve_card and save them in the desired path:

import fairseq2, joblib

model_retrieve_card = fairseq2.assets.asset_store.retrieve_card('seamlessM4T_large') vocoder_retrieve_card = fairseq2.assets.asset_store.retrieve_card('vocoder_36langs') joblib.dump(model_retrieve_card, 'seamlessM4T_large_retrieve_card.pkl') joblib.dump(vocoder_retrieve_card, 'vocoder_36langs_retrieve_card.pkl')

Then do this to load the model and vocoder locally:

from seamless_communication.inference import Translator

model_retrieve_card = joblib.load('./seamlessM4T_large_retrieve_card.pkl') model_retrieve_card.metadata['checkpoint'] = './pretrained_models/seamless-m4t-large/multitask_unity_large.pt'

vocoder_retrieve_card = joblib.load('./vocoder_36langs_retrieve_card.pkl') vocoder_retrieve_card.metadata['checkpoint'] = './pretrained_models/vocoder/vocoder_36langs.pt'

translator = Translator(model_name_or_card=model_retrieve_card, vocoder_name_or_card=vocoder_retrieve_card, device=torch.device('cuda:0'), dtype=None)

dsp6414 commented 4 months ago

已收到!