Remove timm backbone weight loading to prevent meta-tensor warnings in from_pretrained#42284
Remove timm backbone weight loading to prevent meta-tensor warnings in from_pretrained#42284HichTala wants to merge 11 commits intohuggingface:mainfrom
from_pretrained#42284Conversation
…h `from_pretrained` method of `PreTrainedModel` to make sure weights get loaded after the model is initialized
|
Hey @HichTala! Are you sure you are still facing the original issue in latest |
|
Hi @Cyrilvallez! I just tested this again with the latest The problem is not related to This PR simply removes loading the |
|
I see... Then this config switch should be hardcoded in all model config when this can happen, not in the general loading code! Do you want to make the change? |
|
Yep totally agree with that, I'm making the change! |
…figuration and ensure it is disabled when using timm backbone
|
[For maintainers] Suggested jobs to run (before merge) run-slow: conditional_detr, dab_detr, deformable_detr, detr, table_transformer |
|
Hi, sorry for the delay, I completely forgot about this PR. Here are the updates |
|
Hey! I believe this PR is superseded by #43323 |
|
Ok cool I'm closing this then |
|
superseded by #43323 |
What does this PR do?
This pull request makes a targeted change to the model loading logic in
modeling_utils.pyto improve compatibility with timm backbones. Specifically, it ensures that when a model is configured to use a timm backbone with pretrained weights (use_pretrained_backbone=True), the backbone weights are not loaded while the model is still inmetadevice duringfrom_pretrained().Model initialization and configuration:
from_pretrained, before model instantiation, if the config specifies bothuse_timm_backboneanduse_pretrained_backbone, the code setsconfig.use_pretrained_backbonetoFalseto defer loading pretrained timm backbone weights until after initialization.Fixes # (issue)
Before submitting
Pull Request section?
to it if that's the case.
documentation guidelines, and
here are tips on formatting docstrings.
Who can review?
@Rocketknight1 @qubvel @Cyrilvallez @NielsRogge @xenova