Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pairwise attention comparison in test #737

Merged
merged 4 commits into from
Nov 15, 2023
Merged
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
13 changes: 11 additions & 2 deletions tests/test_flash_triton_torch.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def test_attn_impl(attn_impl_0: str,

cfg = om.create({
'attn_impl': 'flash',
'd_model': 128,
'd_model': 64,
'n_heads': 4,
'attn_pdrop': 0,
'clip_qkv': clip_qkv,
Expand All @@ -88,6 +88,7 @@ def test_attn_impl(attn_impl_0: str,

cfg.attn_impl = attn_impl_0
attn0 = attention.ATTN_CLASS_REGISTRY[attn_type](**cfg).to(device)
cfg.attn_impl = attn_impl_1
attn1 = attention.ATTN_CLASS_REGISTRY[attn_type](**cfg).to(device)

attn1.load_state_dict(attn0.state_dict())
Expand Down Expand Up @@ -182,7 +183,15 @@ def gen_bias(attn_impl: str):
assert p.grad is not None
assert tp.grad is not None
assert allclose_helper(p, tp)
sashaDoubov marked this conversation as resolved.
Show resolved Hide resolved
assert allclose_helper(p.grad, tp.grad)

using_hf_rope = pos_emb_config['rope'] and pos_emb_config[
'rope_impl'] == 'hf'

# special case that (likely) fails due to numerics
if clip_qkv and qk_ln and using_hf_rope and attn_type == 'grouped_query_attention':
assert allclose_helper(p.grad, tp.grad, atol=2.e-2, rtol=2.e-2)
else:
assert allclose_helper(p.grad, tp.grad)

assert x0.grad is not None
assert x1.grad is not None
Expand Down
Loading