mlx-audio: Resource limit (499000) exceeded.

Running on a 64GB Mac Mini M4 Pro, trying to parse a file with 1109 words, getting Resource limit (499000) exceeded. at the 5th chunk.

I am running it under conda.

Parsing the same file, on my Mac Mini M4Pro 24GB, it finishes without any problems (not running under conda)

I am ignorant in all things python so i’m not sure what can be causing this.

Voice: af_heart
Speed: 1.0x
Language: a
==========
Audio generated successfully, saving to audio!
==========
Duration:              00:00:02.674
Samples/sec:           1.6
Prompt:                40 tokens, 65.0 tokens-per-sec
Audio:                 1 samples, 1.6 samples-per-sec
Real-time factor:      0.23x
Processing time:       0.62s
Peak memory usage:     0.35GB
==========
Duration:              00:00:11.875
Samples/sec:           0.7
Prompt:                194 tokens, 125.5 tokens-per-sec
Audio:                 1 samples, 0.7 samples-per-sec
Real-time factor:      0.13x
Processing time:       1.55s
Peak memory usage:     0.44GB
==========
Duration:              00:00:03.674
Samples/sec:           0.5
Prompt:                56 tokens, 29.8 tokens-per-sec
Audio:                 1 samples, 0.5 samples-per-sec
Real-time factor:      0.51x
Processing time:       1.88s
Peak memory usage:     0.44GB
==========
Duration:              00:00:17.074
Samples/sec:           0.3
Prompt:                276 tokens, 74.7 tokens-per-sec
Audio:                 1 samples, 0.3 samples-per-sec
Real-time factor:      0.22x
Processing time:       3.69s
Peak memory usage:     0.51GB
==========
Duration:              00:00:14.375
Samples/sec:           0.2
Prompt:                220 tokens, 38.9 tokens-per-sec
Audio:                 1 samples, 0.2 samples-per-sec
Real-time factor:      0.39x
Processing time:       5.65s
Peak memory usage:     0.51GB
Error loading model: [metal::malloc] Resource limit (499000) exceeded.
Traceback (most recent call last):
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/generate.py", line 76, in main
    for i, result in enumerate(results):
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/kokoro.py", line 258, in generate
    for segment_idx, (graphenes, phonemes, audio) in enumerate(
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/pipeline.py", line 389, in __call__
    KokoroPipeline.infer(self.model, ps, pack, speed)
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/pipeline.py", line 235, in infer
    return model(ps, mx.array(pack[len(ps) - 1]), speed, return_output=True)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/kokoro.py", line 155, in __call__
    audio = decoder(asr, F0_pred, N_pred, ref_s[:, :128])[0]  # Working fine in MLX
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/istftnet.py", line 1075, in __call__
    x = self.generator(x, s, F0_curve)  # Working in MLX
        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/istftnet.py", line 919, in __call__
    result = self.stft.inverse(spec, phase)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/istftnet.py", line 623, in inverse
    audio = mlx_istft(
            ^^^^^^^^^^
  File "/Users/andrepadez/miniconda/envs/mlx/lib/python3.11/site-packages/mlx_audio/tts/models/kokoro/istftnet.py", line 498, in mlx_istft
    window_sum[start:end] += w**2
                             ~^^~
RuntimeError: [metal::malloc] Resource limit (499000) exceeded.
Execution time: 9.81s

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 21 (15 by maintainers)

Most upvoted comments

@lucasnewman / @Blaizzy I moved the mx.eval in kokoro.py so that it’s used by CLI and Web too in #35 I did some tests and it works fine, this replaces #33

Audio quality is so amazing! and this leverage sample is so great that we should add it as sample.

@ivanfioravanti Any ideas why this would differ from the command line and the web UI?

Let me check. Keep you posted.

Hmm, I can’t seem to reproduce that with the fix on my local machine, although I’m using the command-line interface and not the web UI. Does it work for you from the command line?

% cat leverage.txt | python -m mlx_audio.tts.generate --join_audio

Model: prince-canuma/Kokoro-82M
Text: "Leverage" is an entertaining, fun show. The cast is stellar, the writing snappy, and the characters are likable. It's nice to see a show that doesn't focus too heavily on the "dark side" of everything and can exist without a message.

That's not to say that there aren't poignant moments. (Nate in "The Snow Job" and Parker in "The Stork Job" are particularly memorable.) But they aren't in the majority. Although not every episode is brilliant, none have failed yet to make me laugh at least once.

The show follows a group of thieves who take on corporate villains who have too much power for their victims to defend themselves under normal means. Timely? Oh, yeah.

Timothy Hutton is the much-advertised Oscar-winning face of the team's leader, ex-insurance investigator Nathan Ford. At first, I was incredibly underwhelmed by Hutton's performance. After a few episodes, however, I started to think that maybe he was deliberately underacting (while the others are overacting) to contrast Nate's "honest man" to the thieves who make up the rest of the cast.

Gina Bellman plays a sympathetic Sophie Deveraux. Sophie is the team's "grifter" who moonlights as an actress. How well does that go? As Nate puts it, "she can act... when it's an act." Although she's hilarious, Bellman isn't the funniest of the cast by any means. Christian Kane, the badass Texan you might remember from "Angel," is even tougher, funnier, and angrier as the team's strangely likable fighter Eliot Spencer. Beth Riesgraf contrasts his deadpan humor perfectly as Parker, the crazy but lovable money-obsessed thief. And Aldis Hodge is hilarious, playing the cool geek of their techie, Alec Hardison.

The group has their conflicts, and in the first season, it looks like their biggest problem might be staying together. But the quirkiness and bickering creates a team of misfits that will have you rooting for them from the beginning.

"Leverage" is a good, escapist show where everything is sexy and exciting and the good guys always win. I can see this show becoming a cult hit, or I can see it failing after only a few seasons. Either way, if nothing else, it's fun!
Voice: af_heart
Speed: 1.0x
Language: a
==========
Audio generated successfully, saving to audio!
WARNING:root:EspeakFallback not Enabled: OOD words will be skipped
WARNING:root:{"type object 'EspeakWrapper' has no attribute 'set_data_path'"}
==========
Duration:              00:00:14.625
Samples/sec:           0.7
Prompt:                231 tokens, 161.4 tokens-per-sec
Audio:                 1 samples, 0.7 samples-per-sec
Real-time factor:      0.10x
Processing time:       1.43s
Peak memory usage:     0.47GB
==========
Duration:              00:00:15.750
Samples/sec:           0.2
Prompt:                262 tokens, 61.5 tokens-per-sec
Audio:                 1 samples, 0.2 samples-per-sec
Real-time factor:      0.27x
Processing time:       4.26s
Peak memory usage:     4.33GB
==========
Duration:              00:00:10.299
Samples/sec:           0.1
Prompt:                162 tokens, 23.4 tokens-per-sec
Audio:                 1 samples, 0.1 samples-per-sec
Real-time factor:      0.67x
Processing time:       6.94s
Peak memory usage:     4.64GB
==========
Duration:              00:00:23.500
Samples/sec:           0.1
Prompt:                378 tokens, 37.7 tokens-per-sec
Audio:                 1 samples, 0.1 samples-per-sec
Real-time factor:      0.43x
Processing time:       10.04s
Peak memory usage:     4.64GB
==========
Duration:              00:00:28.550
Samples/sec:           0.1
Prompt:                502 tokens, 30.8 tokens-per-sec
Audio:                 1 samples, 0.1 samples-per-sec
Real-time factor:      0.57x
Processing time:       16.28s
Peak memory usage:     4.73GB
==========
Duration:              00:00:04.000
Samples/sec:           0.0
Prompt:                62 tokens, 2.6 tokens-per-sec
Audio:                 1 samples, 0.0 samples-per-sec
Real-time factor:      6.03x
Processing time:       24.14s
Peak memory usage:     5.29GB
==========
Duration:              00:00:12.699
Samples/sec:           0.0
Prompt:                223 tokens, 8.8 tokens-per-sec
Audio:                 1 samples, 0.0 samples-per-sec
Real-time factor:      2.00x
Processing time:       25.37s
Peak memory usage:     5.29GB
==========
Duration:              00:00:15.400
Samples/sec:           0.0
Prompt:                237 tokens, 8.2 tokens-per-sec
Audio:                 1 samples, 0.0 samples-per-sec
Real-time factor:      1.87x
Processing time:       28.85s
Peak memory usage:     5.29GB
Joining 8 audio files

Actually this turned out to be pretty simple, I put up a fix here: https://github.com/Blaizzy/mlx-audio/pull/33

My pleasure!

Just install v0.0.2 and this should be solved.

Run this on your terminal:

pip install mlx-audio==0.0.2

Update, after some investigation. It sees that using np.stack solves both the jaggy audio and the issue you reported @andrepadez.

https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/tts/models/kokoro/istftnet.py#L634

Still don’t know why. I need to investigate when I come back from the long weekend.

I managed to reproduce the issue with the main branch.

It seems like the new isft is creating large temp arrays eating up the memory and affecting the audio as well. Here: https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/tts/models/kokoro/istftnet.py#L488-L498

@lucasnewman mx.stack makes the audio jaggy if you use --play, it seems like np.stack is the only thing that works when reconstructing the audio.

TEXT_CONTENT=$(< ./text1.txt)
python -m mlx_audio.tts.generate --text "$TEXT_CONTENT" --join_audio --play

https://github.com/Blaizzy/mlx-audio/blob/main/mlx_audio/tts/models/kokoro/istftnet.py#L634

The text1.txt is the same provided in the message above.

Sorry for the lack of details…

  • i did install it from source, exactly with that command
  • the text is in the annexed file, it’s a long tweet from Devon Eriksen
  • i thought it might be a problem with some characters inside but if i break it into smaller chunks, everything gets parsed correctly
  • as i said before, the same file, same long text, works perfectly on a lesser mac mini m4 pro with “only” 24GB of ram and 12 cores, it is crashing on the 64GB Ram with 14 cores.
  • i also rebooted the machine, and tried to run it cleanly, with nothing else running, same result.

Thank you for your prompt reply.

text1.txt

Also please share a reproducible example.

For instance a text similar to yours

Hey @andrepadez

Thanks for sharing this issue!

Could you install from source and then run it again to see if the issue persists? We made some changes that might improve things.

pip install git+https://github.com/Blaizzy/mlx-audio