MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / test_idata_split

Function test_idata_split

external/ggml/tests/test-opt.cpp:514–603  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

512}
513
514static std::pair<int, int> test_idata_split(
515 enum ggml_opt_optimizer_type optim,
516 ggml_backend_sched_t backend_sched, ggml_backend_t backend, const bool high_level) {
517 int ntest = 0;
518 int npass = 0;
519
520 struct helper_ctx_data cd = helper_get_ctx_data(optim, backend_sched, backend, /*init_opt_ctx =*/ true, /*optimizer_defaults =*/ false);
521 struct ggml_tensor * loss = ggml_opt_loss(cd.opt_ctx);
522 const int idata_split = ndata * 2/3;
523
524 std::vector<float> loss_history(ndata);
525 for (int64_t idata = 0; idata < ndata; ++idata) {
526 loss_history[idata] = NAN;
527 }
528
529 bool const adamw = optim == GGML_OPT_OPTIMIZER_TYPE_ADAMW;
530 for (int epoch = 1; epoch <= 4; ++epoch) {
531 if (high_level) {
532 ggml_opt_epoch(cd.opt_ctx, cd.dataset_unsupervised, cd.result, cd.result2, idata_split, nullptr, nullptr);
533 } else {
534 int idata = 0;
535 for (; idata < idata_split; ++idata) {
536 const float idataf = idata;
537 ggml_opt_alloc(cd.opt_ctx, /*backward =*/ true);
538 ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
539 ggml_opt_eval(cd.opt_ctx, cd.result);
540 ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
541 }
542 for (; idata < ndata; ++idata) {
543 const float idataf = idata;
544 ggml_opt_alloc(cd.opt_ctx, /*backward =*/ false);
545 ggml_backend_tensor_set(cd.inputs, &idataf, 0, ggml_nbytes(cd.inputs));
546 ggml_opt_eval(cd.opt_ctx, cd.result2);
547 ggml_backend_tensor_get(loss, loss_history.data() + idata, 0, sizeof(float));
548 }
549 }
550
551 if (adamw) {
552 float weights;
553 ggml_backend_tensor_get(cd.weights, &weights, 0, sizeof(float));
554 const bool subtest_ok = almost_equal(weights, ndata/2 - epoch*idata_split, 1e-10);
555 helper_after_test_idata_split(optim, __func__, high_level, epoch, "weights", subtest_ok, ntest, npass);
556 }
557 if (adamw) {
558 constexpr double atol = 1e-10;
559
560 int64_t ndata_result;
561 ggml_opt_result_ndata(cd.result, &ndata_result);
562 bool subtest_ok = ndata_result == idata_split;
563
564 double loss;
565 double loss_unc;
566 ggml_opt_result_loss(cd.result, &loss, &loss_unc);
567 subtest_ok = subtest_ok && almost_equal(loss, 28.0 - epoch*16.0, atol) && almost_equal(loss_unc, 0.0, atol);
568
569 double accuracy;
570 double accuracy_unc;
571 ggml_opt_result_accuracy(cd.result, &accuracy, &accuracy_unc);

Callers 1

test_backendFunction · 0.85

Calls 15

helper_get_ctx_dataFunction · 0.85
ggml_opt_lossFunction · 0.85
ggml_opt_epochFunction · 0.85
ggml_opt_allocFunction · 0.85
ggml_backend_tensor_setFunction · 0.85
ggml_nbytesFunction · 0.85
ggml_opt_evalFunction · 0.85
ggml_backend_tensor_getFunction · 0.85
almost_equalFunction · 0.85
ggml_opt_result_ndataFunction · 0.85
ggml_opt_result_lossFunction · 0.85

Tested by

no test coverage detected