(T, provider)
| 27 | ) |
| 28 | ) |
| 29 | def 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 | |
| 51 | if __name__ == '__main__': |
nothing calls this directly
no outgoing calls
no test coverage detected