MCPcopy Create free account
hub / github.com/OpenSparseLLMs/MoM / benchmark

Function benchmark

benchmarks/ops/benchmark_gla.py:35–77  ·  view source on GitHub ↗
(T, provider)

Source from the content-addressed store, hash-verified

33 )
34)
35def benchmark(T, provider):
36 device = 'cuda'
37 dtype = torch.bfloat16
38 requires_grad = True
39 B, H, D = 16, 8, 128
40
41 q = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
42 k = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
43 g = F.logsigmoid(torch.randn(B, H, T, D, device=device, dtype=dtype)).clamp_min(-5).requires_grad_(requires_grad)
44 v = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
45
46 do = torch.ones_like(q, dtype=dtype)
47
48 quantiles = [0.5, 0.2, 0.8]
49 results = 0, 0, 0
50 if provider == 'torch':
51 if T > 2048:
52 return results
53 results = triton.testing.do_bench(lambda: naive_retention(q, k, v), quantiles=quantiles)
54 elif provider == 'recurrent_gla':
55 results = triton.testing.do_bench(lambda: fused_recurrent_gla(q, k, v, g), quantiles=quantiles)
56 elif provider == 'fused_chunk_gla':
57 results = triton.testing.do_bench(lambda: fused_chunk_gla(q, k, v, g), quantiles=quantiles)
58 elif provider == 'chunk_retention':
59 results = triton.testing.do_bench(lambda: chunk_retention(q, k, v), quantiles=quantiles)
60 elif provider == 'chunk_gla':
61 results = triton.testing.do_bench(lambda: chunk_gla(q, k, v, g), quantiles=quantiles)
62 elif provider == 'parallel':
63 results = triton.testing.do_bench(lambda: parallel_retention(q, k, v), quantiles=quantiles)
64 elif provider == 'torch_bwd':
65 if T > 2048:
66 return results
67 elif provider == 'chunk_retention_bwd':
68 results = triton.testing.do_bench(lambda: chunk_retention(q, k, v)[0].backward(do), quantiles=quantiles)
69 elif provider == 'recurrent_gla_bwd':
70 results = triton.testing.do_bench(lambda: fused_recurrent_gla(q, k, v, g)[0].backward(do), quantiles=quantiles)
71 elif provider == 'fused_chunk_gla_bwd':
72 results = triton.testing.do_bench(lambda: fused_chunk_gla(q, k, v, g)[0].backward(do), quantiles=quantiles)
73 elif provider == 'chunk_gla_bwd':
74 results = triton.testing.do_bench(lambda: chunk_gla(q, k, v, g)[0].backward(do), quantiles=quantiles)
75 elif provider == 'parallel_bwd':
76 results = triton.testing.do_bench(lambda: parallel_retention(q, k, v)[0].backward(do), quantiles=quantiles)
77 return results
78
79
80if __name__ == '__main__':

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected