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

How can I freeze some weights of models when fine-tuning? #258

Closed sakemin closed 12 months ago

sakemin commented 12 months ago

I want to freeze the weights of the model except output_proj of ChromaStemConditioner, which is nn.Linear(in_features=12, out_features=1536, bias=True).

In which file should I add some codes for freezing the rest of the weights?

Maybe audiocraft.solvers.musicgen.py ?

Or is there any built-in freezing methods?

Thanks

adefossez commented 12 months ago

just after this line would be a good spot: https://github.com/facebookresearch/audiocraft/blob/main/audiocraft/solvers/musicgen.py#L137

Just set requires_grad = False on all the model parameters except the one you want to keep.

sakemin commented 12 months ago

@adefossez Thanks for letting me know :)