Skip to content

Conversation

@NielsRogge
Copy link

@NielsRogge NielsRogge commented Apr 18, 2025

Hi @dbolya, @berniebear and team!

Thanks for making the models available on the hub. This PR improves the 🤗 integration, by making the main class inherit from the PyTorchModelHubMixin class. This was also adopted by your colleagues for the following works:

As well as other popular models:

Benefits:

  • weights are serialized in safetensors format, instead of pickle
  • download stats work
  • the class automatically inhertis the from_pretrained, save_pretrained and push_to_hub methods.

You can push weights to the hub as follows (for example, for https://huggingface.co/facebook/PE-Core-L14-336):

from model import CLIP
from huggingface_hub import hf_hub_download
import torch

# load model
model = CLIP(**model_cfg)

# equip with weights
filepath = hf_hub_download(repo_id="", filename="")
state_dict = torch.load(filepath, map_location="cpu")
model.load_state_dict(state_dict)

# push to the hub
model.push_to_hub("facebook/PE-Core-L14-336")

# now anyone can use it like so:
model = CLIP.from_pretrained("facebook/PE-Core-L14-336")

It would be great if you could try this out, and overwrite the weights of the model repository with the updated ones.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Meta Open Source bot.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants