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

Method opt_epoch_iter

subprojects/llama.cpp/src/llama-context.cpp:2790–2897  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2788}
2789
2790void llama_context::opt_epoch_iter(
2791 ggml_opt_dataset_t dataset,
2792 ggml_opt_result_t result,
2793 const std::vector<llama_token> & tokens,
2794 const std::vector<llama_token> & labels_sparse,
2795 llama_batch & batch,
2796 ggml_opt_epoch_callback callback,
2797 bool train,
2798 int64_t idata_in_loop,
2799 int64_t ndata_in_loop,
2800 int64_t t_loop_start) {
2801 GGML_ASSERT(opt_ctx);
2802 const uint32_t n_ctx = llama_model_n_ctx_train(&model);
2803 const uint32_t n_batch = std::min(this->n_batch(), n_ctx);
2804 const uint32_t n_ubatch = std::min(this->n_ubatch(), n_batch);
2805
2806 memory->clear(true);
2807
2808 for (uint32_t pos_ctx = 0; pos_ctx < n_ctx; pos_ctx += n_batch) {
2809 batch.n_tokens = n_batch;
2810 for (uint32_t pos_batch = 0; pos_batch < n_batch; ++pos_batch) {
2811 batch.token [pos_batch] = tokens[pos_ctx + pos_batch];
2812 batch.pos [pos_batch] = pos_ctx + pos_batch;
2813 batch.n_seq_id[pos_batch] = 1;
2814 batch.seq_id [pos_batch][0] = 0;
2815 batch.logits [pos_batch] = true;
2816 }
2817
2818 if (!balloc->init(batch, model.vocab, nullptr, model.hparams.n_embd_inp(), cparams.kv_unified ? LLAMA_MAX_SEQ : cparams.n_seq_max, true)) {
2819 LLAMA_LOG_ERROR("%s: failed to initialize batch\n", __func__);
2820 return;
2821 }
2822
2823 const uint32_t n_tokens_all = balloc->get_n_tokens();
2824
2825 n_queued_tokens += n_tokens_all;
2826
2827 embd_seq.clear();
2828
2829 uint32_t n_outputs_all = n_tokens_all;
2830
2831 auto mctx = memory->init_batch(*balloc, cparams.n_ubatch, true);
2832 if (!mctx || mctx->get_status() != LLAMA_MEMORY_STATUS_SUCCESS) {
2833 LLAMA_LOG_ERROR("%s: could not initialize batch\n", __func__);
2834 break;
2835 }
2836
2837 // reserve output buffer
2838 if (output_reserve(n_outputs_all) < n_outputs_all) {
2839 LLAMA_LOG_ERROR("%s: could not reserve space for batch with %d outputs\n", __func__, n_outputs_all);
2840 GGML_ABORT("TODO: handle this error");
2841 };
2842
2843 uint32_t pos_batch = 0;
2844 do {
2845 const auto & ubatch = mctx->get_ubatch();
2846
2847 n_outputs = ubatch.n_tokens;

Callers

nothing calls this directly

Calls 15

n_batchMethod · 0.95
n_ubatchMethod · 0.95
llama_model_n_ctx_trainFunction · 0.85
minFunction · 0.85
ggml_graph_sizeFunction · 0.85
ggml_tensor_overheadFunction · 0.85
ggml_initFunction · 0.85
ggml_opt_prepare_allocFunction · 0.85
ggml_opt_allocFunction · 0.85
ggml_opt_labelsFunction · 0.85
ggml_set_zeroFunction · 0.85

Tested by

no test coverage detected