MCPcopy Create free account
hub / github.com/apache/tvm / get_numpy_attention_ref

Function get_numpy_attention_ref

tests/python/relax/test_codegen_cutlass.py:608–635  ·  view source on GitHub ↗
(
    b,
    s,
    s_kv,
    n,
    h,
    h_v,
    bias_shape,
    qk_scale,
    causal,
    dtype,
    window_size=None,
    num_kv_head=None,
)

Source from the content-addressed store, hash-verified

606
607
608def 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
638def test_attention_offload(attention_size, attention_dtype):

Callers 6

test_attention_offloadFunction · 0.85
test_sliding_windowFunction · 0.85

Calls 1

astypeMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…