Skip to content

Instantly share code, notes, and snippets.

@madebyollin
Created May 17, 2026 18:07
Show Gist options
  • Select an option

  • Save madebyollin/d3df5ecde967b3fd56d6841542f133a1 to your computer and use it in GitHub Desktop.

Select an option

Save madebyollin/d3df5ecde967b3fd56d6841542f133a1 to your computer and use it in GitHub Desktop.
Suppressing NNPACK.cpp:57 Could not initialize NNPACK! Reason: Unsupported hardware.

Problem

If you run pytorch ops on CPU you may get spammed with this extremely annoying warning about NNPack:

#!/usr/bin/env python3
import torch as th
import torch.nn as nn
conv = nn.Conv2d(3, 3, 3)
# cpu forward here will spam an nnpack warning
for i in range(10):
    x = conv(th.ones(1, 3, 3, 3))
./nnpack_repro.py
[W517 18:02:54.644240235 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.650463229 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.650796375 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.651290323 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.651739820 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.652140107 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.652370471 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.652827388 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.653462109 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.
[W517 18:02:54.653915717 NNPACK.cpp:57] Could not initialize NNPACK! Reason: Unsupported hardware.

This warning is emitted by C++ code so you can't suppress it with warnings or any usual python method.

Fix

The fix is to tell PyTorch to disable NNPack entirely:

import torch as th
th.backends.nnpack.set_flags(False)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment