Search code examples
huggingface-transformersgit-lfshuggingface

Huggingface models: how to store a different version of a model


I have a model that I pushed to the remote using the following code:

from transformers import CLIPProcessor, CLIPModel

checkpoint = "./checkpoints-15/checkpoint-60"
    
model = CLIPModel.from_pretrained(checkpoint)
processor = CLIPProcessor.from_pretrained(checkpoint)

repo = "vincentclaes/emoji-predictor"
model.push_to_hub(repo, use_temp_dir=True)
processor.push_to_hub(repo, use_temp_dir=True)

On the UI I see my model under a main branch: enter image description here

What if I want to store multiple versions of a model?

  • Can I create a separate git branch?
  • Can I create a git tag?

How do I do this using the huggingface tools? Thinking transformers, huggingface_hub, ...


Solution

  • If you want to load a specific version or revision of a model from a specific branch, you can use the revision parameter

    here the detail: https://huggingface.co/docs/transformers/main_classes/model#transformers.PreTrainedModel.from_pretrained.revision

    So if you have different branch e.g "v2.0" you can add revision parameter as "v2.0"

    model = CLIPModel.from_pretrained("vincentclaes/emoji-predictor", revision="v2.0")