[Refactor] Replace and ban a few torch.cuda functions in favor of torch.accelerator replacements. (#3365)

Signed-off-by: Nick Cao <ncao@redhat.com>
This commit is contained in:
Nick Cao authored and GitHub committed 2026-05-07 23:23:59 +08:00
1 parent 54277a8dd0
commit e6466cf0e6
40 files changed
+98 -90

No files matched your search

@@ -267,7 +267,7 @@ class LTX23Pipeline(nn.Module, ProgressBarMixin):
)
# Move text encoder back to CPU immediately
self.text_encoder.to("cpu")
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
hidden_states = text_encoder_outputs.hidden_states
@@ -754,7 +754,7 @@ class LTX23Pipeline(nn.Module, ProgressBarMixin):
)
self.connectors.to("cpu")
if torch.cuda.is_available():
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
# ---- Prepare latents ----
latent_num_frames = (num_frames - 1) // self.vae_temporal_compression_ratio + 1
@@ -978,7 +978,7 @@ class LTX23Pipeline(nn.Module, ProgressBarMixin):
self.vocoder.to(device)
audio = self.vocoder(generated_mel_spectrograms)
self.vocoder.to("cpu")
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
return DiffusionOutput(output=(video, audio))
@@ -1684,7 +1684,7 @@ class MagiHumanPipeline(nn.Module, ProgressBarMixin, DiffusionPipelineProfilerMi
super().__init__()
model_path = od_config.model
local_files_only = os.path.exists(model_path)
device = f"cuda:{torch.cuda.current_device()}"
device = f"cuda:{torch.accelerator.current_device_index()}"
self.device_str = device
self.dtype = od_config.dtype or torch.bfloat16
@@ -2255,7 +2255,7 @@ class MagiHumanPipeline(nn.Module, ProgressBarMixin, DiffusionPipelineProfilerMi
1 - self.sr_audio_noise_scale
)
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
sr_steps = sr_num_steps or self.sr_num_inference_steps_default
final_latent_video, _ = self._evaluate_with_latent(
context,
@@ -2274,9 +2274,9 @@ class MagiHumanPipeline(nn.Module, ProgressBarMixin, DiffusionPipelineProfilerMi
final_latent_video = br_latent_video
final_latent_audio = br_latent_audio
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
videos_np = self._decode_video(final_latent_video)
torch.cuda.empty_cache()
torch.accelerator.empty_cache()
audio_np = self._decode_audio(final_latent_audio)
return DiffusionOutput(output=(videos_np, audio_np))