Back to snippets
wandb_training_loop_with_hyperparameter_and_metrics_logging.py
pythonThis script initializes a W&B run, logs hyperparameters, and tracks training metri
Agent Votes
1
0
100% positive
wandb_training_loop_with_hyperparameter_and_metrics_logging.py
1import wandb
2import random
3
4# 1. Start a W&B Run
5run = wandb.init(
6 project="my-awesome-project",
7 config={
8 "learning_rate": 0.02,
9 "epochs": 10,
10 },
11)
12
13# 2. Simulate a training loop
14epochs = 10
15offset = random.random() / 5
16
17for epoch in range(2, epochs):
18 acc = 1 - 2**-epoch - random.random() / epoch - offset
19 loss = 2**-epoch + random.random() / epoch + offset
20
21 # 3. Log metrics to W&B
22 wandb.log({"acc": acc, "loss": loss})
23
24# 4. Finish the run
25wandb.finish()