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

Function helper_get_ctx_data

subprojects/llama.cpp/tests/test-opt.cpp:59–159  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

57}
58
59static helper_ctx_data helper_get_ctx_data(
60 enum ggml_opt_optimizer_type optim,
61 ggml_backend_sched_t backend_sched,
62 ggml_backend_t backend,
63 const bool init_opt_ctx = true,
64 const bool optimizer_defaults = true,
65 int64_t nbatch_logical = 1,
66 int64_t nbatch_physical = 1,
67 enum ggml_opt_loss_type loss_type = GGML_OPT_LOSS_TYPE_SUM) {
68 std::vector<ggml_opt_dataset_t> datasets(ndata);
69 for (int64_t ndata_shard = 1; ndata_shard <= ndata; ++ndata_shard) {
70 ggml_opt_dataset_t dataset = ggml_opt_dataset_init(
71 GGML_TYPE_F32, GGML_TYPE_F32, ne_datapoint, ne_label, ndata, ndata_shard);
72
73 float * data = ggml_get_data_f32(ggml_opt_dataset_data( dataset));
74 float * labels = ggml_get_data_f32(ggml_opt_dataset_labels(dataset));
75
76 for (int64_t idata = 0; idata < ndata; ++idata) {
77 for (int64_t id = 0; id < ne_datapoint; ++id) {
78 data[ idata*ne_datapoint + id] = 16*idata + id;
79 }
80 for (int64_t il = 0; il < ne_label; ++il) {
81 labels[idata*ne_label + il] = 16*(16*idata + il);
82 }
83 }
84
85 datasets[ndata_shard-1] = dataset;
86 }
87
88 ggml_opt_dataset_t dataset_unsupervised = ggml_opt_dataset_init(
89 GGML_TYPE_F32, GGML_TYPE_F32, 1, 0, ndata, /*ndata_shard =*/ 1);
90
91 float * data = ggml_get_data_f32(ggml_opt_dataset_data(dataset_unsupervised));
92
93 for (int64_t idata = 0; idata < ndata; ++idata) {
94 data[idata] = idata;
95 }
96
97 struct ggml_context * ctx_static;
98 struct ggml_context * ctx_compute;
99 {
100 struct ggml_init_params params = {
101 /*.mem_size =*/ (2*ndata + 2)*ggml_tensor_overhead(),
102 /*.mem_buffer =*/ nullptr,
103 /*.no_alloc =*/ true,
104 };
105 ctx_static = ggml_init(params);
106 }
107 {
108 struct ggml_init_params params = {
109 /*.mem_size =*/ GGML_DEFAULT_GRAPH_SIZE*ggml_tensor_overhead() + 3*ggml_graph_overhead(),
110 /*.mem_buffer =*/ nullptr,
111 /*.no_alloc =*/ true,
112 };
113 ctx_compute = ggml_init(params);
114 }
115
116 std::vector<struct ggml_tensor *> data_batch(ndata);

Callers 6

test_datasetFunction · 0.85
test_gradFunction · 0.85
test_forward_backwardFunction · 0.85
test_epoch_vs_fitFunction · 0.85
test_idata_splitFunction · 0.85

Calls 15

ggml_opt_dataset_initFunction · 0.85
ggml_get_data_f32Function · 0.85
ggml_opt_dataset_dataFunction · 0.85
ggml_opt_dataset_labelsFunction · 0.85
ggml_tensor_overheadFunction · 0.85
ggml_initFunction · 0.85
ggml_graph_overheadFunction · 0.85
ggml_new_tensor_1dFunction · 0.85
ggml_set_nameFunction · 0.85
ggml_set_paramFunction · 0.85
ggml_addFunction · 0.85
ggml_scaleFunction · 0.85

Tested by

no test coverage detected