@@ -358,7 +358,7 @@ static std::pair<int, int> test_forward_backward(
358
358
double accuracy;
359
359
double accuracy_unc;
360
360
ggml_opt_result_accuracy (cd.result , &accuracy, &accuracy_unc);
361
- const bool subtest_ok = ndata == 0 && loss == 0.0 && std::isnan (loss_unc) && std::isnan (accuracy) && std::isnan (accuracy_unc);
361
+ const bool subtest_ok = ndata == 0 && almost_equal ( loss, 0.0 , 1e-6 ) && std::isnan (loss_unc) && std::isnan (accuracy) && std::isnan (accuracy_unc);
362
362
helper_after_test_forward_backward (optim, __func__, high_level, shuffle, " results_initial" , subtest_ok, ntest, npass);
363
363
}
364
364
@@ -381,18 +381,20 @@ static std::pair<int, int> test_forward_backward(
381
381
{
382
382
float weights;
383
383
ggml_backend_tensor_get (cd.weights , &weights, 0 , sizeof (float ));
384
- const bool subtest_ok = weights == ndata/2 ;
384
+ const bool subtest_ok = almost_equal ( weights, ndata/2 , 1e-10 ) ;
385
385
helper_after_test_forward_backward (optim, __func__, high_level, shuffle, " weights_after_forward" , subtest_ok, ntest, npass);
386
386
}
387
387
{
388
+ constexpr double atol = 1e-10 ;
389
+
388
390
int64_t ndata;
389
391
ggml_opt_result_ndata (cd.result , &ndata);
390
392
bool subtest_ok = ndata == 6 ;
391
393
392
394
double loss;
393
395
double loss_unc;
394
396
ggml_opt_result_loss (cd.result , &loss, &loss_unc);
395
- subtest_ok = subtest_ok && loss == 33.0 && almost_equal (loss_unc, sqrt (3.5 ), 1e-10 );
397
+ subtest_ok = subtest_ok && almost_equal ( loss, 33.0 , atol) && almost_equal (loss_unc, sqrt (3.5 ), atol );
396
398
397
399
double accuracy;
398
400
double accuracy_unc;
@@ -437,7 +439,7 @@ static std::pair<int, int> test_forward_backward(
437
439
{
438
440
float weights;
439
441
ggml_backend_tensor_get (cd.weights , &weights, 0 , sizeof (float ));
440
- const bool subtest_ok = weights == -ndata * . 5 ;
442
+ const bool subtest_ok = almost_equal ( weights, -ndata * 0.5 , 1e-10 ) ;
441
443
helper_after_test_forward_backward (optim, __func__, high_level, shuffle, " weights_after_forward_backward" , subtest_ok, ntest, npass);
442
444
}
443
445
{
@@ -448,7 +450,7 @@ static std::pair<int, int> test_forward_backward(
448
450
double loss;
449
451
double loss_unc;
450
452
ggml_opt_result_loss (cd.result , &loss, &loss_unc);
451
- subtest_ok = subtest_ok && loss == 18.0 && (shuffle || loss_unc == 0.0 );
453
+ subtest_ok = subtest_ok && almost_equal ( loss, 18.0 , 1e-10 ) && (shuffle || loss_unc == 0.0 );
452
454
453
455
double accuracy;
454
456
double accuracy_unc;
@@ -550,18 +552,20 @@ static std::pair<int, int> test_idata_split(
550
552
if (adamw) {
551
553
float weights;
552
554
ggml_backend_tensor_get (cd.weights , &weights, 0 , sizeof (float ));
553
- const bool subtest_ok = weights == ndata/2 - epoch*idata_split;
555
+ const bool subtest_ok = almost_equal ( weights, ndata/2 - epoch*idata_split, 1e-10 ) ;
554
556
helper_after_test_idata_split (optim, __func__, high_level, epoch, " weights" , subtest_ok, ntest, npass);
555
557
}
556
558
if (adamw) {
559
+ constexpr double atol = 1e-10 ;
560
+
557
561
int64_t ndata_result;
558
562
ggml_opt_result_ndata (cd.result , &ndata_result);
559
563
bool subtest_ok = ndata_result == idata_split;
560
564
561
565
double loss;
562
566
double loss_unc;
563
567
ggml_opt_result_loss (cd.result , &loss, &loss_unc);
564
- subtest_ok = subtest_ok && loss == 28.0 - epoch*16.0 && loss_unc == 0.0 ;
568
+ subtest_ok = subtest_ok && almost_equal ( loss, 28.0 - epoch*16.0 , atol) && almost_equal ( loss_unc, 0.0 , atol) ;
565
569
566
570
double accuracy;
567
571
double accuracy_unc;
@@ -571,14 +575,16 @@ static std::pair<int, int> test_idata_split(
571
575
helper_after_test_idata_split (optim, __func__, high_level, epoch, " results_backward" , subtest_ok, ntest, npass);
572
576
}
573
577
if (adamw) {
578
+ constexpr double atol = 1e-10 ;
579
+
574
580
int64_t ndata_result;
575
581
ggml_opt_result_ndata (cd.result2 , &ndata_result);
576
582
bool subtest_ok = ndata_result == ndata - idata_split;
577
583
578
584
double loss;
579
585
double loss_unc;
580
586
ggml_opt_result_loss (cd.result2 , &loss, &loss_unc);
581
- subtest_ok = subtest_ok && loss == 15.0 - epoch*8 && almost_equal (loss_unc, sqrt (0.5 ), 1e-10 );
587
+ subtest_ok = subtest_ok && almost_equal ( loss, 15.0 - epoch*8 , atol) && almost_equal (loss_unc, sqrt (0.5 ), atol );
582
588
583
589
double accuracy;
584
590
double accuracy_unc;
@@ -687,22 +693,24 @@ static std::pair<int, int> test_gradient_accumulation(
687
693
}
688
694
bool const adamw = optim == GGML_OPT_OPTIMIZER_TYPE_ADAMW;
689
695
if (adamw) {
696
+ constexpr double atol = 1e-6 ;
690
697
float weights;
691
698
ggml_backend_tensor_get (cd.weights , &weights, 0 , sizeof (float ));
692
- const bool subtest_ok = weights == (ndata/2 ) - epoch;
699
+ const bool subtest_ok = almost_equal ( weights, (ndata/2 ) - epoch, atol) ;
693
700
helper_after_test_gradient_accumulation (optim, __func__, nbatch_physical, loss_type, epoch, " weights" , subtest_ok, ntest, npass);
694
701
}
695
702
{
703
+ constexpr double atol = 1e-6 ;
696
704
int64_t ndata_result;
697
705
ggml_opt_result_ndata (cd.result , &ndata_result);
698
- bool subtest_ok = ndata_result == ndata/nbatch_physical;
706
+ bool subtest_ok = almost_equal ( ndata_result, ndata/nbatch_physical, atol) ;
699
707
700
708
double loss;
701
709
ggml_opt_result_loss (cd.result , &loss, /* loss_unc =*/ nullptr );
702
710
if (loss_type == GGML_OPT_LOSS_TYPE_SUM) {
703
- subtest_ok = subtest_ok && loss == (39.0 - epoch*6.0 );
711
+ subtest_ok = subtest_ok && almost_equal ( loss, (39.0 - epoch*6.0 ), atol );
704
712
} else if (loss_type == GGML_OPT_LOSS_TYPE_MEAN) {
705
- subtest_ok = subtest_ok && almost_equal (loss, (39.0 - epoch*6.0 ) / ndata, 1e-6 );
713
+ subtest_ok = subtest_ok && almost_equal (loss, (39.0 - epoch*6.0 ) / ndata, atol );
706
714
} else {
707
715
GGML_ASSERT (false );
708
716
}
0 commit comments