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

fixbug for chatglm_v2's RetaryEmbedding dtype #9476

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
10 changes: 5 additions & 5 deletions paddlenlp/transformers/chatglm_v2/modeling.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@
def __init__(self, dim, original_impl=False):
super().__init__()
self.default_dtype = paddle.get_default_dtype()
inv_freq = 1.0 / (10000 ** (paddle.arange(0, dim, 2, dtype="float32") / dim))
inv_freq = 1.0 / (10000 ** (paddle.arange(0, dim, 2, dtype=self.default_dtype) / dim))
self.register_buffer("inv_freq", inv_freq)
self.dim = dim
self.original_impl = original_impl
Expand All @@ -113,16 +113,16 @@
theta = 1.0 / (base ** (paddle.arange(0, n_elem, 2, dtype="float32") / n_elem))

# Create position indexes `[0, 1, ..., seq_len - 1]`
seq_idx = paddle.arange(0, seq_len, dtype=theta.dtype)
seq_idx = paddle.arange(0, seq_len, dtype="float32")

# Calculate the product of position index and $\theta_i$
idx_theta = paddle.outer(seq_idx, theta).astype(self.default_dtype)
idx_theta = paddle.outer(seq_idx, theta).astype("float32")

cache = paddle.stack([paddle.cos(idx_theta), paddle.sin(idx_theta)], axis=-1)

# this is to mimic the behaviour of complex32, else we will get different results
if self.default_dtype in (paddle.float16, paddle.bfloat16, paddle.int8):
cache = cache.astype(self.default_dtype)
if self.default_dtype in ("float16", "bfloat16", "int8"):
cache = cache.astype("bfloat16") if self.default_dtype == "bfloat16" else cache.astype("float16")

Check warning on line 125 in paddlenlp/transformers/chatglm_v2/modeling.py

View check run for this annotation

Codecov / codecov/patch

paddlenlp/transformers/chatglm_v2/modeling.py#L125

Added line #L125 was not covered by tests
# cache = cache.bfloat16() if dtype == paddle.bfloat16 else cache.astype("float16")
return cache

Expand Down
Loading