-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Help running on MacOS M1? #13
Comments
Thanks for this post, following because I'm running into same issues... |
Me 2 |
Seems like cuda issue can be solved by running it on CPU instead of CUDA. I also suggest taking a look at this whisper.cpp project for a reference of where macOS coreML support was added to a model: ggerganov/whisper.cpp#126 |
Try with |
thanks xaviviro - this does seem to be running
|
@xaviviro Did you try MPS with a nightly PyTorch build? Maybe it's supported... https://developer.apple.com/metal/pytorch/ Update: I guess still not supported pytorch/pytorch#78044 |
might have spoken too soon...when I run this in jupyter...
I get this error...
I've tried running the following updates and still no luck...any ideas?
also tried enabling the extensions (which seemed to work)
|
I am facing the same issue |
It worked for me after changing to cpu. I will post the steps once I get back to my computer. |
I bet the notebook is somehow using different version. But actually, do you still need "from .autonotebook import tqdm as notebook_tqdm" I think it's all automatic now, it just figures out what progress bar to use.
|
Here is what I got working:
|
can you make an idiot proof guide for getting this to work on m1? |
That sounds worthy to pay it forward. I will create a Medium post that is very detailed and link to it. The problem is code changes and tutorials will have to change too. |
Hi @DJChief , all I did was take the example posted, and asked ChatGPT to "change it so it works on cpu", it hallucinated some code, but it led to the right solution, all it took was reading the code a bit, reading the code helps a lot in understanding how to change the options, and what options are interesting to change. So the main issue appears to be if you have a fancy computer, you can use cuda, if you have a lame-ass computer like mine, you can use mps and cpu and if you are running it in "potato" you have to use cpu. I tried changing "cuda" to "mps" and it didn't work for some weird reason, so I was like "meh", I guess "cpu" it is. in my m1 it takes like 5 mins to generate 10 seconds of audio, but my m1 is old, so maybe your computer does it faster? idk, I closed all the tabs to allow the about 10GB ram or so to do it's thing, the "medium" model seems good enough. Also apparently, the prompt really matters. this code runs on my machine (TM)
As for how to run it, maybe try these steps:
you can run this command to figure out how much free space you have:
somewhere, in a soup of numbers, the free disk space is visible. 3 install XCode, https://apps.apple.com/us/app/xcode/id497799835?mt=12 (like seriously, isn't it about time you wrote that app you were thinking about 10 years ago?, well now this is the excuse), you will need another 10GB for that, so maybe delete even more files or perhaps a couple DAWs you aren't using too much. 4 install brew (yes, that's even, another thing, can you believe it!) https://brew.sh/ (so, here is the deal, brew is required because every * developer ever wants to use a package manager (it's the convenience, you see, package managers are like app-stores for developers, that's the reason we love them), maybe another GB or 2 of stuff will be lost forever in some random section of your hard-drive, no way to get it back, but like, whatever)
that should create a file called /opt/homebrew/bin/python3, treasure this file, and light a candle for guido, for we are not worthy.
these steps should be done only once, including the pip installs, however,Every time you are going to run the thing, you need to: 1. cd into the folder and 2.then activate the virtual environment, this tells bash (the computer's command interpreter) that we are using this specific set of libraries, activating the venv is done like this:.
you may be tempted to ignore the step where we make the virtual env and just mess up the main system python. recently Apple forced zsh down's people troats because having compatibility is apparently unimportant, so if you see zsh or a % symbol on the terminal, just type bash.
in my device, I also had to do this, which you may or may not have to do, depending on how far away into the future
if found, rename it, and then run it again, if you want to generate multiple ideas, from a file, you can try this script (but this is optional, feel free to just run the example and then rename the 0.wav file over an over as well, to each it's own):
Here I just made a txt file with genres I wanted to try out, one genre per line, from a file called genres.txt, you can rename it to ideas.txt I guess. but feel free to change the example, the key part here is that I suggest generating multiple samples, one single sample doesn't do it for me. if any of the steps seem too "high level", feel free to "research the way to do step x" by entering the step description in your AI of choice, I recommend ChatGPT, you can probably ask ChatGPT to take this very text and to expand on it or summarize it, if you feel lost, I'm sure it won't mind doing it. Oh btw if you don't like using ChatGPT what are you even doing in this part of town anyway? Don't be afraid to work with incomplete and imperfect instructions, and with incomplete and imperfect code, and let ChatGPT guide you along the way. being willing to tinker with the code and changing the code will allow you to run other music generation models, and who knows even make some cool music in the process. I guess my message here is don't be afraid to try stuff, it's OK if things break, you can always re-install things, re-create the virtual environment, etc. There are several models out there, most of them require some fiddling. have fun! |
when I run pip freeze it looks like this, if something fails, perhaps a pip package is missing:
|
Thanks @dataf3l! I too tried I didn't have to install as many packages: python3 -m venv env
source env/bin/activate
pip install 'torch>=2.0'
pip install -U 'git+https://git@github.com/facebookresearch/audiocraft#egg=audiocraft'
python test.py and then this test.py program worked (it automatically downloaded the models and generated wav files): import torchaudio
from audiocraft.models import MusicGen
from audiocraft.data.audio import audio_write
model = MusicGen.get_pretrained('small', device='cpu') # note cpu not cuda or mps
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.
# haven't tried the melody stuff yet
for idx, one_wav in enumerate(wav):
# Will save under {idx}.wav, with loudness normalization at -14 db LUFS.
audio_write(str(f'{idx}'), one_wav.cpu(), model.sample_rate, strategy="loudness", loudness_compressor=True) |
Pre-requisites
Note: I assumed audiocraft requires Python 3.9 so I installed that in the next steps and call it when running the program but perhaps it just needs something >=3.9 Audiocraft install instructions (in your terminal)
Copy this to a text file in your current working directory and name it
Run the program in your terminal calling python3.9
The first time it runs it will download the necessary files and then generate the following files in your working directory
Now you can tweak the program as you wish (diff prompts, longer audio, etc) Thanks for the tips @redblobgames |
I get :raise AssertionError("Torch not compiled with CUDA enabled") |
I followed the instruction above from redblobgames and was getting an error
I then removed the So this code worked for me
|
I was able to get python app.py runnig on my M1 by modifying code in app.py to this function: def load_model(version): |
Below are install instructions that should work for folks who wanna run the Gradio interface on their Mac (can confirm it works with all 4 model variations) Pre-requisites
Audiocraft install instructions (in your terminal)
Download ffmpeg and ffprobe binaries (https://evermeet.cx/ffmpeg/) and place in /usr/local/bin
Update path to the binaries in your profile
Optional: Confirm binaries are installed
In the file audiocraft/app.py update/replace the first function so it falls back to CPU
Finally, start the program that will load the gradio interface (which will direct you to a URL to enter in your browser) |
Thank you! This was very helpful. I didn't do this and it still loads and works but realize I need to because it's slooooow. I don't see this, exactly, in app.py so just want to, quite literally, ask... Am I replacing this (the only thing I see)
With this?
Also: where are the (sizable) models stored after downloading? I don't see them in "Models," but want to know in case I want to prune space. Thanks! |
Yes!! |
Thank you! Ok so now it says
But – and again I know there's not GPU Here – I can't say it's anymore faster (M1 Max, 64GB of RAM), still quite slow... Being thick here but, should it be? |
Yes, it's slow for me (M2 Max, 32GB of RAM), taking around 15–20 min to generate the three 8-second sample files. I think the models are saved in |
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...
Second, I downloaded these two items from Hugging Face but wasn't sure where to put them: https://huggingface.co/facebook/musicgen-melody
Third, when Jupyter opened in Safari I created a new notebook and ran this from here: https://github.com/facebookresearch/audiocraft#api
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.
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 use818 #
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
The text was updated successfully, but these errors were encountered: