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

Implementation of RoPE in YOCO #1554

Closed
nkkbr opened this issue May 19, 2024 · 1 comment
Closed

Implementation of RoPE in YOCO #1554

nkkbr opened this issue May 19, 2024 · 1 comment
Assignees

Comments

@nkkbr
Copy link

nkkbr commented May 19, 2024

In this file:

YOCO/yoco/models/decoder/yoco.py

RoPE was implemented as:

    def build_rel_pos(self, x, start_pos):
        if self._precomputed_freqs_cis is None:
            angle = 1.0 / (self.args.rope_theta ** torch.linspace(0, 1, self.head_dim // 2, dtype=torch.float, device=x.device))
            index = torch.arange(self.args.max_seq_len).to(angle)
            self._precomputed_freqs_cis = index[:, None] * angle

        cos = torch.cos(self._precomputed_freqs_cis[start_pos:start_pos+x.size(1)])
        sin = torch.sin(self._precomputed_freqs_cis[start_pos:start_pos+x.size(1)])
        rel_pos = (cos.to(x.dtype), sin.to(x.dtype))
        return rel_pos

I wonder if the angle should be:

angle = 1.0 / (self.args.rope_theta ** torch.linspace(0, 1, self.head_dim // 2 + 1, dtype=torch.float, device=x.device))
angle = angle[:-1]
@sunyt32
Copy link

sunyt32 commented May 19, 2024

In practice, the performance is almost the same between these two implementations. We use torch.linspace for simplicity.

@donglixp donglixp self-assigned this May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants