Fix CLIP _init_weights when a child module carries quantized weights (#47921)
* Fix _init_weights on CLIP models whose children carry quantized weights `CLIPPreTrainedModel._init_weights` initializes the parameters of child modules by name (`module.q_proj.weight`, `module.fc1.weight`, ...). A quantized checkpoint replaces `weight` on those children with packed tensors -- `weight_packed` for compressed-tensors, `qweight` for GPTQ/AWQ -- so loading one raises `AttributeError: 'Linear' object has no attribute 'weight'` from the init pass that `from_pretrained` runs for the keys that are missing from the checkpoint. Route every child-weight initialization through a helper that skips a child that has no `weight`, mirroring the guard the generic `PreTrainedModel._init_weights` already applies to `nn.Linear`. Initialization of a non-quantized model is unchanged. MetaCLIP-2 inlines this method through modular, so its modeling file is regenerated. * Update src/transformers/models/clip/modeling_clip.py * Update src/transformers/models/metaclip_2/modeling_metaclip_2.py * Apply ruff format to the edited docstring and regenerate MetaCLIP-2 --------- Co-authored-by: Matt <Rocketknight1@users.noreply.github.com>
S
SMG committed
13190137d607632ad687486ccd714ef8ea01dbfa
Parent: 463f684
Committed by GitHub <noreply@github.com>
on 8/14/2026, 12:16:33 PM