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

Update RoPE tests #1746

Merged
merged 2 commits into from
Sep 26, 2024
Merged
Changes from 1 commit
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
Next Next commit
Update RoPE tests
  • Loading branch information
rasbt committed Sep 26, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 813274736b6e62c584a0e883bfdfb477b6d66261
10 changes: 6 additions & 4 deletions tests/test_rope.py
Original file line number Diff line number Diff line change
@@ -13,12 +13,14 @@ def test_rope():
x = torch.randint(0, 10000, size=(bs, n_head, seq_len, head_size)).float()
position_ids = torch.arange(seq_len).unsqueeze(0)

theirs = GPTNeoXRotaryEmbedding(head_size, seq_len)
theirs_rot_emb = GPTNeoXRotaryEmbedding(head_size, seq_len)
theirs_cos, theirs_sin = theirs_rot_emb(x, position_ids)

ours_cos_cached, ours_sin_cached = build_rope_cache(seq_len, head_size, device=x.device)
# their rope cache has 2 added dimensions and the cos/sin is duplicated
torch.testing.assert_close(ours_cos_cached, theirs.cos_cached.squeeze())
torch.testing.assert_close(ours_sin_cached, theirs.sin_cached.squeeze())
torch.testing.assert_close(ours_cos_cached, theirs_cos.squeeze())
torch.testing.assert_close(ours_sin_cached, theirs_sin.squeeze())

ours_x_rope = apply_rope(x, ours_cos_cached, ours_sin_cached)
theirs_x_rope, _ = apply_rotary_pos_emb(x, x, theirs.cos_cached, theirs.sin_cached, position_ids)
theirs_x_rope, _ = apply_rotary_pos_emb(x, x, theirs_cos, theirs_sin, position_ids)
torch.testing.assert_close(ours_x_rope, theirs_x_rope)
Loading