Skip to content

Silence torchao _C*.so load-failure WARNING on torch >= 2.11 - #6712

Merged
danielhanchen merged 1 commit into
mainfrom
silence-torchao-so-load-warning
Jun 27, 2026
Merged

danielhanchen merged 1 commit into
mainfrom
silence-torchao-so-load-warning

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

Silences the cosmetic per-file torchao WARNING that shows up on torch >= 2.11:

WARNING:torchao:Failed to load .../torchao/_C_mxfp8.cpython-310-x86_64-linux-gnu.so: Could not load this library: ...
WARNING:torchao:Failed to load .../torchao/_C_cutlass_90a.abi3.so: Could not load this library: ...

This was reported when running the Llama3.2 (1B and 3B) Conversational Colab notebook on a T4.

Why it happens

On torch >= 2.11, torchao/__init__.py stops taking the "Skipping import of cpp extensions" branch and instead dlopens each prebuilt _C*.so, logging Failed to load <path>/_C*.so: <error> per file that fails. The failures are expected here:

  • ABI tag mismatch in the prebuilt wheel, for example a cp310 .so loaded under a cp312 runtime (the Colab case).
  • Arch-specific kernels the GPU does not have. _C_mxfp8 needs FP8 hardware and _C_cutlass_90a is Hopper / SM90 only, so neither is usable on a T4.

In all cases torchao falls back to its non-cpp paths, and Unsloth's bnb-4bit / Triton kernels do not use these extensions, so the warning is purely cosmetic.

Fix

import_fixes.py already filters the sibling torch < 2.11 message (Skipping import of cpp extensions) on the torchao logger. The Failed to load ... warning comes from that same torchao logger, so this adds one more HideLoggingMessage filter next to it:

logging.getLogger("torchao").addFilter(HideLoggingMessage("Failed to load "))

This drops only those records rather than raising the whole logger to ERROR, and it stays under the existing if not UNSLOTH_ENABLE_LOGGING: guard, so UNSLOTH_ENABLE_LOGGING=1 still surfaces everything.

Testing

  • import_fixes.py parses via ast.parse and byte-compiles via py_compile.
  • Feeding the exact Colab messages through the torchao logger confirms both Failed to load .../_C*.so records are suppressed, the existing Skipping import of cpp extensions record stays suppressed, and an unrelated torchao warning still passes through.

On torch >= 2.11 torchao tries to dlopen each prebuilt _C*.so and logs a
per-file "Failed to load .../_C*.so" WARNING via the torchao logger when one
cannot load. This happens on an ABI tag mismatch in the prebuilt wheel (for
example a cp310 .so under a cp312 runtime, as on Colab) or when the kernel
targets an arch the GPU does not have (mxfp8 needs FP8 hardware, _C_cutlass_90a
is Hopper/SM90 only). torchao falls back to its non-cpp paths and Unsloth's
bnb-4bit / Triton kernels do not use these, so the warning is cosmetic.

Add a HideLoggingMessage filter on the same torchao logger that already filters
the torch < 2.11 "Skipping import of cpp extensions" message, so only these
records are dropped rather than raising the whole logger to ERROR.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request adds a log filter to suppress cosmetic "Failed to load" warnings from the torchao logger when prebuilt shared libraries fail to load. The reviewer pointed out that the current filter is too broad and could suppress critical error messages, suggesting a more specific filter that checks for both "Failed to load" and ".so" in the log message.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread unsloth/import_fixes.py
# .../_C*.so" when one can't (ABI tag mismatch in the wheel, e.g. a cp310 .so under a
# cp312 runtime on Colab, or an arch-specific kernel the GPU lacks). It falls back to
# non-cpp paths and Unsloth doesn't use these kernels, so drop the cosmetic record.
logging.getLogger("torchao").addFilter(HideLoggingMessage("Failed to load "))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Filtering out any log message containing "Failed to load " is overly broad and could accidentally suppress critical error messages from torchao (such as failing to load a model, config, or weights). Since the cosmetic warnings always refer to shared library (.so) files, we should make the filter more specific by ensuring it only suppresses messages that contain both "Failed to load" and ".so".

Suggested change
logging.getLogger("torchao").addFilter(HideLoggingMessage("Failed to load "))
logging.getLogger("torchao").addFilter(
lambda record: not ("Failed to load" in record.getMessage() and ".so" in record.getMessage())
)

@danielhanchen
danielhanchen merged commit 101de19 into main Jun 27, 2026
60 of 62 checks passed
@danielhanchen
danielhanchen deleted the silence-torchao-so-load-warning branch June 27, 2026 02:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant