forked from RobinWitch/DyStream
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_blockwise_metrics.py
More file actions
85 lines (69 loc) · 2.28 KB
/
Copy pathplot_blockwise_metrics.py
File metadata and controls
85 lines (69 loc) · 2.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
"""
Plot block-wise distillation training metrics.
Usage:
.venv/bin/python plot_blockwise_metrics.py \
--metrics outputs/blockwise_stream_distill/metrics.jsonl
"""
import argparse
import json
import os
os.environ.setdefault("MPLCONFIGDIR", os.path.join(os.path.dirname(os.path.abspath(__file__)), ".cache", "matplotlib"))
import matplotlib.pyplot as plt
def load_metrics(path):
rows = []
with open(path, "r", encoding="utf-8") as f:
for line in f:
if not line.strip():
continue
item = json.loads(line)
if item.get("event") == "train":
rows.append(item)
if not rows:
raise ValueError(f"No train events found in {path}")
return rows
def smooth(values, window):
if window <= 1:
return values
out = []
acc = 0.0
queue = []
for value in values:
queue.append(value)
acc += value
if len(queue) > window:
acc -= queue.pop(0)
out.append(acc / len(queue))
return out
def main():
parser = argparse.ArgumentParser(description="Plot block-wise distillation metrics")
parser.add_argument("--metrics", default="outputs/blockwise_stream_distill/metrics.jsonl")
parser.add_argument("--output", default=None)
parser.add_argument("--smooth", type=int, default=50)
args = parser.parse_args()
rows = load_metrics(args.metrics)
steps = [row["step"] for row in rows]
output = args.output or os.path.join(os.path.dirname(args.metrics), "loss_curves.png")
curves = [
("loss", "total"),
("loss_motion", "motion"),
("loss_velocity", "velocity"),
("loss_acceleration", "acceleration"),
("loss_boundary", "boundary"),
]
plt.figure(figsize=(12, 7))
for key, label in curves:
values = [row[key] for row in rows if key in row]
if len(values) != len(steps):
continue
plt.plot(steps, smooth(values, args.smooth), label=label)
plt.xlabel("step")
plt.ylabel("loss")
plt.title("Block-wise Streaming Distillation Loss")
plt.grid(True, alpha=0.3)
plt.legend()
plt.tight_layout()
os.makedirs(os.path.dirname(output), exist_ok=True)
plt.savefig(output, dpi=160)
print(output)
if __name__ == "__main__":
main()