Skip to content

Silence torch._check_is_size FutureWarning and shim it if torch removes it - #7023

Merged
danielhanchen merged 3 commits into
mainfrom
fix/torch-check-is-size-deprecation
Jul 9, 2026
Merged

danielhanchen merged 3 commits into
mainfrom
fix/torch-check-is-size-deprecation

Conversation

@danielhanchen

Copy link
Copy Markdown
Member

Summary

bitsandbytes 4-bit dequant calls torch._check_is_size(blocksize) (many sites across bitsandbytes/_ops.py and the CUDA/Triton backends). torch deprecated that function, so every gpt-oss and any bnb-4bit load prints:

FutureWarning: _check_is_size will be removed in a future PyTorch release along with guard_size_oblivious. Use _check(i >= 0) instead.

Change

  • Silence that specific FutureWarning in suppress_cuda_printf, next to the other torch and torchao deprecation filters.
  • Add fix_torch_check_is_size(): if a future torch removes torch._check_is_size, shim it to torch._check(i >= 0) (honoring the optional max bound) so bitsandbytes keeps working. It is a no-op while torch still provides the function.

Wired into _gpu_init.py. Only bitsandbytes calls _check_is_size; no unsloth or unsloth_zoo code does.

Tested

On torch 2.11.0 and 2.12.1: the warning no longer prints after import unsloth, and with _check_is_size deleted the shim recreates it, accepts a valid size, rejects a negative size, and honors max.

…es 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.
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

Reviewed commit: 72dabdfdef

ℹ️ 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".

Lead with what the shim does and drop the redundant line; two lines
instead of three, same intent.
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. 🎉

Reviewed commit: 464405c9f2

ℹ️ 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 b509d47 into main Jul 9, 2026
52 of 54 checks passed
@danielhanchen
danielhanchen deleted the fix/torch-check-is-size-deprecation branch July 9, 2026 09:26
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