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

Add an option to do the final step on a CPU #98

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions stable_audio_tools/inference/generation.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ def generate_diffusion_cond(
init_noise_level: float = 1.0,
mask_args: dict = None,
return_latents = False,
cpu_final_step:bool = False,
**sampler_kwargs
) -> torch.Tensor:
"""
Expand Down Expand Up @@ -235,6 +236,8 @@ def generate_diffusion_cond(

# v-diffusion:
#sampled = sample(model.model, noise, steps, 0, **conditioning_tensors, embedding_scale=cfg_scale)
if cpu_final_step:
model.to('cpu')
del noise
del conditioning_tensors
del conditioning_inputs
Expand All @@ -244,6 +247,8 @@ def generate_diffusion_cond(
if model.pretransform is not None and not return_latents:
#cast sampled latents to pretransform dtype
sampled = sampled.to(next(model.pretransform.parameters()).dtype)
if cpu_final_step:
sampled = sampled.to('cpu')
sampled = model.pretransform.decode(sampled)

# Return audio
Expand Down