Loading audio file with torchaudio fails (memory crash)
Open
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 2.9k
- Forks
- 799
- Avg merge
- 58m
- Merged PRs (30d)
- 3
Description
🐛 Describe the bug
When I try to load a 43-second .wav file, the memory consumption increases, which causes the session to crash. I have about 12GB of RAM.
This is the piece of code that I have
from transformers import ClapProcessor, ClapModel
import torchaudio
import torch
# Setup device
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
# Load CLAP model and processor
model = ClapModel.from_pretrained("laion/clap-htsat-unfused").to(device)
processor = ClapProcessor.from_pretrained("laion/clap-htsat-unfused")
# Load audio file
audio, sr = torchaudio.load("/content/temp_audio_6169.wav")
# Resample to 48kHz if needed
if sr != 48000:
audio = torchaudio.transforms.Resample(sr, 48000)(audio)
# Convert stereo to mono
if audio.shape[0] > 1:
audio = audio.mean(dim=0)
# Limit to 10 seconds (CLAP expects max 480000 samples at 48kHz)
audio = audio[:480000]
# Process audio
inputs = processor(audios=audio, sampling_rate=48000, return_tensors="pt")
inputs = {k: v.to(device) for k, v in inputs.items()} # Move to GPU
# Extract audio embedding
with torch.no_grad():
audio_embedding = model.get_audio_features(**inputs)
print(":loud_sound: Audio embedding shape:", audio_embedding.shape)
audio file
temp_audio_6169.zip
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the report with the attached WAV file and the provided Python snippet. Measure memory after torchaudio.load, resampling, processor(), and get_audio_features() to identify where the crash occurs; done means the cause and a reproducible fix or confirmed expected behavior are documented.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, pytorch
- Domain
- audio-video-rtc, machine-learning
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100