facebookresearch / audiocraft

Audiocraft is a library for audio processing and generation with deep learning. It features the state-of-the-art EnCodec audio compressor / tokenizer, along with MusicGen, a simple and controllable music generation LM with textual and melodic conditioning.
MIT License
20.5k stars 2.06k forks source link

Load saved models from during training, how? #255

Closed carlthome closed 12 months ago

carlthome commented 12 months ago

Was hoping this would just work:

from audiocraft.models import MusicGen

model_path = "/tmp/audiocraft/xps/60625e70/checkpoint.th"
model = MusicGen.get_pretrained(model_path)

but I'm getting

Unexpected key(s) in state_dict: "model".

so guess there's more to it.

How can I load the saved model during training, for testing some prompts?

adefossez commented 12 months ago

You need to export the model using the instructions over there https://github.com/facebookresearch/audiocraft/blob/main/docs/MUSICGEN.md#importing--exporting-models

Another solution would be to build directly the model using, e.g.

from audiocraft.models import MusicGen
from audiocraft.solvers import MusicGenSolver

solver = MusicGenSolver.get_eval_solver_from_sig('60625e70')
solver.model.cfg = solver.cfg
musicgen = MusicGen(name='mymusicgen', compression_model=solver.compression_model, lm=solver.model)

Let me know if that snippet of code worked for you and I will add it to the README.

carlthome commented 12 months ago

Awesome! Thanks @adefossez!

Got that snippet to work but only by running it from the same working directory as the training (so same Dora directory).