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

Add RoPE positional encoding - llama3 feature branch #756

Open
wants to merge 15 commits into
base: llama3
Choose a base branch
from

Conversation

gordicaleksa
Copy link
Contributor

Implemented RoPE - rotary position embedding from the RoFormer paper.

Note:

  1. I do not conditionally remove the allocation of our learnable position embedding buffer (wpe) as that would require touching many parts of the codebase that rely on the particular order inside the parameter buffer (e.g. wpe has index 1).
  2. I do turn off fwd/bwd computation / grad norm computation / update for the wpe buffer.
    The explicit tradeoff is: suffer a minimal memory bloat (maxT * C) but the PR has minimal impact on the readability of the codebase.

Tests:
I ran an A/B experiment: trained a 124M GPT-2 on 10B tokens (FineWeb subset) with:
a) learnable positional embeddings (default, -er == 0)
b) RoPE (-er == 1)
c) no positional embedding at all
all other settings being the same same.

Results:
image

Conclusions:

  • The validation loss is significantly better with RoPE
  • RoPE implementation slightly decresed the performance (consistent with what EleutherAI folks observed). I observed a drop ~1_632_000 -> ~1_603_000 tok/s (~1.7% perf hit).

@ademeure
Copy link
Contributor

ademeure commented Sep 13, 2024

LGTM, we could reduce the number of GPU instructions for the kernels a bit by moving use_rope to being known at compile time, but it's debatable whether that's worth the small compile time increase of having more kernel versions given the kernel should be DRAM limited, see: https://godbolt.org/z/es6GzeePq

(it turns out the bigger optimisation by far is using a 3D grid to get rid of modulus/division/etc. for btc calculation, which is orthogonal and doesn't really belong in this PR)

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

Successfully merging this pull request may close these issues.

2 participants