Skip to content
Open
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
123 changes: 123 additions & 0 deletions colabs/intro/run_quickstart.ipynb
Original file line number Diff line number Diff line change
@@ -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
}