add vram optimization cmdline args

This commit is contained in:
xushengyuan
2025-05-09 22:47:41 +08:00
parent 56ae032172
commit f23b7b34e3
3 changed files with 13 additions and 6 deletions
@@ -144,6 +144,7 @@ class MusicDCAE(ModelMixin, ConfigMixin, FromOriginalModelMixin):
@torch.no_grad() @torch.no_grad()
def decode_overlap(self, latents, audio_lengths=None, sr=None): def decode_overlap(self, latents, audio_lengths=None, sr=None):
print("Using Overlapped DCAE and Vocoder Decoding.")
latents = latents / self.scale_factor + self.shift_factor latents = latents / self.scale_factor + self.shift_factor
pred_wavs = [] pred_wavs = []
+3 -5
View File
@@ -88,7 +88,6 @@ REPO_ID = "ACE-Step/ACE-Step-v1-3.5B"
# class ACEStepPipeline(DiffusionPipeline): # class ACEStepPipeline(DiffusionPipeline):
class ACEStepPipeline: class ACEStepPipeline:
def __init__( def __init__(
self, self,
checkpoint_dir=None, checkpoint_dir=None,
@@ -97,9 +96,9 @@ class ACEStepPipeline:
text_encoder_checkpoint_path=None, text_encoder_checkpoint_path=None,
persistent_storage_path=None, persistent_storage_path=None,
torch_compile=False, torch_compile=False,
cpu_offload=True, cpu_offload=False,
quantized=False, quantized=False,
overlapped_decode=True, overlapped_decode=False,
**kwargs, **kwargs,
): ):
if not checkpoint_dir: if not checkpoint_dir:
@@ -462,7 +461,6 @@ class ACEStepPipeline:
from torchao.quantization import ( from torchao.quantization import (
quantize_, quantize_,
Int4WeightOnlyConfig, Int4WeightOnlyConfig,
Int8WeightOnlyConfig,
) )
group_size = 128 group_size = 128
@@ -498,6 +496,7 @@ class ACEStepPipeline:
os.path.join(text_encoder_model_path, "pytorch_model_int4wo.bin"), os.path.join(text_encoder_model_path, "pytorch_model_int4wo.bin"),
) )
def load_quantized_checkpoint(self, checkpoint_dir=None): def load_quantized_checkpoint(self, checkpoint_dir=None):
device = self.device device = self.device
@@ -507,7 +506,6 @@ class ACEStepPipeline:
text_encoder_model_path = os.path.join(checkpoint_dir, "umt5-base") text_encoder_model_path = os.path.join(checkpoint_dir, "umt5-base")
dcae_checkpoint_path = dcae_model_path dcae_checkpoint_path = dcae_model_path
vocoder_checkpoint_path = vocoder_model_path vocoder_checkpoint_path = vocoder_model_path
ace_step_checkpoint_path = ace_step_model_path ace_step_checkpoint_path = ace_step_model_path
+9 -1
View File
@@ -40,15 +40,23 @@ def sample_data(json_data):
@click.option( @click.option(
"--torch_compile", type=bool, default=False, help="Whether to use torch compile" "--torch_compile", type=bool, default=False, help="Whether to use torch compile"
) )
@click.option(
"--cpu_offload", type=bool, default=False, help="Whether to use CPU offloading (only load current stage's model to GPU)"
)
@click.option(
"--overlapped_decode", type=bool, default=False, help="Whether to use overlapped decoding (run dcae and vocoder using sliding windows)"
)
@click.option("--device_id", type=int, default=0, help="Device ID to use") @click.option("--device_id", type=int, default=0, help="Device ID to use")
@click.option("--output_path", type=str, default=None, help="Path to save the output") @click.option("--output_path", type=str, default=None, help="Path to save the output")
def main(checkpoint_path, bf16, torch_compile, device_id, output_path): def main(checkpoint_path, bf16, torch_compile, cpu_offload, overlapped_decode, device_id, output_path):
os.environ["CUDA_VISIBLE_DEVICES"] = str(device_id) os.environ["CUDA_VISIBLE_DEVICES"] = str(device_id)
model_demo = ACEStepPipeline( model_demo = ACEStepPipeline(
checkpoint_dir=checkpoint_path, checkpoint_dir=checkpoint_path,
dtype="bfloat16" if bf16 else "float32", dtype="bfloat16" if bf16 else "float32",
torch_compile=torch_compile, torch_compile=torch_compile,
cpu_offload=cpu_offload,
overlapped_decode=overlapped_decode
) )
print(model_demo) print(model_demo)