MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / ggml_opt_epoch

Function ggml_opt_epoch

subprojects/llama.cpp/ggml/src/ggml-opt.cpp:880–923  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

878// ====== High-Level Functions ======
879
880void ggml_opt_epoch(
881 ggml_opt_context_t opt_ctx,
882 ggml_opt_dataset_t dataset,
883 ggml_opt_result_t result_train,
884 ggml_opt_result_t result_eval,
885 int64_t idata_split,
886 ggml_opt_epoch_callback callback_train,
887 ggml_opt_epoch_callback callback_eval) {
888 GGML_ASSERT(ggml_opt_static_graphs(opt_ctx) && "ggml_opt_epoch requires static graphs");
889 struct ggml_tensor * inputs = ggml_opt_inputs(opt_ctx);
890 struct ggml_tensor * labels = ggml_opt_labels(opt_ctx);
891 struct ggml_tensor * data = ggml_opt_dataset_data(dataset);
892 GGML_ASSERT(data->ne[0] == inputs->ne[0]);
893
894 const int64_t ndata = data->ne[1];
895 const int64_t ndata_batch = inputs->ne[1];
896
897 GGML_ASSERT(data->ne[1] % inputs->ne[1] == 0);
898 const int64_t nbatches = ndata/ndata_batch;
899
900 idata_split = idata_split < 0 ? ndata : idata_split;
901 GGML_ASSERT(idata_split % ndata_batch == 0);
902 const int64_t ibatch_split = idata_split / ndata_batch;
903
904 int64_t ibatch = 0;
905 int64_t t_loop_start = ggml_time_us();
906 for (; ibatch < ibatch_split; ++ibatch) {
907 ggml_opt_alloc(opt_ctx, /*backward =*/ true);
908 ggml_opt_dataset_get_batch(dataset, inputs, labels, ibatch);
909 ggml_opt_eval(opt_ctx, result_train);
910 if (callback_train) {
911 callback_train(true, opt_ctx, dataset, result_train, ibatch+1, ibatch_split, t_loop_start);
912 }
913 }
914 t_loop_start = ggml_time_us();
915 for (; ibatch < nbatches; ++ibatch) {
916 ggml_opt_alloc(opt_ctx, /*backward =*/ false);
917 ggml_opt_dataset_get_batch(dataset, inputs, labels, ibatch);
918 ggml_opt_eval(opt_ctx, result_eval);
919 if (callback_eval) {
920 callback_eval(false, opt_ctx, dataset, result_eval, ibatch+1-ibatch_split, nbatches-ibatch_split, t_loop_start);
921 }
922 }
923}
924
925void ggml_opt_epoch_callback_progress_bar(
926 bool train,

Callers 4

test_forward_backwardFunction · 0.85
test_epoch_vs_fitFunction · 0.85
test_idata_splitFunction · 0.85
ggml_opt_fitFunction · 0.85

Calls 8

ggml_opt_static_graphsFunction · 0.85
ggml_opt_inputsFunction · 0.85
ggml_opt_labelsFunction · 0.85
ggml_opt_dataset_dataFunction · 0.85
ggml_time_usFunction · 0.85
ggml_opt_allocFunction · 0.85
ggml_opt_evalFunction · 0.85

Tested by 3

test_forward_backwardFunction · 0.68
test_epoch_vs_fitFunction · 0.68
test_idata_splitFunction · 0.68