Silence third-party deprecation warnings and fix socket leak (#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>
This commit is contained in:
parent
0166c6266d
commit
5117baaf60
2 changed files with 47 additions and 2 deletions
|
|
@ -123,6 +123,47 @@ if os.environ.get("UNSLOTH_ENABLE_LOGGING", "0") != "1":
|
|||
warnings.filterwarnings("ignore", message = "`int4_weight_only` is deprecated")
|
||||
warnings.filterwarnings("ignore", message = "`int8_weight_only` is deprecated")
|
||||
|
||||
# TorchAO deprecated import paths (https://github.com/pytorch/ao/issues/2752)
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message = r"Importing.*from torchao\.dtypes.*is deprecated",
|
||||
category = DeprecationWarning,
|
||||
)
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message = r"Importing BlockSparseLayout from torchao\.dtypes is deprecated",
|
||||
category = DeprecationWarning,
|
||||
)
|
||||
|
||||
# SWIG builtin type warnings (from bitsandbytes/triton SWIG bindings)
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message = r"builtin type Swig.*has no __module__ attribute",
|
||||
category = DeprecationWarning,
|
||||
)
|
||||
|
||||
# Triton autotuner deprecation (https://github.com/triton-lang/triton/pull/4496)
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message = r"warmup, rep, and use_cuda_graph parameters are deprecated",
|
||||
category = DeprecationWarning,
|
||||
)
|
||||
|
||||
# Python 3.12+ multiprocessing fork warning in multi-threaded processes
|
||||
warnings.filterwarnings(
|
||||
"ignore",
|
||||
message = r".*multi-threaded.*use of fork\(\) may lead to deadlocks",
|
||||
category = DeprecationWarning,
|
||||
)
|
||||
|
||||
# Resource warnings from internal socket/file operations
|
||||
warnings.filterwarnings(
|
||||
"ignore", message = r"unclosed.*socket", category = ResourceWarning
|
||||
)
|
||||
warnings.filterwarnings(
|
||||
"ignore", message = r"unclosed file.*dev/null", category = ResourceWarning
|
||||
)
|
||||
|
||||
|
||||
# Fix up AttributeError: 'MessageFactory' object has no attribute 'GetPrototype'
|
||||
# MUST do this at the start primarily due to tensorflow causing issues
|
||||
|
|
|
|||
|
|
@ -1152,8 +1152,12 @@ def has_internet(host = "8.8.8.8", port = 53, timeout = 3):
|
|||
return False
|
||||
try:
|
||||
socket.setdefaulttimeout(timeout)
|
||||
socket.socket(socket.AF_INET, socket.SOCK_STREAM).connect((host, port))
|
||||
return True
|
||||
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
sock.connect((host, port))
|
||||
return True
|
||||
finally:
|
||||
sock.close()
|
||||
except socket.error as ex:
|
||||
return False
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue