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

Function benchmark

benchmarks/ops/benchmark_hgrn.py:29–48  ·  view source on GitHub ↗
(T, provider)

Source from the content-addressed store, hash-verified

27 )
28)
29def benchmark(T, provider):
30 dtype = torch.bfloat16
31 B, D = 16, 512
32
33 x = torch.randn((B, T, D), dtype=dtype, device='cuda')
34 g = torch.randn((B, T, D), dtype=dtype, device='cuda').sigmoid()
35 x = (1 - g) * x
36 x, g = (i.detach().clone().to(dtype).requires_grad_() for i in (x, g))
37 do = torch.randn_like(x, dtype=dtype)
38 quantiles = [0.5, 0.2, 0.8]
39 results = 0, 0, 0
40 if provider == 'chunk':
41 results = triton.testing.do_bench(lambda: chunk_hgrn(x, g), quantiles=quantiles)
42 if provider == 'recurrent':
43 results = triton.testing.do_bench(lambda: fused_recurrent_hgrn(x, g), quantiles=quantiles)
44 if provider == 'chunk_bwd':
45 results = triton.testing.do_bench(lambda: chunk_hgrn(x, g)[0].backward(do), quantiles=quantiles)
46 if provider == 'recurrent_bwd':
47 results = triton.testing.do_bench(lambda: fused_recurrent_hgrn(x, g)[0].backward(do), quantiles=quantiles)
48 return results
49
50
51if __name__ == '__main__':

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected