Skip to content

caching_allocator_warmup crashes with AttributeError when loading bitsandbytes-quantized model with PEFT adapter #47914

Description

@LiaoBill

System Info

  • transformers version: 5.1.0
  • Platform: Windows-11-10.0.26200-SP0
  • Python version: 3.12.11
  • Huggingface_hub version: 1.27.0
  • Safetensors version: 0.8.0
  • Accelerate version: 1.14.0
  • Accelerate config: not found
  • DeepSpeed version: not installed
  • PyTorch version (GPU?): 2.5.1+cu124 (True)
  • Tensorflow version (GPU?): not installed (NA)
  • Flax version (CPU?/GPU?/TPU?): not installed (NA)
  • Jax version: not installed
  • JaxLib version: not installed
  • bitsandbytes version: 0.50.0

Who can help?

@SunMarc @MekkCyber

Information

  • The official example scripts
  • My own modified scripts

Tasks

  • An officially supported task in the examples folder (such as GLUE/SQuAD, ...)
  • My own task or dataset (give details below)

Reproduction

from transformers import AutoModelForCausalLM, BitsAndBytesConfig
from peft import PeftModel

quant_config = BitsAndBytesConfig(load_in_8bit=True)
base_model = AutoModelForCausalLM.from_pretrained(
    "meta-llama/Meta-Llama-3-8B-Instruct",
    quantization_config=quant_config,
    device_map="auto",
)
# Next call triggers _load_pretrained_model again via load_adapter
model = PeftModel.from_pretrained(base_model, "some-peft-adapter")

Traceback:

File "transformers/modeling_utils.py", line 4677, in caching_allocator_warmup
    total_byte_count = get_total_byte_count(model, accelerator_device_map, hf_quantizer)
File "transformers/modeling_utils.py", line 4634, in get_total_byte_count
    param = model.get_parameter_or_buffer(param_name)
File "transformers/modeling_utils.py", line 4550, in get_parameter_or_buffer
    raise AttributeError(f"`{target}` is neither a parameter, buffer, nor extra state.")
AttributeError: `layers.0.self_attn.q_proj.base_layer.SCB` is neither a parameter, buffer, nor extra state.

Expected behavior

A clear and concise description of what you would expect to happen:
Loading a PEFT adapter on top of a bitsandbytes-quantized model should succeed.

Now, caching_allocator_warmup (introduced in 5.x) crashes because expanded_device_map includes entries like layers.0.self_attn.q_proj.base_layer.SCB, which are bitsandbytes internal tensors stored as plain Python attributes on Int8Params (not registered via register_parameter()/register_buffer()), so get_parameter_or_buffer() cannot find them.

caching_allocator_warmup already exempts HQQ and Quark by skipping the warmup entirely for those quantization methods, but BITS_AND_BYTES is missing from that exemption list, I add that to the list fix the problem #47919

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions