-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 #714
base: master
Are you sure you want to change the base?
Conversation
@@ -17,7 +17,7 @@ In the backward pass, the gradients flow to both, handled by different kernels | |||
// CUDA kernels | |||
|
|||
__global__ void encoder_forward_kernel3(floatX* out, | |||
const int* inp, const floatX* wte, const floatX* wpe, | |||
const int* inp, const floatX* wte, const floatX* wpe, int use_rope, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't like this because use_rope
has nothing to do with this encoding function, which we want to be nice and modular and self-contained. Maybe something like use_positional
or something like that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
agree, can refactor a few of those bits quickly
I tried this branch on HPRC, it did not reach the lowest loss you had. #!/bin/bash #SBATCH --output=gpt2_train.%j.log #Redirect stdout/err to file Run the training script./train_gpt2cu -i "dev/data/fineweb10B/fineweb_train_.bin" -j "dev/data/fineweb10B/fineweb_val_.bin" -o log124M -e "d12" -b 32 -t 1024 -d 524288 -r 0 -z 1 -c 0.1 -l 0.0006 -q 0.0 -u 700 -n 5000 -v 250 -s 20000 -h 1 |
Implemented RoPE - rotary position embedding from the RoFormer paper.
Note:
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).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:
Conclusions: