Skip to content

Forward the model argument through update_weight_conversions overrides (transformers 5.21+) - #16559

Merged
danielhanchen merged 8 commits into
mainfrom
dh/quantizer-update-weight-conversions-model
Nov 4, 2026
Merged

danielhanchen merged 8 commits into
mainfrom
dh/quantizer-update-weight-conversions-model

Conversation

@danielhanchen

@danielhanchen danielhanchen commented Nov 3, 2026 •

Copy link
Copy Markdown
Member

transformers 5.21 changed the quantizer hook to HfQuantizer.update_weight_conversions(self, weight_conversions, model), and conversion_mapping.get_model_conversion_mapping now passes the model on every quantized load. Three Unsloth overrides still took one argument, so on transformers 5.21+ they raise TypeError: ... takes 2 positional arguments but 3 were given:

  • UnslothBnb4BitHfQuantizer (compressed_tensors_bnb.py) and UnslothFp8ToNf4Bnb4BitHfQuantizer (fp8_to_nf4.py):
    • they are registered for bitsandbytes_4bit on the first compressed-tensors or fp8-to-NF4 load, and stay registered;
    • so that load fails, and so does every later bitsandbytes 4-bit load in the same process.
    • A plain 4-bit load in a fresh process is not affected.
  • The Mistral FP8 dequantize wrapper in mistral_format.py.

The current transformers<=5.17.0 pin hides this; anyone on 5.21+ hits it.

Change

Each override now takes (weight_conversions, *args, **kwargs) and passes the extra arguments on to the parent. transformers 5.8 to 5.20, which call the hook with one argument, behave exactly as before.

Three existing tests called the hook with one argument, which is the pre-5.21 contract, so they failed on 5.21+ on main as well. They now call it the way the installed transformers does:

  • test_compressed_tensors_bnb.py::test_the_planner_pass_does_not_consume_the_plan
  • test_compressed_tensors_bnb.py::test_armed_conversions_still_run_a_composed_subclass_hook
  • test_k3_mxfp4_stacked_experts.py::test_a_kept_packed_load_registers_no_decompress_op

Tests

New tests/test_quantizer_update_weight_conversions_model.py (CPU):

main this branch
transformers 5.17 / torch 2.13 2 failed, 1 passed 3 passed
transformers 5.22 / torch 2.15 3 failed (TypeError above) 3 passed

The three updated tests pass on 5.17 and 5.22 with compressed-tensors 0.19 installed.

Real GPU, one Kaggle T4, base vs this branch, one fresh process per arm, Qwen3-0.6B checkpoints:

  • transformers 5.22:
    • the compressed-tensors w4a16 load fails on main with the TypeError and loads and generates on this branch;
    • the bitsandbytes 4-bit load after it also fails on main and works here.
  • Plain 4-bit work on both arms: a pre-quantized bnb-4bit load, generate and a 3-step LoRA SFT (losses 2.3597, 2.3664, 2.1877) give identical results on main and this branch.
  • transformers 5.17: all 9 phases are identical on both arms.

Not covered

  • The armed fp8-to-NF4 path on GPU; it is covered by CPU checks only.
  • A full Mistral-format FP8 load.
  • transformers 5.18 to 5.21 were not run; their hook signatures were read from the released wheels.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-03T16:55:29.456772Z 27e41a3 Manual request
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

[skip ci]
@danielhanchen

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: f1b330d123

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

Copy link
Copy Markdown
Member Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Can't wait for the next one!

Reviewed commit: 27e41a3ec5

ℹ️ 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 ca762a0 into main Nov 4, 2026
@danielhanchen
danielhanchen deleted the dh/quantizer-update-weight-conversions-model branch November 4, 2026 11:00
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