Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pretrained Models do not load with pip release #37

Open
paulgavrikov opened this issue Jan 17, 2024 · 6 comments
Open

Pretrained Models do not load with pip release #37

paulgavrikov opened this issue Jan 17, 2024 · 6 comments

Comments

@paulgavrikov
Copy link

I installed the latest version of medclip via pip and am trying to load the pretrained models.
However, when loading ResNet or ViT I get the following error

RuntimeError: Error(s) in loading state_dict for MedCLIPModel:
	Unexpected key(s) in state_dict: "text_model.model.embeddings.position_ids".

It works if I install the module directly from git.

Reproduce:

from medclip import MedCLIPModel, MedCLIPVisionModelViT, MedCLIPVisionModel

model = MedCLIPModel(vision_cls=MedCLIPVisionModel)
model.from_pretrained()
@Weixiang-Sun
Copy link

same problem! Do u find any solution?

@paulgavrikov
Copy link
Author

same problem! Do u find any solution?

Yes, it works if you install directly from this repo pip install git+https://github.com/RyanWangZf/MedCLIP.git

@Spring24ch
Copy link

Why do I use pip install git+https://github.com/RyanWangZf/MedCLIP.git to produce
Uploading 微信图片_20240121232226.png…

@Spring24ch
Copy link

same problem! Do u find any solution?

@EastMage
Copy link

same problem! Do u find any solution?

you may delete this key from the dict using 'del text_encoder_checkpoint["text_model.model.embeddings.position_ids"]'. This is because of the Mismatched transformers version.

@StefanDenn3r
Copy link

A fix would also be to not be strict with loading the models weights.
for that you can just add strict=False in this file:
https://github.com/RyanWangZf/MedCLIP/blob/main/medclip/modeling_medclip.py#L185

StefanDenn3r added a commit to StefanDenn3r/MedCLIP that referenced this issue Apr 12, 2024
The loading of model weights fails due to some transformer version mismatch. 
Relaxing the strictness when loading the weights fixes this issue.

RyanWangZf#37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants