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

Function benchmark

benchmarks/ops/benchmark_rwkv6.py:39–74  ·  view source on GitHub ↗
(T, provider)

Source from the content-addressed store, hash-verified

37 )
38)
39def benchmark(T, provider):
40 device = 'cuda'
41 dtype = torch.bfloat16
42 requires_grad = True
43 B, H, D = 16, 8, 128
44
45 q = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
46 k = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
47 v = torch.randn(B, H, T, D, device=device, requires_grad=requires_grad, dtype=dtype)
48 if provider.startswith('flash'):
49 q = torch.randn(B, T, H, D, device=device, requires_grad=requires_grad, dtype=dtype)
50 k = torch.randn(B, T, H, D, device=device, requires_grad=requires_grad, dtype=dtype)
51 v = torch.randn(B, T, H, D, device=device, requires_grad=requires_grad, dtype=dtype)
52 if provider.startswith('gla'):
53 g = F.logsigmoid(torch.randn(B, H, T, D, device=device, dtype=dtype))
54 g = g.clamp_min(-5).requires_grad_(requires_grad)
55 if provider.startswith('rwkv6'):
56 w = F.logsigmoid(torch.randn(B, H, T, D, device=device, dtype=dtype)).requires_grad_(True)
57 u = torch.randn(H, D, device=device, dtype=dtype).requires_grad_(True)
58
59 do = torch.ones_like(v, dtype=dtype)
60
61 quantiles = [0.5, 0.2, 0.8]
62 if provider == 'rwkv6':
63 results = triton.testing.do_bench(lambda: chunk_rwkv6(q, k, v, w, u), quantiles=quantiles)
64 elif provider == 'gla':
65 results = triton.testing.do_bench(lambda: chunk_gla(q, k, v, g), quantiles=quantiles)
66 elif provider == 'rwkv6_bwd':
67 results = triton.testing.do_bench(lambda: chunk_rwkv6(q, k, v, w, u)[0].backward(do), quantiles=quantiles)
68 elif provider == 'gla_bwd':
69 results = triton.testing.do_bench(lambda: chunk_gla(q, k, v, g)[0].backward(do), quantiles=quantiles)
70 elif provider == 'retention_bwd':
71 results = triton.testing.do_bench(lambda: chunk_retention(q, k, v)[0].backward(do), quantiles=quantiles)
72 elif provider == 'flash_bwd':
73 results = triton.testing.do_bench(lambda: flash_attn_func(q, k, v, causal=True).backward(do), quantiles=quantiles)
74 return results
75
76
77if __name__ == '__main__':

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected