Fix transformers 5.2.0 transpose conversion issue#1475
Merged
Conversation
Signed-off-by: lvliang-intel <liang1.lv@intel.com>
for more information, see https://pre-commit.ci
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a compatibility monkey-patch to auto_round to prevent failures when loading quantized MoE checkpoints with transformers==5.2.0+, where a new transpose conversion path incorrectly assumes weights are nn.Parameter rather than buffers.
Changes:
- Introduce
_patch_transpose_for_buffers()to wraptransformers.core_model_loading.Transpose.convert()and bypass transpose logic for buffer-backed tensors. - Apply the patch from
monkey_patch_transformers()fortransformers >= 5.2.0.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
xin3he
approved these changes
Mar 2, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Root cause
In transformers 5.2.0, the new Transpose conversion class calls get_parameter() on weight tensors during quantized MoE checkpoint loading. auto_round's QuantLinear stores weight_packed and weight_scale as buffers (via register_buffer()), not nn.Parameter, so get_parameter() raises an AttributeError, which transformers then raises as a RuntimeError.
Fix
A _patch_transpose_for_buffers() monkey-patch wraps Transpose.convert() to check if the target tensor is a buffer first — if so, it returns the tensor as-is instead of attempting a transpose. This patch is applied in monkey_patch_transformers() for transformers ≥ 5.2.0.
Type of Change
Related Issues
Fixes or relates to #
Checklist Before Submitting