Skip to content

Commit

Permalink
Update intro colab with models logging (#549)
Browse files Browse the repository at this point in the history
Merging
  • Loading branch information
morganmcg1 authored Jul 23, 2024
1 parent f718e01 commit 96d7fb9
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions colabs/intro/Intro_to_Weights_&_Biases.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
"colab_type": "text",
"id": "view-in-github"
},
"source": [
"<a href=\"https://colab.research.google.com/github/wandb/examples/blob/add-core-to-examples/colabs/intro/Intro_to_Weights_%26_Biases.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
Expand Down Expand Up @@ -104,7 +104,7 @@
"# Log in to your W&B account\n",
"import wandb\n",
"\n",
"# Use wandb-core\n",
"# Use wandb-core, temporary for wandb's new backend \n",
"wandb.require(\"core\")"
]
},
Expand Down Expand Up @@ -199,7 +199,9 @@
"[hyperparameters](https://docs.wandb.ai/ref/app/pages/run-page#overview-tab),\n",
"[terminal output](https://docs.wandb.ai/ref/app/pages/run-page#logs-tab) and\n",
"you'll see an [interactive table](https://docs.wandb.ai/guides/data-vis)\n",
"with model inputs and outputs."
"with model inputs and outputs. \n",
"\n",
"This code will also save and upload Model checkpoints to W&B where you can then use them in the [W&B Registry](https://docs.wandb.ai/guides/registry)"
]
},
{
Expand Down Expand Up @@ -286,7 +288,7 @@
"id": "KR8D_a7l1KEB"
},
"source": [
"## Train Your Model"
"## Train Your Model & Upload Checkpoints"
]
},
{
Expand All @@ -297,13 +299,13 @@
},
"outputs": [],
"source": [
"# Launch 5 experiments, trying different dropout rates\n",
"for _ in range(5):\n",
"# Launch 3 experiments, trying different dropout rates\n",
"for _ in range(3):\n",
" # 🐝 initialise a wandb run\n",
" wandb.init(\n",
" project=\"pytorch-intro\",\n",
" config={\n",
" \"epochs\": 10,\n",
" \"epochs\": 5,\n",
" \"batch_size\": 128,\n",
" \"lr\": 1e-3,\n",
" \"dropout\": random.uniform(0.01, 0.80),\n",
Expand Down Expand Up @@ -356,9 +358,13 @@
" \"val/val_accuracy\": accuracy}\n",
" wandb.log({**metrics, **val_metrics})\n",
"\n",
" print(f\"Train Loss: {train_loss:.3f}, Valid Loss: {val_loss:3f}, Accuracy: {accuracy:.2f}\")\n",
" # 🐝 Save the model checkpoint to wandb\n",
" torch.save(model, \"my_model.pt\")\n",
" wandb.log_model(\"./mnist_model.pt\", \"my_mnist_model\", aliases=[f\"epoch-{epoch+1}_dropout-{round(wandb.config.dropout, 4)}\"])\n",
"\n",
" print(f\"Epoch: {epoch+1}, Train Loss: {train_loss:.3f}, Valid Loss: {val_loss:3f}, Accuracy: {accuracy:.2f}\")\n",
"\n",
" # If you had a test set, this is how you could log it as a Summary metric\n",
" # 🐝 If you had a test set, this is how you could log it as a Summary metric\n",
" wandb.summary['test_accuracy'] = 0.8\n",
"\n",
" # 🐝 Close your wandb run\n",
Expand All @@ -371,7 +377,7 @@
"id": "4SZOL5on1KEB"
},
"source": [
"You have now trained your first model using wandb! 👆 Click on the wandb link above to see your metrics"
"You have now trained your first model using wandb! 👆 Click on the wandb link above to see your metrics and see your saved Model checkpoints in the Artifacts tab in the UI"
]
},
{
Expand Down Expand Up @@ -450,9 +456,9 @@
"metadata": {
"accelerator": "GPU",
"colab": {
"include_colab_link": true,
"provenance": [],
"toc_visible": true,
"include_colab_link": true
"toc_visible": true
},
"kernelspec": {
"display_name": "Python 3",
Expand All @@ -461,4 +467,4 @@
},
"nbformat": 4,
"nbformat_minor": 0
}
}

0 comments on commit 96d7fb9

Please sign in to comment.