Coder Social home page Coder Social logo

Comments (18)

CarlKenner avatar CarlKenner commented on May 29, 2024 2

I had this problem on my GTX 970. I tried adding this code to preload the models before generating audio:

preload_models(text_use_gpu=False, text_use_small=True, coarse_use_gpu=False, coarse_use_small=True, fine_use_gpu=False, fine_use_small=True, codec_use_gpu=False)

But it still gave me a CUDA out of memory error, even though I said to only use the CPU. Turns out, the generate_audio function doesn't respect the values you pass to preload_models... unless the models are the same size as generate_audio defaults to.

You need to set the environment variable SET SUNO_USE_SMALL_MODELS=True before you import bark. I ended up setting it in the batch file I use to start my program. Then it will use small models AND it will respect the use_gpu values you pass into preload_models.

You should be able to load some of the small models on the GPU, even if you can't load all of them on GPU, but I'm tired so I'll have to test that tomorrow.

from bark.

michaelachrisco avatar michaelachrisco commented on May 29, 2024 1
from bark import SAMPLE_RATE, generate_audio, preload_models
from IPython.display import Audio

#import gc
#gc.collect()
#torch.cuda.empty_cache()


# download and load all models
#preload_models()
preload_models(
    text_use_small=True,
    coarse_use_small=True,
    fine_use_gpu=True, 
    fine_use_small=True,
)

# generate audio from text
text_prompt = """
     Hello, my name is Suno. And, uh — and I like pizza. [laughs] 
     But I also have other interests such as playing tic tac toe.
"""
audio_array = generate_audio(text_prompt)

# play text in notebook
Audio(audio_array, rate=SAMPLE_RATE)

ran the above. Got the error below:
OutOfMemoryError: CUDA out of memory. Tried to allocate 44.00 MiB (GPU 0; 3.82 GiB total capacity; 2.40 GiB already allocated; 30.75 MiB free; 2.54 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

I then set: export PYTORCH_CUDA_ALLOC_CONF=garbage_collection_threshold:0.6,max_split_size_mb:21
and then the code was able to run with another ipython main.py.
Note the fine_use_gpu=True,

from bark.

shengkaixuan avatar shengkaixuan commented on May 29, 2024 1

tried on my 4g gpu, oh man, it worked! thanks

from bark.

shengkaixuan avatar shengkaixuan commented on May 29, 2024

got the same problem !

from bark.

David-Krug avatar David-Krug commented on May 29, 2024

Same problem on 360ti with 8gb vram while loading the model on my local install. Works fine for me on colab though for some reason

from bark.

gkucsko avatar gkucsko commented on May 29, 2024

try using the small models. set the environment variable USE_SMALL_MODELS="True"

from bark.

David-Krug avatar David-Krug commented on May 29, 2024

Like this?:
import os

os.environ["SUNO_USE_SMALL_MODELS"] = "True"

from bark.

gkucsko avatar gkucsko commented on May 29, 2024

Yup that should do it

from bark.

David-Krug avatar David-Krug commented on May 29, 2024

Still got the same error:
torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 12.00 MiB (GPU 0; 8.00 GiB total capacity; 7.30 GiB already allocated; 0 bytes free; 7.33 GiB reserved in total
by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation. See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

This is the code I am using:
from bark import SAMPLE_RATE, generate_audio, preload_models
import os

os.environ["SUNO_USE_SMALL_MODELS"] = "True"

preload_models()

from bark.

hritikb27 avatar hritikb27 commented on May 29, 2024

Any fix for this?

from bark.

SeanDohertyPhotos avatar SeanDohertyPhotos commented on May 29, 2024

Yup that should do it

doesn't work for me, same error

from bark.

gkucsko avatar gkucsko commented on May 29, 2024

made a new update where you can control model size and location (gpu/cpu) directly on load, like this for example:

preload_models(
    text_use_small=True,
    coarse_use_small=True,
    fine_use_gpu=False,
    fine_use_small=True,
)

from bark.

shengkaixuan avatar shengkaixuan commented on May 29, 2024

anyone tried this ?? how did it go?

from bark.

SeanDohertyPhotos avatar SeanDohertyPhotos commented on May 29, 2024

from bark import SAMPLE_RATE, generate_audio, preload_models
from IPython.display import Audio

download and load all models

preload_models(
text_use_small=True,
coarse_use_small=True,
fine_use_gpu=False,
fine_use_small=True,
)

generate audio from text

text_prompt = """
Hello, my name is Suno. And, uh — and I like pizza. [laughs]
But I also have other interests such as playing tic tac toe.
"""
audio_array = generate_audio(text_prompt)

play text in notebook

Audio(audio_array, rate=SAMPLE_RATE)

from bark.

michaelachrisco avatar michaelachrisco commented on May 29, 2024

It appears the script does not remove the cache. First time, I was able to get the script running. I ran the exact same script and get the following:

torch.cuda.OutOfMemoryError: CUDA out of memory. Tried to allocate 20.00 MiB (GPU 0; 3.82 GiB total capacity; 2.75 GiB already allocated; 20.00 MiB free; 2.88 GiB reserved in total by PyTorch) If reserved memory is >> allocated memory try setting max_split_size_mb to avoid fragmentation.  See documentation for Memory Management and PYTORCH_CUDA_ALLOC_CONF

No changes to the code or env. If I were to guess, it appears the memory is not being cleared on CUDA. Script is very cool though! Thanks for providing the source on this!

from bark.

papuSpartan avatar papuSpartan commented on May 29, 2024

You need to set the environment variable SET SUNO_USE_SMALL_MODELS=True before you import bark. I ended up setting it in the batch file I use to start my program. Then it will use small models AND it will respect the use_gpu values you pass into preload_models.

Seconding this. Without setting the environment variable before importing bark, the smaller models will not download unless you change the preload_models() arguments instead.

from bark.

gkucsko avatar gkucsko commented on May 29, 2024

image

hmmm, definitely downloads the small version for me...

from bark.

papuSpartan avatar papuSpartan commented on May 29, 2024

They do when calling preload_models with those options. I was referring to when only using the env var.

from bark.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.