Silence third-party deprecation warnings and fix socket leak#3983
Conversation
- 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
for more information, see https://pre-commit.ci
Summary of ChangesHello @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
🧠 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
Activity
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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.
| ) | ||
| warnings.filterwarnings( | ||
| "ignore", | ||
| message = r"Importing BlockSparseLayout from torchao\.dtypes is deprecated", |
| sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | ||
| try: | ||
| sock.connect((host, port)) | ||
| return True | ||
| finally: | ||
| sock.close() |
There was a problem hiding this comment.
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…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>
Summary
has_internet()Changes
unsloth/import_fixes.pyAdded warning filters for:
TorchAO deprecated import paths - These warnings appear because torchao is moving imports from
torchao.dtypes.*totorchao.prototype.dtypes.*. Reference: Migrating from AffineQuantizedTensor + Layouts to new structure of tensor subclasses pytorch/ao#2752SWIG builtin type warnings -
builtin type SwigPyPacked/SwigPyObject has no __module__ attributewarnings from bitsandbytes/triton SWIG bindingsTriton autotuner deprecation -
warmup, rep, and use_cuda_graph parameters are deprecated. Reference: [AUTOTUNER] Make autotuner takedo_benchas a parameter triton-lang/triton#4496Python 3.12+ multiprocessing fork warnings -
multi-threaded, use of fork() may lead to deadlockswarnings that appear when using PyTorch data loadersResource warnings - Filter unclosed socket/file warnings from internal operations
unsloth/models/_utils.pyFixed socket resource leak in
has_internet()function. The socket was being created but never explicitly closed, which triggeredResourceWarningon Python 3.12+.Test Plan
has_internet()still works correctly after socket fix