wave2vec OOM while doing inference
See original GitHub issue❓ Questions and Help
Before asking:
- search the issues. yes
- search the docs. yes
What is your question?
When I’m trying to do inference on a audio of length of around 52 sec , I’m getting this error RuntimeError: [enforce fail at CPUAllocator.cpp:65] . DefaultCPUAllocator: can't allocate memory: you tried to allocate 326730288 bytes. Error code 12 (Cannot allocate memory)
the inference is going to take almost 326.730288 MB. And when I ran
free -h
I’m having this much of free space.
sh-4.2$ free -h
total used free shared buffers cached
Mem: 7.7G 977M 6.7G 0B 90M 384M
-/+ buffers/cache: 502M 7.2G
Swap: 3.0G 290M 2.7G
Would you please help me regarding this issue. @patrickvonplaten .
code
import soundfile as sf
import librosa
import torch
from transformers import Wav2Vec2ForCTC, Wav2Vec2Tokenizer
tokenizer = Wav2Vec2Tokenizer.from_pretrained("facebook/wav2vec2-base-960h")
model = Wav2Vec2ForCTC.from_pretrained("facebook/wav2vec2-base-960h")
input_audio, _ = librosa.load(filename,
sr=16000)
input_values = tokenizer(input_audio, return_tensors="pt").input_values
logits = model(input_values).logits
predicted_ids = torch.argmax(logits, dim=-1)
text = tokenizer.batch_decode(predicted_ids)[0]
sample audio file in wave format
https://github.com/abhinavsp0730/video-to-text-ap/blob/main/sample_audio_1.wav
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (2 by maintainers)
Top Results From Across the Web
wave2vec OOM while doing inference · Issue #3359 - GitHub
When I'm trying to do inference on a audio of length of around 52 sec , I'm getting this error ... wave2vec OOM...
Read more >Wav2vec2.0 memory issue - Models - Hugging Face Forums
When I take a subset (100 sound) and fine-tune on this subset, everything is fine. What could be the problem? Is there any...
Read more >Inference with Wav2vec 2.0 - Medium
In this post we'll show you how to perform inference with wav2vec 2.0 to speed up processing times when using speech processing models....
Read more >Shrinking Bigfoot: Reducing wav2vec 2.0 footprint - arXiv Vanity
Hence, the inference latency of wav2vec 2.0 will be a bottleneck in production, leading to high costs and a significant environmental footprint.
Read more >arXiv:2103.15760v2 [cs.CL] 1 Apr 2021
Our distilled student model has a faster inference speed and makes wav2vec 2.0 more cost-efficient and environmentally friendly. 2. Related work.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @olafthiele - make sure wrap your code into a
with torch.no_grad():
to same memory. This snippet should work:Thanks, @patrickvonplaten for the help I’m closing this issue as it has been resolved.