demo
Browse files
app.py
CHANGED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import torch
|
2 |
+
import torch.nn as nn
|
3 |
+
from huggingface_hub import PyTorchModelHubMixin
|
4 |
+
|
5 |
+
|
6 |
+
class MyModel(nn.Module, PyTorchModelHubMixin):
|
7 |
+
def __init__(self, config: dict):
|
8 |
+
super().__init__()
|
9 |
+
self.param = nn.Parameter(torch.rand(config["num_channels"], config["hidden_size"]))
|
10 |
+
self.linear = nn.Linear(config["hidden_size"], config["num_classes"])
|
11 |
+
|
12 |
+
def forward(self, x):
|
13 |
+
return self.linear(x + self.param)
|
14 |
+
|
15 |
+
# create model
|
16 |
+
config = {"num_channels": 3, "hidden_size": 32, "num_classes": 10}
|
17 |
+
model = MyModel(config=config)
|
18 |
+
|
19 |
+
# save locally
|
20 |
+
model.save_pretrained("my-awesome-model", config=config)
|
21 |
+
|
22 |
+
# push to the hub
|
23 |
+
model.push_to_hub("my-awesome-model", config=config)
|
24 |
+
|
25 |
+
# reload
|
26 |
+
model = MyModel.from_pretrained("username/my-awesome-model")
|