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

Function test_sliding_window

tests/python/relax/test_codegen_cutlass.py:2314–2352  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

2312
2313
2314def test_sliding_window():
2315 q_shape = (1, 64, 16, 8)
2316 k_shape = v_shape = q_shape
2317 window_size = 8
2318 causal = "BottomRight"
2319
2320 mod = get_relax_attention_module(
2321 q_shape,
2322 k_shape,
2323 v_shape,
2324 dtype="float16",
2325 causal_mask=causal,
2326 window_size=window_size,
2327 )
2328
2329 q, k, v, _, ref = get_numpy_attention_ref(
2330 1, 64, 64, 16, 8, 8, "none", "none", causal, "float16", window_size=window_size
2331 )
2332
2333 out = get_result_with_relax_cutlass_offload(mod, q, k, v, num_final_bindings=2)
2334
2335 tvm.testing.assert_allclose(out, ref, rtol=1e-2, atol=1e-2)
2336
2337 ############# xformer reference for verification #############
2338
2339 # attn_bias = BlockDiagonalCausalMask.from_seqlens([64])
2340
2341 # if window_size > 0:
2342 # attn_bias = attn_bias.make_local_attention(window_size)
2343
2344 # query = torch.from_numpy(q).to("cuda")
2345 # key = torch.from_numpy(k).to("cuda")
2346 # value = torch.from_numpy(v).to("cuda")
2347
2348 # ref = xops.memory_efficient_attention_forward(
2349 # query, key, value, attn_bias=attn_bias,
2350 # ).cpu().numpy()
2351
2352 # tvm.testing.assert_allclose(out, ref, rtol=1e-2, atol=1e-2)
2353
2354
2355def test_batched_var_len_sliding_window():

Callers

nothing calls this directly

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…