[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:
1 parent
54277a8dd0
commit
e6466cf0e6
40 files changed
+98
-90
No files matched your search
@@ -372,7 +372,7 @@ class FishSpeechFastAR(nn.Module):
|
||||
dtype=torch.long,
|
||||
)
|
||||
self(hidden, semantic, do_sample=False)
|
||||
torch.cuda.synchronize(device)
|
||||
torch.accelerator.synchronize(device)
|
||||
|
||||
@torch.inference_mode()
|
||||
def _run_model(self, step_input: torch.Tensor, step_pos_ids: torch.Tensor, bsz: int) -> torch.Tensor:
|
||||
|
||||
@@ -1603,7 +1603,7 @@ class HunyuanImage3ForConditionalGeneration(nn.Module, SupportsMultiModal, Suppo
|
||||
layer.mlp = None
|
||||
del mlp
|
||||
gc.collect()
|
||||
torch.cuda.empty_cache()
|
||||
torch.accelerator.empty_cache()
|
||||
|
||||
layer.mlp = HunyuanImage3SparseMoeBlock(
|
||||
config=self.config,
|
||||
|
||||
@@ -276,7 +276,9 @@ class MiMoAudioDataParser(MultiModalDataParser):
|
||||
self.device = torch.device(tokenizer_device)
|
||||
else:
|
||||
# Default to cuda (will use current GPU)
|
||||
self.device = torch.device(f"cuda:{torch.cuda.current_device()}" if torch.cuda.is_available() else "cpu")
|
||||
self.device = torch.device(
|
||||
f"cuda:{torch.accelerator.current_device_index()}" if torch.cuda.is_available() else "cpu"
|
||||
)
|
||||
|
||||
self.audio_tokenizer_path = os.environ.get("MIMO_AUDIO_TOKENIZER_PATH", None)
|
||||
if not self.audio_tokenizer_path:
|
||||
|
||||
@@ -793,7 +793,7 @@ class MiMoAudioLLMForConditionalGeneration(nn.Module, SupportsMultiModal, Suppor
|
||||
local_embeds: torch.FloatTensor, # [1, 1, hidden_size]
|
||||
tokens_dtype: torch.dtype = torch.int64,
|
||||
tokens_device: torch.device = torch.device(
|
||||
f"cuda:{torch.cuda.current_device()}" if torch.cuda.is_available() else "cpu"
|
||||
f"cuda:{torch.accelerator.current_device_index()}" if torch.cuda.is_available() else "cpu"
|
||||
),
|
||||
local_sampler: MiMoSampler | MiMoLocalSamplerTensor | None = None,
|
||||
):
|
||||
@@ -847,7 +847,7 @@ class MiMoAudioLLMForConditionalGeneration(nn.Module, SupportsMultiModal, Suppor
|
||||
local_embeds: torch.FloatTensor, # [1, 1, hidden_size]
|
||||
tokens_dtype: torch.dtype = torch.int64,
|
||||
tokens_device: torch.device = torch.device(
|
||||
f"cuda:{torch.cuda.current_device()}" if torch.cuda.is_available() else "cpu"
|
||||
f"cuda:{torch.accelerator.current_device_index()}" if torch.cuda.is_available() else "cpu"
|
||||
),
|
||||
local_sampler: MiMoSampler | None = None,
|
||||
):
|
||||
|
||||
@@ -110,7 +110,7 @@ class CUDAGraphDecoderWrapper:
|
||||
with torch.no_grad():
|
||||
_ = self.decoder(dummy)
|
||||
|
||||
torch.cuda.synchronize(device)
|
||||
torch.accelerator.synchronize(device)
|
||||
|
||||
for size in self.capture_sizes:
|
||||
try:
|
||||
@@ -126,7 +126,7 @@ class CUDAGraphDecoderWrapper:
|
||||
static_input = torch.zeros(1, self.num_quantizers, size, dtype=dtype, device=device)
|
||||
with torch.no_grad():
|
||||
_ = self.decoder(static_input)
|
||||
torch.cuda.synchronize(device)
|
||||
torch.accelerator.synchronize(device)
|
||||
|
||||
graph = CUDAGraph()
|
||||
with torch.no_grad():
|
||||
|
||||
@@ -229,7 +229,7 @@ class _PerfTimer:
|
||||
def _resolve(self) -> None:
|
||||
if not self._pairs:
|
||||
return
|
||||
torch.cuda.synchronize()
|
||||
torch.accelerator.synchronize()
|
||||
for name, s, e in self._pairs:
|
||||
self._timers[name] = self._timers.get(name, 0.0) + s.elapsed_time(e)
|
||||
self._counts[name] = self._counts.get(name, 0) + 1
|
||||
@@ -433,7 +433,7 @@ class VoxCPM2TalkerForConditionalGeneration(nn.Module):
|
||||
self._tts.base_lm = None
|
||||
del self._tts.residual_lm
|
||||
self._tts.residual_lm = None
|
||||
torch.cuda.empty_cache()
|
||||
torch.accelerator.empty_cache()
|
||||
|
||||
self._inference_timesteps = 10
|
||||
self._cfg_value = 2.0
|
||||
|
||||
+2
-2
@@ -85,7 +85,7 @@ class CUDAGraphAcousticTransformerWrapper:
|
||||
with torch.no_grad():
|
||||
self._forward_cudagraph_compatible(dummy, cfg_alpha=dummy_cfg_alpha, noise=dummy_noise)
|
||||
|
||||
torch.cuda.synchronize(device)
|
||||
torch.accelerator.synchronize(device)
|
||||
|
||||
# Phase 2: Capture graphs
|
||||
for size in self.capture_sizes:
|
||||
@@ -199,7 +199,7 @@ class CUDAGraphAcousticTransformerWrapper:
|
||||
with torch.no_grad():
|
||||
_ = self._forward_cudagraph_compatible(static_input, cfg_alpha=static_cfg_alpha, noise=static_noise)
|
||||
|
||||
torch.cuda.synchronize(device)
|
||||
torch.accelerator.synchronize(device)
|
||||
|
||||
graph = CUDAGraph()
|
||||
with torch.no_grad():
|
||||
|
||||
Reference in new issue
Block a user