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

Test CI #1747

Closed
wants to merge 2 commits into from
Closed

Test CI #1747

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
4 changes: 2 additions & 2 deletions .github/workflows/cpu-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ jobs:
- {os: "macOS-14", python-version: "3.10"}
- {os: "ubuntu-22.04", python-version: "3.11"}
- {os: "ubuntu-22.04", python-version: "3.10"}
- {os: "ubuntu-22.04", python-version: "3.9"}
- {os: "windows-2022", python-version: "3.9"}
- {os: "ubuntu-22.04", python-version: "3.10"}
- {os: "windows-2022", python-version: "3.10"}
timeout-minutes: 25

steps:
Expand Down
36 changes: 18 additions & 18 deletions tests/test_rope.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
# Copyright Lightning AI. Licensed under the Apache License 2.0, see LICENSE file.
# # Copyright Lightning AI. Licensed under the Apache License 2.0, see LICENSE file.

import torch
from transformers.models.gpt_neox.modeling_gpt_neox import GPTNeoXRotaryEmbedding, apply_rotary_pos_emb
# import torch
# from transformers.models.gpt_neox.modeling_gpt_neox import GPTNeoXRotaryEmbedding, apply_rotary_pos_emb

from litgpt.model import apply_rope, build_rope_cache
# from litgpt.model import apply_rope, build_rope_cache


@torch.inference_mode()
def test_rope():
bs, seq_len, n_head, n_embed = 1, 6, 2, 8
head_size = n_embed // n_head
x = torch.randint(0, 10000, size=(bs, n_head, seq_len, head_size)).float()
position_ids = torch.arange(seq_len).unsqueeze(0)
# @torch.inference_mode()
# def test_rope():
# bs, seq_len, n_head, n_embed = 1, 6, 2, 8
# head_size = n_embed // n_head
# 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)
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())
# theirs = GPTNeoXRotaryEmbedding(head_size, seq_len)
# 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())

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)
torch.testing.assert_close(ours_x_rope, theirs_x_rope)
# 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)
# torch.testing.assert_close(ours_x_rope, theirs_x_rope)
Loading