Skip to content

Mac mps support? #12

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

Open
dfl opened this issue Mar 2, 2025 · 9 comments
Open

Mac mps support? #12

dfl opened this issue Mar 2, 2025 · 9 comments

Comments

@dfl
Copy link

dfl commented Mar 2, 2025

when I try to run on Mac M3 I get the following errors:

(.sparktts) (base) ➜ example git:(main) ✗ ./infer.sh
/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torchvision/io/image.py:13: UserWarning: Failed to load image Python extension: 'dlopen(/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torchvision/image.so, 0x0006): Symbol not found: __ZN3c1017RegisterOperatorsD1Ev
Referenced from: <2BD1B165-EC09-3F68-BCE4-8FE4E70CA7E2> /Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torchvision/image.so
Expected in: /Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/lib/libtorch_cpu.dylib'If you don't plan on using image functionality from torchvision.io, you can ignore this warning. Otherwise, there might be something wrong with your environment. Did you have libjpeg or libpng installed before building torchvision from source?
warn(
/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torchvision/datapoints/init.py:12: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: pytorch/vision#6753, and you can also check out pytorch/vision#7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().
warnings.warn(_BETA_TRANSFORMS_WARNING)
/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torchvision/transforms/v2/init.py:54: UserWarning: The torchvision.datapoints and torchvision.transforms.v2 namespaces are still Beta. While we do not expect major breaking changes, some APIs may still change according to user feedback. Please submit any feedback you may have in this issue: pytorch/vision#6753, and you can also check out pytorch/vision#7319 to learn more about the APIs that we suspect might involve future changes. You can silence this warning by calling torchvision.disable_beta_transforms_warning().
warnings.warn(_BETA_TRANSFORMS_WARNING)
2025-03-02 17:51:58,980 - INFO - Using model from: pretrained_models/Spark-TTS-0.5B
2025-03-02 17:51:58,980 - INFO - Saving audio to: example/results
/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/utils/weight_norm.py:143: FutureWarning: torch.nn.utils.weight_norm is deprecated in favor of torch.nn.utils.parametrizations.weight_norm.
WeightNorm.apply(module, name, dim)
Missing tensor: mel_transformer.spectrogram.window
Missing tensor: mel_transformer.mel_scale.fb
Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/Users/dfl/work/ai/tts/Spark-TTS/cli/inference.py", line 104, in
run_tts(args)
File "/Users/dfl/work/ai/tts/Spark-TTS/cli/inference.py", line 75, in run_tts
model = SparkTTS(args.model_dir, device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/cli/SparkTTS.py", line 44, in init
self._initialize_inference()
File "/Users/dfl/work/ai/tts/Spark-TTS/cli/SparkTTS.py", line 50, in _initialize_inference
self.audio_tokenizer = BiCodecTokenizer(self.model_dir, device=self.device)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/sparktts/models/audio_tokenizer.py", line 42, in init
self._initialize_model()
File "/Users/dfl/work/ai/tts/Spark-TTS/sparktts/models/audio_tokenizer.py", line 46, in _initialize_model
self.model = BiCodec.load_from_checkpoint(f"{self.model_dir}/BiCodec").to(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1340, in to
return self._apply(convert)
^^^^^^^^^^^^^^^^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 900, in _apply
module._apply(fn)
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 900, in _apply
module._apply(fn)
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 900, in _apply
module._apply(fn)
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 927, in _apply
param_applied = fn(param)
^^^^^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/nn/modules/module.py", line 1326, in convert
return t.to(
^^^^^
File "/Users/dfl/work/ai/tts/Spark-TTS/.sparktts/lib/python3.11/site-packages/torch/cuda/init.py", line 310, in _lazy_init
raise AssertionError("Torch not compiled with CUDA enabled")
AssertionError: Torch not compiled with CUDA enabled

@RebelKeithy
Copy link

RebelKeithy commented Mar 5, 2025

I was able to work around this by replacing cuda:{device} with cpu in webui.py and inference.py. Trying to use mps as the device gives the error message "NotImplementedError: Output channels > 65536 not supported at the MPS device."

@kcalliauw
Copy link

Here's the output I'm getting when trying to run the example on MPS:

2025-03-06 17:22:32,784 - INFO - Using model from: pretrained_models/Spark-TTS-0.5B
2025-03-06 17:22:32,784 - INFO - Saving audio to: example/results
/Volumes/SN850X/code/ai/Spark-TTS/sparktts-python/lib/python3.11/site-packages/torch/nn/utils/weight_norm.py:143: FutureWarning: `torch.nn.utils.weight_norm` is deprecated in favor of `torch.nn.utils.parametrizations.weight_norm`.
  WeightNorm.apply(module, name, dim)
Missing tensor: mel_transformer.spectrogram.window
Missing tensor: mel_transformer.mel_scale.fb
2025-03-06 17:22:35,227 - INFO - Starting inference...
/AppleInternal/Library/BuildRoots/799aba5a-efcd-11ef-b353-122ba06eff56/Library/Caches/com.apple.xbs/Sources/MetalPerformanceShadersGraph/mpsgraph/MetalPerformanceShadersGraph/Core/Files/MPSGraphExecutable.mm:3561: failed assertion `Error: MLIR pass manager failed'
infer.sh: line 45: 16457 Abort trap: 6           python -m cli.inference --text "${text}" --device "${device}" --save_dir "${save_dir}" --model_dir "${model_dir}" --prompt_text "${prompt_text}" --prompt_speech_path "${prompt_speech_path}"

@JakeQiu3
Copy link

JakeQiu3 commented Mar 7, 2025

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

@AimoneAndex
Copy link

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

If you meet "NotImplementedError: Output channels > 65536 not supported at the MPS device. ",update macOS to 15.1 or newer version can maybe help.Just have a try.

@JakeQiu3
Copy link

JakeQiu3 commented Mar 9, 2025

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

If you meet "NotImplementedError: Output channels > 65536 not supported at the MPS device. ",update macOS to 15.1 or newer version can maybe help.Just have a try.

macOS 15.3.1, not work

@AimoneAndex
Copy link

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

If you meet "NotImplementedError: Output channels > 65536 not supported at the MPS device. ",update macOS to 15.1 or newer version can maybe help.Just have a try.

macOS 15.3.1, not work

I updated my torch,torchvision and torchaudio to 2.7.0(Preview edition)and it worked.Version 2.5.1 doesn't work.And I haven't try 2.6.0.

@MindFreeze
Copy link

MindFreeze commented Mar 10, 2025

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

This was fixed in a newer version of pytorch. Here is an updated requirements.txt that works:

einops==0.8.1
einx==0.3.0
numpy==1.26.4
pandas==2.2.0
omegaconf==2.3.0
packaging==24.2
safetensors==0.5.2
soundfile==0.12.1
soxr==0.5.0.post1
torch==2.6.0
torchaudio==2.6.0
tqdm==4.66.5
transformers==4.46.2
gradio==5.18.0

@euzkadie
Copy link

NotImplementedError: Output channels > 65536 not supported at the MPS device. As a temporary fix, you can set the environment variable PYTORCH_ENABLE_MPS_FALLBACK=1 to use the CPU as a fallback for this op. WARNING: this will be slower than running natively on MPS.

This was fixed in a newer version of pytorch. Here is an updated requirements.txt that works:

einops==0.8.1
einx==0.3.0
numpy==1.26.4
pandas==2.2.0
omegaconf==2.3.0
packaging==24.2
safetensors==0.5.2
soundfile==0.12.1
soxr==0.5.0.post1
torch==2.6.0
torchaudio==2.6.0
tqdm==4.66.5
transformers==4.46.2
gradio==5.18.0

Works 100% for me... Now the issue is that even tho I write the text from the audio, which is in spanish, the result audio is like some french guy reading spanish... So i guess its not working with spanish yet...

@Goactivemedia
Copy link

Is there full instructions someplace of how to install this on Mac and make it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants