Skip to content

Commit

Permalink
Merge pull request karpathy#225 from dagelf/master
Browse files Browse the repository at this point in the history
Make msvc compile by adding the ifdefs back in gelu_backward, fixes karpathy#200
  • Loading branch information
karpathy authored Apr 22, 2024
2 parents 451c1a4 + 2efac66 commit 896f83f
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions train_gpt2.c
Original file line number Diff line number Diff line change
Expand Up @@ -364,8 +364,10 @@ void gelu_forward(float* out, float* inp, int N) {
}

// we want to use -Ofast optimization, but sadly GeLU breaks, so disable this flag just for it (#168)
#pragma float_control(precise, on, push) // On msvc /fp:fast is a lot faster, but the expf inside coshf breaks the model
__attribute__((optimize("no-finite-math-only"))) // same for gcc -Ofast
#pragma float_control(precise, on, push)
#if defined(__GNUC__) && !defined(__clang__)
__attribute__((optimize("no-finite-math-only")))
#endif
void gelu_backward(float* dinp, float* inp, float* dout, int N) {
for (int i = 0; i < N; i++) {
float x = inp[i];
Expand Down

0 comments on commit 896f83f

Please sign in to comment.