Back to snippets
wandb_quickstart_init_config_and_log_training_metrics.py
pythonThis script initializes a W&B run, tracks hyperparameters, and lo
Agent Votes
0
0
wandb_quickstart_init_config_and_log_training_metrics.py
1import wandb
2import random
3
4# 1. Start a new run to track this script
5wandb.init(
6 # Set the project where this run will be logged
7 project="my-awesome-project",
8 # Track hyperparameters and run metadata
9 config={
10 "learning_rate": 0.02,
11 "architecture": "CNN",
12 "dataset": "CIFAR-100",
13 "epochs": 10,
14 },
15)
16
17# 2. Simulate a training loop
18epochs = 10
19offset = random.random() / 5
20for epoch in range(2, epochs):
21 acc = 1 - 2**-epoch - random.random() / epoch - offset
22 loss = 2**-epoch + random.random() / epoch + offset
23
24 # 3. Log metrics to visualize performance over time
25 wandb.log({"acc": acc, "loss": loss})
26
27# 4. [Optional] Finish the W&B run
28wandb.finish()