huggingface/transformers · error · TypeError
Input weight should be of type nn.Parameter, got {type(weigh
Error message
Input weight should be of type nn.Parameter, got {type(weight)} instead What it means
Error "Input weight should be of type nn.Parameter, got {type(weight)} instead" thrown in huggingface/transformers.
Source
Thrown at src/transformers/integrations/bitsandbytes.py:247
if not has_been_replaced:
logger.warning(
"You are loading your model using eetq but no linear modules were found in your model."
" Please double check your model architecture, or submit an issue on github if you think this is"
" a bug."
)
return model
# Copied from PEFT: https://github.com/huggingface/peft/blob/47b3712898539569c02ec5b3ed4a6c36811331a1/src/peft/utils/integrations.py#L41
def dequantize_bnb_weight(weight: "torch.nn.Parameter", state=None):
"""
Helper function to dequantize 4bit or 8bit bnb weights.
If the weight is not a bnb quantized weight, it will be returned as is.
"""
if not isinstance(weight, torch.nn.Parameter):
raise TypeError(f"Input weight should be of type nn.Parameter, got {type(weight)} instead")
cls_name = weight.__class__.__name__
if cls_name not in ("Params4bit", "Int8Params"):
return weight
if cls_name == "Params4bit":
output_tensor = bnb.functional.dequantize_4bit(weight.data, weight.quant_state)
return output_tensor
if state.SCB is None:
state.SCB = weight.SCB
if hasattr(bnb.functional, "int8_vectorwise_dequant"):
# Use bitsandbytes API if available (requires v0.45.0+)
dequantized = bnb.functional.int8_vectorwise_dequant(weight.data, state.SCB)
else:
# Multiply by (scale/127) to dequantize.
dequantized = weight.data * state.SCB.view(-1, 1) * 7.874015718698502e-3View on GitHub (pinned to a597f97485)
Solutions
- Pass an `nn.Parameter` weight to the bitsandbytes layer replacement.
- Wrap plain tensors with `nn.Parameter(tensor)`.
When it happens
Trigger: Raised in bitsandbytes quantization when the weight passed to a quantized linear is not an nn.Parameter.
Common situations: Passing plain tensors to bnb 8-bit/4-bit linear initialization instead of nn.Parameter.
AI-assisted analysis of huggingface/transformers@a597f97485 (2026-08-14).
Data as JSON: /api/errors/8273724bf55a47d3.
Report an issue: GitHub.