import torch import torch.nn as nn from huggingface_hub import PyTorchModelHubMixin class MyModel(nn.Module, PyTorchModelHubMixin): def __init__(self, num_channels: int, hidden_size: int, num_classes: int): super().__init__() self.param = nn.Parameter(torch.rand(num_channels, hidden_size)) self.linear = nn.Linear(hidden_size, num_classes) def forward(self, x): return self.linear(x + self.param) # create model config = {"num_channels": 3, "hidden_size": 32, "num_classes": 10} model = MyModel(**config) # save locally model.save_pretrained("my-awesome-model") # push to the hub model.push_to_hub("my-awesome-model") # reload model = MyModel.from_pretrained("username/my-awesome-model")