MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / ggml_opt_dataset_get_batch

Function ggml_opt_dataset_get_batch

smallthinker/ggml/src/ggml-opt.cpp:161–192  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

159}
160
161void ggml_opt_dataset_get_batch(ggml_opt_dataset_t dataset, struct ggml_tensor * data_batch, struct ggml_tensor * labels_batch, int64_t ibatch) {
162 GGML_ASSERT( data_batch && ggml_is_contiguous(data_batch));
163 GGML_ASSERT(!labels_batch || ggml_is_contiguous(labels_batch));
164 GGML_ASSERT((labels_batch == nullptr) == (dataset->labels == nullptr));
165 GGML_ASSERT( data_batch->type == dataset->data->type);
166 GGML_ASSERT(!labels_batch || labels_batch->type == dataset->labels->type);
167
168 const size_t nb_data_batch = ggml_nbytes(data_batch);
169 GGML_ASSERT(nb_data_batch % dataset->nbs_data == 0);
170 const int64_t shards_per_batch = nb_data_batch / dataset->nbs_data;
171
172 if (labels_batch) {
173 const size_t nb_labels_batch = ggml_nbytes(labels_batch);
174 GGML_ASSERT(nb_labels_batch == shards_per_batch*dataset->nbs_labels);
175 }
176
177 GGML_ASSERT((ibatch + 1)*shards_per_batch <= int64_t(dataset->permutation.size()));
178
179 for (int64_t ishard_batch = 0; ishard_batch < shards_per_batch; ++ishard_batch) {
180 const int64_t ishard = dataset->permutation[ibatch*shards_per_batch + ishard_batch];
181
182 const char * ptr_data = (const char *) dataset->data->data + ishard*dataset->nbs_data;
183 ggml_backend_tensor_set(data_batch, ptr_data, ishard_batch*dataset->nbs_data, dataset->nbs_data);
184
185 if (!labels_batch) {
186 continue;
187 }
188
189 const char * ptr_labels = (const char *) dataset->labels->data + ishard*dataset->nbs_labels;
190 ggml_backend_tensor_set(labels_batch, ptr_labels, ishard_batch*dataset->nbs_labels, dataset->nbs_labels);
191 }
192}
193
194void ggml_opt_dataset_get_batch_host(ggml_opt_dataset_t dataset, void * data_batch, size_t nb_data_batch, void * labels_batch, int64_t ibatch) {
195 GGML_ASSERT((labels_batch == nullptr) == (dataset->labels == nullptr));

Callers 2

test_datasetFunction · 0.85
ggml_opt_epochFunction · 0.85

Calls 4

ggml_is_contiguousFunction · 0.70
ggml_nbytesFunction · 0.70
ggml_backend_tensor_setFunction · 0.70
sizeMethod · 0.45

Tested by 1

test_datasetFunction · 0.68