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