Skip to content

Commit afa42a7

Browse files
committed
test(§TB1): --frugal bs4 arm (v1 vs batched only, free between) for mem-lean bs4 prod
1 parent d3176fe commit afa42a7

1 file changed

Lines changed: 15 additions & 6 deletions

File tree

scratch/probe_b2_batched_cuda_ab_only.py

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,25 @@ def timeit(k, n=20):
7474
torch.cuda.synchronize()
7575
return (time.perf_counter() - t0) / n * 1e3, o
7676

77-
print("[B2-AB] building v1-threaded ..."); k1 = build(chunk_scan_combine_bwd_cuda_prim(b, S, chunk, G, H, P, N))
78-
print("[B2-AB] building §27 single-tile gemm ..."); kg = build(chunk_scan_combine_bwd_cuda_prim_gemm(b, S, chunk, G, H, P, N))
79-
print(f"[B2-AB] building batched HPC={HPC} ..."); kb = build(chunk_scan_combine_bwd_cuda_prim_gemm_batched(b, S, chunk, G, H, P, N, heads_per_cta=HPC))
77+
FRUGAL = "--frugal" in sys.argv # bs4: only v1 + batched, free between (mem-lean)
78+
names = ["dC", "dx", "dz", "dchunk", "dinp", "dA_y", "dD"]
8079

80+
print("[B2-AB] building v1-threaded ..."); k1 = build(chunk_scan_combine_bwd_cuda_prim(b, S, chunk, G, H, P, N))
8181
t1, o1 = timeit(k1)
82-
tg, og = timeit(kg)
82+
if FRUGAL:
83+
o1ref = [t.clone() for t in o1]
84+
del o1; torch.cuda.empty_cache()
85+
tg = float("nan")
86+
else:
87+
print("[B2-AB] building §27 single-tile gemm ..."); kg = build(chunk_scan_combine_bwd_cuda_prim_gemm(b, S, chunk, G, H, P, N))
88+
tg, og = timeit(kg)
89+
del og; torch.cuda.empty_cache()
90+
o1ref = o1
91+
92+
print(f"[B2-AB] building batched HPC={HPC} ..."); kb = build(chunk_scan_combine_bwd_cuda_prim_gemm_batched(b, S, chunk, G, H, P, N, heads_per_cta=HPC))
8393
tb, ob = timeit(kb)
8494

85-
names = ["dC", "dx", "dz", "dchunk", "dinp", "dA_y", "dD"]
86-
eq_b_v1 = {nm: float((a - c).abs().max().cpu()) for nm, a, c in zip(names, ob, o1)}
95+
eq_b_v1 = {nm: float((a - c).abs().max().cpu()) for nm, a, c in zip(names, ob, o1ref)}
8796
worst = max(eq_b_v1.values())
8897

8998
print(f"\n[B2-AB] MEASURED v1_threaded={t1:.3f}ms §27_single_tile_gemm={tg:.3f}ms "

0 commit comments

Comments
 (0)