From abf3823610c030f7b08a4ef5f37d7cac20ccdcf7 Mon Sep 17 00:00:00 2001 From: anastasiaguspan Date: Fri, 30 Jan 2026 15:00:57 -0500 Subject: [PATCH] models quickstart - new colab Creating a new colab file to support the w&B models quickstart page: https://docs.wandb.ai/models/quickstart For docs ticket: https://wandb.atlassian.net/browse/DOCS-1791 I have ran nb-clean on the notebook to remove metadata. --- colabs/intro/run_quickstart.ipynb | 123 ++++++++++++++++++++++++++++++ 1 file changed, 123 insertions(+) create mode 100644 colabs/intro/run_quickstart.ipynb diff --git a/colabs/intro/run_quickstart.ipynb b/colabs/intro/run_quickstart.ipynb new file mode 100644 index 00000000..12ded09f --- /dev/null +++ b/colabs/intro/run_quickstart.ipynb @@ -0,0 +1,123 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "##Use W&B to track, visualize, and manage machine learning experiments of any size.\n", + "To authenticate your machine with W&B, you need a W&B API key.\n", + "Save key to Google Colab Secrets under name WANDB_API_KEY. Enable notebook access for key.\n", + "\n", + "A [run](/models/runs/) is a core element of W&B. You use runs to [track metrics](/models/track/), [create logs](/models/track/log/), track artifacts, and more.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "!pip install wandb" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import wandb\n", + "import os\n", + "from google.colab import userdata\n", + "\n", + "os.environ[\"WANDB_API_KEY\"] = userdata.get(\"WANDB_API_KEY\")\n", + "\n", + "\n", + "wandb.login()\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Set up project and track hyperparameters\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "import wandb\n", + "\n", + "# Project that the run is recorded to\n", + "project = \"my-run-quickstart\"\n", + "\n", + "# Hyperparameters\n", + "config = {\n", + " \"epochs\": 10,\n", + " \"lr\": 0.01,\n", + "}\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "\n", + "\n", + "## Create a machine learning training experiment\n", + "\n", + "This mock training script logs simulated accuracy and loss metrics to W&B.\n", + "\n", + "\n", + "Initialize a W&B run object with [`wandb.init()`](/models/ref/python/experiments/run/). Use a dictionary for the `config` parameter\n", + "to specify hyperparameter names and values. Within the `with` statement, you can log metrics and other information to W&B.\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "import random\n", + "\n", + "\n", + "with wandb.init(project=project, config=config) as run:\n", + " offset = random.random() / 5\n", + " print(f\"lr: {config['lr']}\")\n", + "\n", + " for epoch in range(2, config[\"epochs\"]):\n", + " acc = 1 - 2**-config[\"epochs\"] - random.random() / config[\"epochs\"] - offset\n", + " loss = 2**-config[\"epochs\"] + random.random() / config[\"epochs\"] + offset\n", + "\n", + " print(f\"epoch={epoch}, accuracy={acc:.4f}, loss={loss:.4f}\")\n", + " run.log({\"epoch\": epoch, \"accuracy\": acc, \"loss\": loss})\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Visit the custom \"View run\" link in the prior cell's output (or go to wandb.ai/home) to view recorded metrics such as accuracy and loss and how they changed during each training step. W&B Runs show the loss and accuracy tracked from each run. Each run object appears in the Runs page with auto-generated names." + ] + } + ], + "metadata": { + "colab": { + "provenance": [] + }, + "kernelspec": { + "display_name": "Python 3", + "name": "python3" + }, + "language_info": { + "name": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0 +}