MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / ggml_opt_fit

Function ggml_opt_fit

ggml/src/ggml-opt.cpp:999–1079  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

997}
998
999void ggml_opt_fit(
1000 ggml_backend_sched_t backend_sched,
1001 ggml_context * ctx_compute,
1002 ggml_tensor * inputs,
1003 ggml_tensor * outputs,
1004 ggml_opt_dataset_t dataset,
1005 enum ggml_opt_loss_type loss_type,
1006 enum ggml_opt_optimizer_type optimizer,
1007 ggml_opt_get_optimizer_params get_opt_pars,
1008 int64_t nepoch,
1009 int64_t nbatch_logical,
1010 float val_split,
1011 bool silent) {
1012 ggml_time_init();
1013 const int64_t t_start_us = ggml_time_us();
1014
1015 const int64_t ndata = ggml_opt_dataset_data(dataset)->ne[1];
1016 const int64_t nbatch_physical = inputs->ne[1];
1017 GGML_ASSERT(ndata % nbatch_logical == 0);
1018 GGML_ASSERT(nbatch_logical % nbatch_physical == 0);
1019
1020 const int64_t opt_period = nbatch_logical / nbatch_physical;
1021 const int64_t nbatches_logical = ndata / nbatch_logical;
1022
1023 GGML_ASSERT(val_split >= 0.0f);
1024 GGML_ASSERT(val_split < 1.0f);
1025 const int64_t ibatch_split = int64_t(((1.0f - val_split) * nbatches_logical)) * opt_period; // train <-> val split index (physical)
1026 const int64_t idata_split = ibatch_split * nbatch_physical;
1027
1028 int64_t epoch = 1;
1029
1030 ggml_opt_params params = ggml_opt_default_params(backend_sched, loss_type);
1031 params.ctx_compute = ctx_compute;
1032 params.inputs = inputs;
1033 params.outputs = outputs;
1034 params.opt_period = opt_period;
1035 params.get_opt_pars = get_opt_pars;
1036 params.get_opt_pars_ud = &epoch;
1037 params.optimizer = optimizer;
1038 ggml_opt_context_t opt_ctx = ggml_opt_init(params);
1039
1040 // Shuffling the data is generally useful but there is only a point if not all data is used in a single batch.
1041 if (nbatch_logical < ndata) {
1042 ggml_opt_dataset_shuffle(opt_ctx, dataset, -1); // Shuffle all data (train + validation).
1043 }
1044
1045 ggml_opt_result_t result_train = ggml_opt_result_init();
1046 ggml_opt_result_t result_val = ggml_opt_result_init();
1047
1048 ggml_opt_epoch_callback epoch_callback = silent ? nullptr : ggml_opt_epoch_callback_progress_bar;
1049
1050 for (; epoch <= nepoch; ++epoch) {
1051 if (nbatch_logical < idata_split) {
1052 ggml_opt_dataset_shuffle(opt_ctx, dataset, idata_split);
1053 }
1054
1055 ggml_opt_result_reset(result_train);
1056 ggml_opt_result_reset(result_val);

Callers 2

test_epoch_vs_fitFunction · 0.85
test_regressionFunction · 0.85

Calls 11

ggml_time_initFunction · 0.85
ggml_time_usFunction · 0.85
ggml_opt_dataset_dataFunction · 0.85
ggml_opt_default_paramsFunction · 0.85
ggml_opt_initFunction · 0.85
ggml_opt_dataset_shuffleFunction · 0.85
ggml_opt_result_initFunction · 0.85
ggml_opt_result_resetFunction · 0.85
ggml_opt_epochFunction · 0.85
ggml_opt_freeFunction · 0.85
ggml_opt_result_freeFunction · 0.85

Tested by 2

test_epoch_vs_fitFunction · 0.68
test_regressionFunction · 0.68