Skip to content

Conversation

@NielsRogge
Copy link

@NielsRogge NielsRogge commented Jun 30, 2025

This PR showcases the PyTorchModelHubMixin class which you could use to push and reload the AllTracker models to and from the hub.

Here's the model: https://huggingface.co/nielsr/alltracker.

Usage is as follows:

from nets.net34 import Net

model = Net.from_pretrained("nielsr/alltracker")

Benefits:

  • download stats work
  • the weights are serialized in the safetensors format (along with a config.json)
  • you can tweak the model card, but there's a default one
  • each checkpoint gets pushed to a separate model repository (best practice).

Here's the script I used to push one particular checkpoint:

from nets.net34 import Net
from huggingface_hub import hf_hub_download
import torch

model = Net(seqlen=16)
    
# equip the model with the weights from the hub
filepath = hf_hub_download(repo_id="aharley/alltracker", filename="alltracker_tiny.pth")
state_dict = torch.load(filepath, map_location="cpu")["model"]
model.load_state_dict(state_dict)

# push the model to the hub
model.push_to_hub("nielsr/alltracker-tiny")

# load the model from the hub
model = Net.from_pretrained("nielsr/alltracker-tiny")

@aharley
Copy link
Owner

aharley commented Jun 30, 2025

This is nice, but I will want to use the model from here:
https://huggingface.co/aharley/alltracker/

@NielsRogge
Copy link
Author

NielsRogge commented Jul 1, 2025

Ok, in that case you could add a from_pretrained method like this one: https://huggingface.co/docs/huggingface_hub/guides/integrations#frompretrained. It can do the following behind the scenes:

from huggingface_hub import hf_hub_download

filepath = hf_hub_download(repo_id="aharley/alltracker", filename="alltracker.pth")

Would you be able to integrate this yourself or would you like me to open a PR?

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

Successfully merging this pull request may close these issues.

2 participants