Skip to content

Commit 0cf10dc

Browse files
committed
Ship timeline as flat max_at_time array like PyTorch's MemoryViz
Replace per-event timeline objects with a flat integer array of allocated bytes per timestep. For a 1.8M event trace this reduces the timeline section from 209MB to ~14MB.
1 parent 534d3de commit 0cf10dc

1 file changed

Lines changed: 4 additions & 24 deletions

File tree

transformer_nuggets/utils/memory_viz.py

Lines changed: 4 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ def generate_memory_html(
189189
cat_to_idx[cat] = len(cat_to_idx)
190190
cat_indices = [cat_to_idx.get(c, 0) for c in categories]
191191

192+
max_at_time = [e["a"] for e in timeline]
193+
192194
meta = {
193195
"title": title,
194196
"device": device,
@@ -202,7 +204,7 @@ def generate_memory_html(
202204

203205
return (
204206
_MEMORY_VIZ_TEMPLATE.replace("__TITLE__", title)
205-
.replace("__TIMELINE__", json.dumps(timeline))
207+
.replace("__TIMELINE__", json.dumps(max_at_time))
206208
.replace("__ALLOCS__", json.dumps(alloc_polys))
207209
.replace("__FRAMES__", json.dumps(frames))
208210
.replace("__STACKS__", json.dumps(stacks))
@@ -1160,29 +1162,7 @@ def generate_memory_html(
11601162
.y0(minimapH)
11611163
.y1(d => miniY(d));
11621164
1163-
const allocatedAtTimestep = new Float64Array(META.max_timestep + 1);
1164-
for (const t of TIMELINE) {
1165-
if (t.act === 'alloc' || t.act === 'free_completed') {
1166-
const ts = ALLOCS.length > 0 ? Math.round(miniX.invert(miniX(0))) : 0;
1167-
}
1168-
}
1169-
1170-
let runningAlloc = 0;
1171-
let tsIdx = 0;
1172-
for (const t of TIMELINE) {
1173-
if (t.act === 'alloc' || t.act === 'free_completed' || t.act === 'segment_alloc' || t.act === 'segment_free') {
1174-
allocatedAtTimestep[tsIdx] = t.a;
1175-
} else {
1176-
allocatedAtTimestep[tsIdx] = tsIdx > 0 ? allocatedAtTimestep[tsIdx - 1] : 0;
1177-
}
1178-
tsIdx++;
1179-
}
1180-
1181-
const miniData = [];
1182-
const step = Math.max(1, Math.floor(tsIdx / minimapW));
1183-
for (let i = 0; i < tsIdx; i += step) {
1184-
miniData.push(allocatedAtTimestep[i]);
1185-
}
1165+
const miniData = TIMELINE;
11861166
11871167
miniG.append('path')
11881168
.datum(miniData)

0 commit comments

Comments
 (0)