Update: For most this should work #13 (comment)
Any chance of getting help and/or updated instructions suitable for running audiocraft on MacOS and M1? At the very least, I think I need to know where to put the models I downloaded from Hugging Face. But, it's likely based on the errors I have some other issues too. My steps + errors follow. Thanks for any tips!
I adapted the instructions here for macOS: https://github.com/facebookresearch/audiocraft#installation
First, I ran each line in my terminal...
conda create -n audiocraft
conda activate audiocraft
pip install 'torch>=2.0'
pip install -U audiocraft
pip install ffmpeg
jupyter notebook
Second, I downloaded these two items from Hugging Face but wasn't sure where to put them: https://huggingface.co/facebook/musicgen-melody
- melody: 1.5B model, text to music and text+melody to music - 🤗 Hub
- large: 3.3B model, text to music only - 🤗 Hub
Third, when Jupyter opened in Safari I created a new notebook and ran this from here: https://github.com/facebookresearch/audiocraft#api
import torchaudio
from audiocraft.models import MusicGen
from audiocraft.data.audio import audio_write
model = MusicGen.get_pretrained('melody')
model.set_generation_params(duration=8) # generate 8 seconds.
wav = model.generate_unconditional(4) # generates 4 unconditional audio samples
descriptions = ['happy rock', 'energetic EDM', 'sad jazz']
wav = model.generate(descriptions) # generates 3 samples.
melody, sr = torchaudio.load('./assets/bach.mp3')
# generates using the melody from the given audio and the provided descriptions.
wav = model.generate_with_chroma(descriptions, melody[None].expand(3, -1, -1), sr)
for idx, one_wav in enumerate(wav):
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
audio_write(f'{idx}', one_wav.cpu(), model.sample_rate, strategy="loudness")
Fourth, I got these errors in Jupyter
AssertionError Traceback (most recent call last)
Cell In [2], line 5
2 from audiocraft.models import MusicGen
3 from audiocraft.data.audio import audio_write
----> 5 model = MusicGen.get_pretrained('melody')
6 model.set_generation_params(duration=8) # generate 8 seconds.
7 wav = model.generate_unconditional(4) # generates 4 unconditional audio samples
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/audiocraft/models/musicgen.py:88, in MusicGen.get_pretrained(name, device)
86 else:
87 ROOT = 'https://dl.fbaipublicfiles.com/audiocraft/musicgen/v0/'
---> 88 compression_model = load_compression_model(ROOT + 'b0dbef54-37d256b525.th', device=device)
89 names = {
90 'small': 'ba7a97ba-830fe5771e',
91 'medium': 'aa73ae27-fbc9f401db',
92 'large': '9b6e835c-1f0cf17b5e',
93 'melody': 'f79af192-61305ffc49',
94 }
95 sig = names[name]
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/audiocraft/models/loaders.py:45, in load_compression_model(file_or_url, device)
43 cfg = OmegaConf.create(pkg['xp.cfg'])
44 cfg.device = str(device)
---> 45 model = builders.get_compression_model(cfg)
46 model.load_state_dict(pkg['best_state'])
47 model.eval()
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/audiocraft/models/builders.py:82, in get_compression_model(cfg)
79 renormalize = renorm is not None
80 warnings.warn("You are using a deprecated EnCodec model. Please migrate to new renormalization.")
81 return EncodecModel(encoder, decoder, quantizer,
---> 82 frame_rate=frame_rate, renormalize=renormalize, **kwargs).to(cfg.device)
83 else:
84 raise KeyError(f'Unexpected compression model {cfg.compression_model}')
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1145, in Module.to(self, *args, **kwargs)
1141 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
1142 non_blocking, memory_format=convert_to_format)
1143 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
-> 1145 return self._apply(convert)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:797, in Module._apply(self, fn)
795 def _apply(self, fn):
796 for module in self.children():
--> 797 module._apply(fn)
799 def compute_should_use_set_data(tensor, tensor_applied):
800 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
801 # If the new tensor has compatible tensor type as the existing tensor,
802 # the current behavior is to change the tensor in-place using .data =
,
(...)
807 # global flag to let the user control whether they want the future
808 # behavior of overwriting the existing tensor or not.
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:797, in Module._apply(self, fn)
795 def _apply(self, fn):
796 for module in self.children():
--> 797 module._apply(fn)
799 def compute_should_use_set_data(tensor, tensor_applied):
800 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
801 # If the new tensor has compatible tensor type as the existing tensor,
802 # the current behavior is to change the tensor in-place using .data =
,
(...)
807 # global flag to let the user control whether they want the future
808 # behavior of overwriting the existing tensor or not.
[... skipping similar frames: Module._apply at line 797 (2 times)]
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:797, in Module._apply(self, fn)
795 def _apply(self, fn):
796 for module in self.children():
--> 797 module._apply(fn)
799 def compute_should_use_set_data(tensor, tensor_applied):
800 if torch._has_compatible_shallow_copy_type(tensor, tensor_applied):
801 # If the new tensor has compatible tensor type as the existing tensor,
802 # the current behavior is to change the tensor in-place using .data =
,
(...)
807 # global flag to let the user control whether they want the future
808 # behavior of overwriting the existing tensor or not.
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:820, in Module._apply(self, fn)
816 # Tensors stored in modules are graph leaves, and we don't want to
817 # track autograd history of param_applied
, so we have to use
818 # with torch.no_grad():
819 with torch.no_grad():
--> 820 param_applied = fn(param)
821 should_use_set_data = compute_should_use_set_data(param, param_applied)
822 if should_use_set_data:
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/nn/modules/module.py:1143, in Module.to..convert(t)
1140 if convert_to_format is not None and t.dim() in (4, 5):
1141 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None,
1142 non_blocking, memory_format=convert_to_format)
-> 1143 return t.to(device, dtype if t.is_floating_point() or t.is_complex() else None, non_blocking)
File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/torch/cuda/init.py:239, in _lazy_init()
235 raise RuntimeError(
236 "Cannot re-initialize CUDA in forked subprocess. To use CUDA with "
237 "multiprocessing, you must use the 'spawn' start method")
238 if not hasattr(torch._C, '_cuda_getDeviceCount'):
--> 239 raise AssertionError("Torch not compiled with CUDA enabled")
240 if _cudart is None:
241 raise AssertionError(
242 "libcudart functions unavailable. It looks like you have a broken build?")
AssertionError: Torch not compiled with CUDA enabled