(
b,
s,
s_kv,
n,
h,
h_v,
bias_shape,
qk_scale,
causal,
dtype,
window_size=None,
num_kv_head=None,
)
| 606 | |
| 607 | |
| 608 | def get_numpy_attention_ref( |
| 609 | b, |
| 610 | s, |
| 611 | s_kv, |
| 612 | n, |
| 613 | h, |
| 614 | h_v, |
| 615 | bias_shape, |
| 616 | qk_scale, |
| 617 | causal, |
| 618 | dtype, |
| 619 | window_size=None, |
| 620 | num_kv_head=None, |
| 621 | ): |
| 622 | num_kv_head = num_kv_head or n |
| 623 | q = np.random.randn(b, s, n, h).astype(dtype) |
| 624 | k = np.random.randn(b, s_kv, num_kv_head, h).astype(dtype) |
| 625 | v = np.random.randn(b, s_kv, num_kv_head, h_v).astype(dtype) |
| 626 | if bias_shape == "none": |
| 627 | bias = None |
| 628 | else: |
| 629 | bias = np.random.randn(*bias_shape).astype(dtype) |
| 630 | |
| 631 | ref = tvm.topi.testing.attention_python( |
| 632 | q, k, v, bias, qk_scale, causal=causal, window_size=window_size, layout="BSNH" |
| 633 | ) |
| 634 | |
| 635 | return q, k, v, bias, ref |
| 636 | |
| 637 | |
| 638 | def test_attention_offload(attention_size, attention_dtype): |
no test coverage detected
searching dependent graphs…