Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions extension/llm/modules/test/test_attention.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
MultiHeadAttention as ETMultiHeadAttention,
)
from executorch.runtime import Runtime
from torch.testing import assert_close
from torchtune.models.llama3_1._position_embeddings import Llama3ScaledRoPE
from torchtune.modules.attention import MultiHeadAttention as TTMultiHeadAttention

Expand Down Expand Up @@ -94,7 +95,7 @@ def test_attention_eager(self):
et_res = self.et_mha(self.x, self.x) # Self attention.
tt_res = self.tt_mha(self.x, self.x) # Self attention.

self.assertTrue(torch.allclose(et_res, tt_res))
assert_close(et_res, tt_res)

# test with kv cache
self.et_mha.setup_cache(1, dtype=torch.float32, max_seq_len=20)
Expand Down Expand Up @@ -124,7 +125,8 @@ def test_attention_eager(self):
tt_res = self.tt_mha(
self.x, self.x, input_pos=next_input_pos
) # Self attention with input pos.
self.assertTrue(torch.allclose(et_res, tt_res))

assert_close(et_res, tt_res)

def test_attention_export(self):
# Self attention.
Expand All @@ -136,7 +138,8 @@ def test_attention_export(self):
)
et_res = et_mha_ep.module()(self.x, self.x, input_pos=self.input_pos)
tt_res = self.tt_mha(self.x, self.x, input_pos=self.input_pos)
self.assertTrue(torch.allclose(et_res, tt_res))

assert_close(et_res, tt_res)

# TODO: KV cache.

Expand All @@ -162,6 +165,6 @@ def test_attention_executorch(self):
et_res = method.execute((self.x, self.x, self.input_pos))
tt_res = self.tt_mha(self.x, self.x, input_pos=self.input_pos)

self.assertTrue(torch.allclose(et_res[0], tt_res, atol=1e-06))
assert_close(et_res[0], tt_res)

# TODO: KV cache.
1 change: 0 additions & 1 deletion pytest.ini
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ addopts =
backends/xnnpack/test
# extension/
extension/llm/modules/test
--ignore=extension/llm/modules/test/test_mha.py
extension/pybindings/test
# Runtime
runtime
Expand Down
Loading