Skip to content

Suppress only torchao's cosmetic cpp-extensions warning - #6506

Merged
danielhanchen merged 2 commits into
mainfrom
torchao-cpp-message-surgical-filter
Jun 22, 2026
Merged

danielhanchen merged 2 commits into
mainfrom
torchao-cpp-message-surgical-filter

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

On torch < 2.11, importing torchao prints a cosmetic WARNING:

Skipping import of cpp extensions due to incompatible torch version. Please upgrade to torch >= 2.11.0 (found 2.9.1+cu128).

It is emitted from torchao/__init__.py via logging.getLogger("torchao").warning(...). The bnb-4bit and Unsloth paths do not use torchao's cpp kernels, so this is just log noise.

The quiet block in unsloth/import_fixes.py already targeted this message, but did so with:

logging.getLogger("torchao").setLevel(logging.ERROR)
sys.stderr.add_filter("Skipping import of cpp extensions")

setLevel(logging.ERROR) is a blanket suppressor: it also hides any genuine torchao WARNING (for example a real kernel-load failure), and the stderr substring filter is a redundant second channel that would also match the unrelated TORCHAO_FORCE_SKIP_LOADING_SO_FILES message.

This swaps both for a single HideLoggingMessage logging filter (the same helper already used for the HF_TOKEN message) scoped to the torchao logger, dropping only this one record while every other torchao log passes through.

Verified

  • torch 2.9.1 + torchao 0.17.0: message gone; torchao still imports and works; an unrelated torchao warning still appears.
  • torch >= 2.11: no-op (torchao never emits the message).
  • torchao not installed: no-op (filter registered on an unused logger; nothing imported).
  • Idempotent and platform independent (pure logging).

torchao logs a cosmetic WARNING on torch < 2.11 from torchao/__init__.py
(logger.warning("Skipping import of cpp extensions due to incompatible
torch version...")). The bnb-4bit and Unsloth paths do not use torchao's
cpp kernels, so the message is noise.

The quiet block raised the whole torchao logger to ERROR, which also hid
any genuine torchao warning, plus a redundant stderr substring filter.
Replace both with a HideLoggingMessage logging filter scoped to the
torchao logger that drops only this one record, leaving every other
torchao log intact.

@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 refactors how torchao warnings are suppressed in unsloth/import_fixes.py. Instead of setting the entire torchao logger level to ERROR and filtering stderr, it adds a specific HideLoggingMessage filter to the torchao logger to only suppress the cosmetic warning about incompatible torch versions for cpp extensions, preserving other logs. There are no review comments, so I have no feedback to provide.

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.

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: a1b7a6ac01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. You're on a roll.

Reviewed commit: a1b7a6ac01

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@danielhanchen
danielhanchen merged commit ad2546e into main Jun 22, 2026
41 of 43 checks passed
@danielhanchen
danielhanchen deleted the torchao-cpp-message-surgical-filter branch June 22, 2026 09:28
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.

2 participants