Skip to content
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

gpu + transformers-musicgen #3420

Open
dave-gray101 opened this issue Aug 28, 2024 · 3 comments
Open

gpu + transformers-musicgen #3420

dave-gray101 opened this issue Aug 28, 2024 · 3 comments
Assignees
Labels
enhancement New feature or request

Comments

@dave-gray101
Copy link
Collaborator

it's been reported in discord that transformers-musicgen needs some changes to fully support GPU

@dave-gray101 dave-gray101 added the enhancement New feature or request label Aug 28, 2024
@dave-gray101 dave-gray101 self-assigned this Aug 28, 2024
@fakezeta
Copy link
Collaborator

fakezeta commented Aug 29, 2024

Hi @dave-gray101,

sadly I don't have the time to work on it right now. But I can leave some info here for someone with time and good will 😄

Changes needed are:
In the LoadModel, SoundGeneration and TTS add

        self.CUDA = torch.cuda.is_available()

        if self.CUDA:
            if request.MainGPU:
                device_map=request.MainGPU
            else:
                device_map="cuda:0"

default to cuda:0 if user does not specify the GPU in the config file.
Don't know why the model is loaded every time an inference is requested, probably here we can optimize.

Modify the call to from_pretrained adding the device_map

            self.processor = AutoProcessor.from_pretrained(model_name, device_map=device_map)
            self.model = MusicgenForConditionalGeneration.from_pretrained(model_name, device_map=device_map)

inputs must be on the same device used for inference:

        if self.CUDA:
            inputs = inputs.to("cuda")

To be added before the generate call in SoundGeneration and TTS
This should be enough.

@dave-gray101
Copy link
Collaborator Author

Thanks a ton!

Once I finish up a handful of infra fixes, I'll take a stab at this.

Now that transformers already supports different ways to LoadModel anyway... it may be worth re-considering merging transformers-musicgen into transformers proper

@fakezeta
Copy link
Collaborator

Sure! We can implement other type: like musicgen, diffusers, and so on.

I think that this will help also in reducing building time and final docker image size.

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

No branches or pull requests

2 participants