pytorchcputorchtorchaudio

How to handle "Could not initialize NNPACK! Reason: Unsupported hardware" warning in PyTorch / Silero VAD on cloud CPU?


I’m running Silero VAD (via PyTorch + torchaudio) on a Linode cloud instance (2 dedicated CPUs, 4 GB RAM). When I process 10-minute audio chunks, I always get repeated warnings like this and it doesn't stop at all (logging it forever):

[W915 13:46:29.003463516 NNPACK.cpp:56] Could not initialize NNPACK! Reason: Unsupported hardware.
[W915 13:46:29.010310416 NNPACK.cpp:56] Could not initialize NNPACK! Reason: Unsupported hardware.

Here is the script that I have in jupyter notebook:

import os
import warnings

import torchaudio

os.environ["USE_NNPACK"] = "0"
warnings.filterwarnings("ignore")
torchaudio.set_audio_backend("sox_io")

import torch
from silero_vad import load_silero_vad, read_audio, get_speech_timestamps

torch.backends.nnpack.enabled = False

model = load_silero_vad()

wav = read_audio('./some-audio.wav')

speech_timestamps = get_speech_timestamps(
  wav,
  model,
  return_seconds=True,
)

None of these helped:

torch.backends.nnpack.enabled = False
os.environ["USE_NNPACK"] = "0"

From what I understand:

What is the correct way to disable or bypass NNPACK in PyTorch so Silero VAD runs normally on CPU without printing these warnings?


Solution

  • I encountered the same issue. You can solve it by using a CPU-only version of PyTorch:

    pip uninstall -y torch torchaudio torchcodec
    
    pip install --pre torch torchaudio torchcodec --index-url https://download.pytorch.org/whl/nightly/cpu
    

    Then you can use torch.hub to load the silero-vad model:

    import torch
    
    model, utils = torch.hub.load(repo_or_dir='snakers4/silero-vad', model='silero_vad')
    (get_speech_timestamps, _, read_audio, _, _) = utils
    
    wav = read_audio('path_to_audio_file')
    speech_timestamps = get_speech_timestamps(
      wav,
      model,
      return_seconds=True,  # Return speech timestamps in seconds (default is samples)
    )