facebookresearch / facebookresearch/sonata

Improve Hugging Face integration

Open
#3 3 comments 1 reaction 0 assignees View on GitHub
Dominant language
Python
Stars
795
Forks
56
PR merge metrics
No merged PRs in 30d

Description

Hi @Gofinge,

Thanks for publishing the model on 🤗 : https://huggingface.co/facebook/sonata.

However, I noticed the integration with Hugging Face could be improved by leveraging the [PyTorchModelHubMixin](https://huggingface.co/docs/huggingface_hub/en/package_reference/mixins#huggingface_hub.PyTorchModelHubMixin) class. If you inherit your main class from it, you can do the following:

```python
from model import PointTransformerV3
from huggingface_hub import hf_hub_download

model = PointTransformerV3(...)

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

# push to the hub
model.push_to_hub("facebook/sonata")

# now anyone can use it as follows:
model = PointTransformerV3.from_pretrained("facebook/sonata")
```

This improves the integration by:
- leveraging safetensors for weights serialization
- download stats
- automatic model card.

This was also adopted by the recent VGGT model at Meta: https://huggingface.co/facebook/VGGT-1B.

Could you try this out?

Kind regards,

Niels

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.