Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DENG-6965 Track the trained model as W&B Artifact #41

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions examples/image_classifier/image_classifier_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def train(self):
import wandb
import os

tracking_run = {}
if not self.offline_wandb:
tracking_run = wandb.init(project=os.getenv("WANDB_PROJECT"))
wandb_url = tracking_run.get_url()
Expand Down Expand Up @@ -144,6 +145,16 @@ def train(self):
buffer = BytesIO()
torch.save(image_classifier_model.state_dict(), buffer)
self.model_state_dict_bytes = buffer.getvalue()

if not self.offline_wandb:
# Save trained model locally and then track it in W&B
torch.save(image_classifier_model.state_dict(), "./trained_model.pt")
model_artifact = wandb.Artifact(
name="trained_image_classifier", type="model"
)
model_artifact.add_file(local_path="./trained_model.pt")
tracking_run.log_artifact(model_artifact)

self.next(self.evaluate)

# Test the model on the test data
Expand Down