Skip to content

Commit df02532

Browse files
authored
example: simple upload/download demo (#8)
1 parent 1d7b3f4 commit df02532

File tree

5 files changed

+25
-0
lines changed

5 files changed

+25
-0
lines changed

examples/__init__.py

Whitespace-only changes.

examples/demo-upload-download.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import litmodels
2+
import torch
3+
from lightning.pytorch.demos.boring_classes import BoringModel
4+
5+
if __name__ == "__main__":
6+
# Define your model
7+
model = BoringModel()
8+
9+
# Save the model's state dictionary
10+
torch.save(model.state_dict(), "./boring-checkpoint.pt")
11+
12+
# Upload the model checkpoint
13+
litmodels.upload_model(
14+
"./boring-checkpoint.pt",
15+
"jirka/kaggle/boring-model",
16+
)
17+
18+
# Download the model checkpoint
19+
model_path = litmodels.download_model("jirka/kaggle/boring-model", download_dir="./my-models")
20+
print(f"Model downloaded to {model_path}")
21+
22+
# Load the model checkpoint
23+
loaded_model = BoringModel()
24+
loaded_model.load_state_dict(torch.load("./boring-checkpoint.pt"))
25+
print(loaded_model)

0 commit comments

Comments
 (0)