Skip to content

Silence third-party deprecation warnings and fix socket leak#3983

Merged
danielhanchen merged 2 commits into
mainfrom
silence-deprecation-warnings
Feb 5, 2026
Merged

Silence third-party deprecation warnings and fix socket leak#3983
danielhanchen merged 2 commits into
mainfrom
silence-deprecation-warnings

Conversation

@danielhanchen
Copy link
Copy Markdown
Member

Summary

  • Silence deprecation warnings from third-party libraries that clutter training output
  • Fix a minor socket resource leak in has_internet()

Changes

unsloth/import_fixes.py

Added warning filters for:

  1. TorchAO deprecated import paths - These warnings appear because torchao is moving imports from torchao.dtypes.* to torchao.prototype.dtypes.*. Reference: Migrating from AffineQuantizedTensor + Layouts to new structure of tensor subclasses pytorch/ao#2752

  2. SWIG builtin type warnings - builtin type SwigPyPacked/SwigPyObject has no __module__ attribute warnings from bitsandbytes/triton SWIG bindings

  3. Triton autotuner deprecation - warmup, rep, and use_cuda_graph parameters are deprecated. Reference: [AUTOTUNER] Make autotuner take do_bench as a parameter triton-lang/triton#4496

  4. Python 3.12+ multiprocessing fork warnings - multi-threaded, use of fork() may lead to deadlocks warnings that appear when using PyTorch data loaders

  5. Resource warnings - Filter unclosed socket/file warnings from internal operations

unsloth/models/_utils.py

Fixed socket resource leak in has_internet() function. The socket was being created but never explicitly closed, which triggered ResourceWarning on Python 3.12+.

Test Plan

  • Ran GPT-OSS 20B RL notebook with warning logging enabled
  • Verified all 10 unique warnings are now silenced
  • Confirmed has_internet() still works correctly after socket fix

danielhanchen and others added 2 commits February 5, 2026 12:52
- Add warning filters for TorchAO deprecated import paths
- Filter SWIG builtin type warnings from bitsandbytes/triton
- Filter Triton autotuner deprecation warnings
- Filter Python 3.12+ multiprocessing fork warnings
- Filter resource warnings for unclosed sockets/files
- Fix socket leak in has_internet() by properly closing socket
@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @danielhanchen, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request focuses on improving the user experience by reducing extraneous output and enhancing resource management. It introduces mechanisms to silence common deprecation and resource warnings originating from external dependencies and internal utility functions, thereby providing a cleaner console output and preventing potential resource exhaustion issues.

Highlights

  • Warning Silencing: Implemented new warning filters to suppress deprecation messages from various third-party libraries, including TorchAO, SWIG bindings (bitsandbytes/triton), Triton autotuner, and Python 3.12+ multiprocessing fork warnings. This aims to reduce output clutter during training.
  • Resource Leak Fix: Addressed a minor socket resource leak within the has_internet() function by ensuring the socket is explicitly closed, preventing ResourceWarning messages, especially on Python 3.12+.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Changelog
  • unsloth/import_fixes.py
    • Added warning filters for TorchAO deprecated import paths.
    • Added warning filters for SWIG builtin type warnings from bitsandbytes/triton.
    • Added warning filters for Triton autotuner deprecation messages.
    • Added warning filters for Python 3.12+ multiprocessing fork warnings.
    • Added warning filters for unclosed socket and file resource warnings.
  • unsloth/models/_utils.py
    • Modified the has_internet() function to explicitly close the created socket using a finally block, resolving a resource leak.
Activity
  • The pull request was created by danielhanchen.
  • No human activity (comments, reviews) has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

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

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 effectively silences several third-party deprecation warnings and correctly fixes a socket resource leak, improving the overall developer experience. The changes are clear and well-documented. I have a couple of suggestions to further refine the code by removing a redundant warning filter and adopting a more idiomatic approach for resource management.

Comment thread unsloth/import_fixes.py
Comment on lines +131 to +134
)
warnings.filterwarnings(
"ignore",
message = r"Importing BlockSparseLayout from torchao\.dtypes is deprecated",
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

This warning filter is redundant. The more general filter on lines 127-130 (r"Importing.*from torchao\.dtypes.*is deprecated") already covers this specific case. Removing this will make the code slightly cleaner.

Comment thread unsloth/models/_utils.py
Comment on lines +1155 to +1160
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect((host, port))
return True
finally:
sock.close()
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

While the try...finally block correctly closes the socket, you can make this code more idiomatic and concise by using a with statement. Sockets support the context manager protocol, which automatically handles closing the resource, even if errors occur.

        with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as sock:
            sock.connect((host, port))
            return True

@danielhanchen danielhanchen merged commit f15452a into main Feb 5, 2026
4 checks passed
@danielhanchen danielhanchen deleted the silence-deprecation-warnings branch February 5, 2026 12:55
abiswas-realadvice pushed a commit to abiswas-realadvice/unsloth that referenced this pull request May 14, 2026
…ai#3983)

* Silence third-party deprecation warnings and fix socket resource leak

- Add warning filters for TorchAO deprecated import paths
- Filter SWIG builtin type warnings from bitsandbytes/triton
- Filter Triton autotuner deprecation warnings
- Filter Python 3.12+ multiprocessing fork warnings
- Filter resource warnings for unclosed sockets/files
- Fix socket leak in has_internet() by properly closing socket

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
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