diff --git a/colabs/intro/Intro_to_Weights_&_Biases.ipynb b/colabs/intro/Intro_to_Weights_&_Biases.ipynb index 9d50a20a..2a6aa047 100644 --- a/colabs/intro/Intro_to_Weights_&_Biases.ipynb +++ b/colabs/intro/Intro_to_Weights_&_Biases.ipynb @@ -3,8 +3,8 @@ { "cell_type": "markdown", "metadata": { - "id": "view-in-github", - "colab_type": "text" + "colab_type": "text", + "id": "view-in-github" }, "source": [ "\"Open" @@ -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\")" ] }, @@ -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)" ] }, { @@ -286,7 +288,7 @@ "id": "KR8D_a7l1KEB" }, "source": [ - "## Train Your Model" + "## Train Your Model & Upload Checkpoints" ] }, { @@ -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", @@ -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", @@ -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" ] }, { @@ -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", @@ -461,4 +467,4 @@ }, "nbformat": 4, "nbformat_minor": 0 -} \ No newline at end of file +}