mirror of
https://github.com/unslothai/unsloth.git
synced 2026-07-09 15:58:41 +00:00
Silence torch._check_is_size FutureWarning and shim it if torch removes it (#7023)
* Silence torch._check_is_size FutureWarning and shim it if torch removes it
bitsandbytes 4-bit dequant calls torch._check_is_size, which torch
deprecated with a FutureWarning ("Use _check(i >= 0) instead") that prints
on every bnb-4bit load. Silence that warning in suppress_cuda_printf, and
add fix_torch_check_is_size so a future torch that removes _check_is_size
gets it shimmed to _check(i >= 0) (honoring the max bound) and bitsandbytes
keeps working.
* [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
* Tighten fix_torch_check_is_size docstring
Lead with what the shim does and drop the redundant line; two lines
instead of three, same intent.
---------
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
parent
0d4bd50768
commit
b509d47dd7
2 changed files with 31 additions and 0 deletions
|
|
@ -26,6 +26,7 @@ already_imported = [mod for mod in critical_modules if mod in sys.modules]
|
|||
# Fix some issues before importing other packages
|
||||
from .import_fixes import (
|
||||
fix_message_factory_issue,
|
||||
fix_torch_check_is_size,
|
||||
check_fbgemm_gpu_version,
|
||||
disable_broken_causal_conv1d,
|
||||
disable_broken_vllm,
|
||||
|
|
@ -72,6 +73,7 @@ fix_bitsandbytes_rocm_arch_detection()
|
|||
disable_broken_causal_conv1d()
|
||||
disable_broken_vllm()
|
||||
fix_message_factory_issue()
|
||||
fix_torch_check_is_size()
|
||||
check_fbgemm_gpu_version()
|
||||
torchvision_compatibility_check()
|
||||
fix_diffusers_warnings()
|
||||
|
|
@ -81,6 +83,7 @@ del fix_bitsandbytes_rocm_arch_detection
|
|||
del disable_broken_causal_conv1d
|
||||
del disable_broken_vllm
|
||||
del fix_message_factory_issue
|
||||
del fix_torch_check_is_size
|
||||
del check_fbgemm_gpu_version
|
||||
del torchvision_compatibility_check
|
||||
del fix_diffusers_warnings
|
||||
|
|
|
|||
|
|
@ -172,6 +172,10 @@ if not UNSLOTH_ENABLE_LOGGING:
|
|||
# Deprecation warnings from torchao
|
||||
warnings.filterwarnings("ignore", message = "`int4_weight_only` is deprecated")
|
||||
warnings.filterwarnings("ignore", message = "`int8_weight_only` is deprecated")
|
||||
# torch._check_is_size FutureWarning (called by bitsandbytes 4-bit dequant)
|
||||
warnings.filterwarnings(
|
||||
"ignore", message = r"_check_is_size will be removed", category = FutureWarning
|
||||
)
|
||||
|
||||
# TorchAO deprecated import paths (https://github.com/pytorch/ao/issues/2752)
|
||||
warnings.filterwarnings(
|
||||
|
|
@ -253,6 +257,30 @@ if not UNSLOTH_ENABLE_LOGGING:
|
|||
)
|
||||
|
||||
|
||||
def fix_torch_check_is_size():
|
||||
"""Shim torch._check_is_size if a future torch removes it (bitsandbytes 4-bit
|
||||
dequant calls it). The FutureWarning is silenced in suppress_cuda_printf."""
|
||||
try:
|
||||
import torch
|
||||
|
||||
if hasattr(torch, "_check_is_size"):
|
||||
return
|
||||
|
||||
def _check_is_size(
|
||||
i,
|
||||
message = None,
|
||||
*,
|
||||
max = None,
|
||||
):
|
||||
torch._check(i >= 0, message)
|
||||
if max is not None:
|
||||
torch._check(i <= max, message)
|
||||
|
||||
torch._check_is_size = _check_is_size
|
||||
except Exception:
|
||||
return
|
||||
|
||||
|
||||
# Fix up AttributeError: 'MessageFactory' object has no attribute 'GetPrototype'
|
||||
# MUST do this at the start primarily due to tensorflow causing issues
|
||||
def fix_message_factory_issue():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue