|
| 1 | +import math |
1 | 2 | import random |
2 | 3 | import time |
3 | 4 |
|
4 | | -from tqdm import tqdm |
5 | | - |
6 | 5 | import trackio as wandb |
7 | 6 |
|
8 | | -project_id = random.randint(10000, 99999) |
9 | | - |
10 | | -wandb.init( |
11 | | - project=f"fake-training-{project_id}", |
12 | | - name="test-run", |
13 | | - config=dict( |
14 | | - epochs=5, |
15 | | - learning_rate=0.001, |
16 | | - batch_size=32, |
17 | | - ), |
18 | | - space_id=f"trackio-{project_id}", |
19 | | -) |
20 | | - |
21 | | -EPOCHS = 5 |
22 | | -NUM_TRAIN_BATCHES = 100 |
23 | | -NUM_VAL_BATCHES = 20 |
24 | | - |
25 | | -for epoch in range(EPOCHS): |
26 | | - train_loss = 0 |
27 | | - train_accuracy = 0 |
28 | | - val_loss = 0 |
29 | | - val_accuracy = 0 |
30 | | - |
31 | | - for _ in tqdm(range(NUM_TRAIN_BATCHES), desc=f"Epoch {epoch + 1} - Training"): |
32 | | - loss = random.uniform(0.2, 1.0) |
33 | | - accuracy = random.uniform(0.6, 0.95) |
34 | | - train_loss += loss |
35 | | - train_accuracy += accuracy |
36 | | - |
37 | | - for _ in tqdm(range(NUM_VAL_BATCHES), desc=f"Epoch {epoch + 1} - Validation"): |
38 | | - loss = random.uniform(0.2, 0.9) |
39 | | - accuracy = random.uniform(0.65, 0.98) |
40 | | - val_loss += loss |
41 | | - val_accuracy += accuracy |
42 | | - |
43 | | - train_loss /= NUM_TRAIN_BATCHES |
44 | | - train_accuracy /= NUM_TRAIN_BATCHES |
45 | | - val_loss /= NUM_VAL_BATCHES |
46 | | - val_accuracy /= NUM_VAL_BATCHES |
47 | | - |
48 | | - wandb.log( |
49 | | - { |
50 | | - "train_loss": train_loss, |
51 | | - "train_accuracy": train_accuracy, |
52 | | - "val_loss": val_loss, |
53 | | - "val_accuracy": val_accuracy, |
54 | | - } |
| 7 | +EPOCHS = 20 |
| 8 | +PROJECT_ID = random.randint(100000, 999999) |
| 9 | + |
| 10 | + |
| 11 | +def generate_loss_curve(epoch, max_epochs, base_loss=2.5, min_loss=0.1): |
| 12 | + """Generate a realistic loss curve that decreases over time with noise""" |
| 13 | + progress = epoch / max_epochs |
| 14 | + base_curve = base_loss * math.exp(-3 * progress) + min_loss |
| 15 | + |
| 16 | + noise_scale = 0.3 * (1 - progress * 0.7) |
| 17 | + noise = random.gauss(0, noise_scale) |
| 18 | + |
| 19 | + return max(min_loss * 0.5, base_curve + noise) |
| 20 | + |
| 21 | + |
| 22 | +def generate_accuracy_curve(epoch, max_epochs, max_acc=0.95, min_acc=0.1): |
| 23 | + """Generate a realistic accuracy curve that increases over time with noise""" |
| 24 | + progress = epoch / max_epochs |
| 25 | + base_curve = max_acc / (1 + math.exp(-6 * (progress - 0.5))) + min_acc |
| 26 | + |
| 27 | + noise_scale = 0.08 * (1 - progress * 0.5) |
| 28 | + noise = random.gauss(0, noise_scale) |
| 29 | + |
| 30 | + return max(0, min(max_acc, base_curve + noise)) |
| 31 | + |
| 32 | + |
| 33 | +for run in range(3): |
| 34 | + wandb.init( |
| 35 | + project=f"deploy-on-spaces-{PROJECT_ID}", |
| 36 | + name=f"test-run-{run}", |
| 37 | + config=dict( |
| 38 | + epochs=EPOCHS, |
| 39 | + learning_rate=0.001, |
| 40 | + batch_size=32, |
| 41 | + ), |
| 42 | + space_id=f"trackio-on-spaces-{PROJECT_ID}", |
55 | 43 | ) |
56 | | - time.sleep(1) |
| 44 | + |
| 45 | + for epoch in range(EPOCHS): |
| 46 | + train_loss = generate_loss_curve( |
| 47 | + epoch, |
| 48 | + EPOCHS, |
| 49 | + base_loss=random.uniform(2.5, 3.5), |
| 50 | + min_loss=random.uniform(0.05, 0.15), |
| 51 | + ) |
| 52 | + val_loss = generate_loss_curve( |
| 53 | + epoch, |
| 54 | + EPOCHS, |
| 55 | + base_loss=random.uniform(2.5, 3.5), |
| 56 | + min_loss=random.uniform(0.05, 0.15), |
| 57 | + ) |
| 58 | + |
| 59 | + train_accuracy = generate_accuracy_curve( |
| 60 | + epoch, |
| 61 | + EPOCHS, |
| 62 | + max_acc=random.uniform(0.7, 0.9), |
| 63 | + min_acc=random.uniform(0.1, 0.3), |
| 64 | + ) |
| 65 | + val_accuracy = generate_accuracy_curve( |
| 66 | + epoch, |
| 67 | + EPOCHS, |
| 68 | + max_acc=random.uniform(0.7, 0.9), |
| 69 | + min_acc=random.uniform(0.1, 0.3), |
| 70 | + ) |
| 71 | + |
| 72 | + if epoch > 2 and random.random() < 0.3: |
| 73 | + val_loss *= 1.1 |
| 74 | + val_accuracy *= 0.95 |
| 75 | + |
| 76 | + wandb.log( |
| 77 | + { |
| 78 | + "train_loss": round(train_loss, 4), |
| 79 | + "train_accuracy": round(train_accuracy, 4), |
| 80 | + "val_loss": round(val_loss, 4), |
| 81 | + "val_accuracy": round(val_accuracy, 4), |
| 82 | + } |
| 83 | + ) |
| 84 | + |
| 85 | + time.sleep(0.2) |
57 | 86 |
|
58 | 87 | wandb.finish() |
0 commit comments