Skip to content

Commit

Permalink
change fabs to fabsf
Browse files Browse the repository at this point in the history
  • Loading branch information
karpathy committed Apr 10, 2024
1 parent add9e77 commit e1e0a08
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions test_gpt2.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int check_tensor(float *a, float *b, int n, char* label) {
int ok = 1;
printf("%s\n", label);
for (int i = 0; i < n; i++) {
if (fabs(a[i] - b[i]) <= 1e-2) {
if (fabsf(a[i] - b[i]) <= 1e-2) {
if (i < print_upto) { printf("OK "); }
} else {
if (i < print_upto) { printf("NOT OK "); }
Expand Down Expand Up @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) {
if(i < 3) {
printf("%f %f\n", expected_logits[i], model.acts.logits[i]);
}
if (fabs(expected_logits[i] - model.acts.logits[i]) >= 1e-2) {
if (fabsf(expected_logits[i] - model.acts.logits[i]) >= 1e-2) {
printf("MISMATCH AT INDEX %d: ", i);
printf("%f %f\n", expected_logits[i],model.acts.logits[i]);
logits_ok = 0;
Expand All @@ -103,7 +103,7 @@ int main(int argc, char *argv[]) {
allok = allok && logits_ok;

// compare the achieved loss
if (fabs(model.mean_loss - *expected_loss) >= 1e-2) {
if (fabsf(model.mean_loss - *expected_loss) >= 1e-2) {
printf("LOSS MISMATCH: %f %f\n", model.mean_loss, *expected_loss);
allok = 0;
} else {
Expand Down Expand Up @@ -156,7 +156,7 @@ int main(int argc, char *argv[]) {
};
// compare
for (int i = 0; i < 10; i++) {
if (fabs(losses[i] - expected_losses[i]) >= 1e-2) {
if (fabsf(losses[i] - expected_losses[i]) >= 1e-2) {
printf("LOSS MISMATCH AT STEP %d: %f %f\n", i, losses[i], expected_losses[i]);
allok = 0;
} else {
Expand Down
6 changes: 3 additions & 3 deletions test_gpt2.cu
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ int check_tensor(float *a, float *b, int n, char* label) {
int ok = 1;
printf("%s\n", label);
for (int i = 0; i < n; i++) {
if (fabs(a[i] - b[i]) <= 1e-2) {
if (fabsf(a[i] - b[i]) <= 1e-2) {
if (i < print_upto) { printf("OK "); }
} else {
if (i < print_upto) { printf("NOT OK "); }
Expand Down Expand Up @@ -89,7 +89,7 @@ int main(int argc, char *argv[]) {
if(i < 3) {
printf("%f %f\n", expected_logits[i], logits_cpu[i]);
}
if (fabs(expected_logits[i] - logits_cpu[i]) >= 1e-2) {
if (fabsf(expected_logits[i] - logits_cpu[i]) >= 1e-2) {
printf("MISMATCH AT INDEX %d: ", i);
printf("%f %f\n", expected_logits[i],logits_cpu[i]);
logits_ok = 0;
Expand All @@ -102,7 +102,7 @@ int main(int argc, char *argv[]) {
free(logits_cpu);

// compare the achieved loss
if (fabs(model.mean_loss - *expected_loss) >= 1e-2) {
if (fabsf(model.mean_loss - *expected_loss) >= 1e-2) {
printf("LOSS MISMATCH: %f %f\n", model.mean_loss, *expected_loss);
allok = 0;
} else {
Expand Down

0 comments on commit e1e0a08

Please sign in to comment.