Skip to content

Commit 9109e96

Browse files
author
Alex J Lennon
committed
Use torchaudio.load() instead of load_with_torchcodec to avoid C++ abort in DataLoader workers (ROCm)
Made-with: Cursor
1 parent 652142d commit 9109e96

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

training/modules/data_pipeline.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,12 @@ def load_and_process_audio(self, audio_path: Union[str, Path]) -> torch.Tensor:
8282
Returns:
8383
torch.Tensor: Mel spectrogram features, shape (time_frames, n_mels)
8484
"""
85-
# Load audio using the new torchcodec-based approach
86-
waveform, original_sample_rate = torchaudio.load_with_torchcodec(audio_path)
85+
# Load audio (pass str for C++ bindings; Path can cause issues in some builds)
86+
path_str = str(audio_path) if audio_path is not None else ""
87+
if not path_str:
88+
raise ValueError("audio_path is None or empty")
89+
# Use torchaudio.load(); load_with_torchcodec can trigger C++ aborts in DataLoader workers on some setups (e.g. ROCm)
90+
waveform, original_sample_rate = torchaudio.load(path_str)
8791

8892
# Ensure mono audio
8993
if waveform.shape[0] > 1:
@@ -453,7 +457,10 @@ def _process_sample(self, index: int) -> AudioSample:
453457
audio_features = self.audio_processor.waveform_to_mel_features(waveform, sr)
454458
else:
455459
# Process audio features (this loads and processes the audio)
456-
audio_features = self.audio_processor.load_and_process_audio(audio_file)
460+
try:
461+
audio_features = self.audio_processor.load_and_process_audio(audio_file)
462+
except Exception as e:
463+
raise RuntimeError(f"Failed to load audio for {audio_file}: {e}") from e
457464

458465
# Apply normalization according to configuration
459466
audio_features = self.audio_processor.normalize_features(audio_features)

0 commit comments

Comments
 (0)