llama : migrate to llama_batch_ext (#32356)
* llama : migrate to llama_batch_ext * mtmd : migrate zonos3-mini code Added in https://github.com/ggml-org/llama.cpp/pull/32020
This commit is contained in:
1 parent
ef3848f9d7
commit
62a6d3a302
8 files changed
+146
-169
No files matched your search
+13
-16
@@ -4254,7 +4254,7 @@ void llama_context::opt_epoch_iter(
|
||||
ggml_opt_result_t result,
|
||||
const std::vector<llama_token> & tokens,
|
||||
const std::vector<llama_token> & labels_sparse,
|
||||
llama_batch & batch,
|
||||
llama_batch_ext & batch,
|
||||
ggml_opt_epoch_callback callback,
|
||||
bool train,
|
||||
int64_t idata_in_loop,
|
||||
@@ -4268,22 +4268,21 @@ void llama_context::opt_epoch_iter(
|
||||
memory->clear(true);
|
||||
|
||||
for (uint32_t pos_ctx = 0; pos_ctx < n_ctx; pos_ctx += n_batch) {
|
||||
batch.n_tokens = n_batch;
|
||||
batch.clear();
|
||||
for (uint32_t pos_batch = 0; pos_batch < n_batch; ++pos_batch) {
|
||||
batch.token [pos_batch] = tokens[pos_ctx + pos_batch];
|
||||
batch.pos [pos_batch] = pos_ctx + pos_batch;
|
||||
batch.n_seq_id[pos_batch] = 1;
|
||||
batch.seq_id [pos_batch][0] = 0;
|
||||
batch.logits [pos_batch] = true;
|
||||
}
|
||||
|
||||
// TODO: use llama_batch_ext here
|
||||
{
|
||||
llama_batch_compat compat(this, batch);
|
||||
if (!balloc->init(*compat.batch_ext, model.vocab, true)) {
|
||||
const int32_t idx = batch.add_token(0);
|
||||
const llama_pos pos = pos_ctx + pos_batch;
|
||||
if (idx < 0 || !batch.set_token_id(idx, tokens[pos_ctx + pos_batch])) {
|
||||
LLAMA_LOG_ERROR("%s: failed to initialize batch\n", __func__);
|
||||
return;
|
||||
}
|
||||
batch.set_token_pos(idx, &pos);
|
||||
batch.set_output(idx, true);
|
||||
}
|
||||
|
||||
if (!balloc->init(batch, model.vocab, true)) {
|
||||
LLAMA_LOG_ERROR("%s: failed to initialize batch\n", __func__);
|
||||
return;
|
||||
}
|
||||
|
||||
const uint32_t n_tokens_all = balloc->get_n_tokens();
|
||||
@@ -4382,7 +4381,7 @@ void llama_context::opt_epoch(
|
||||
|
||||
const uint32_t ubatch_per_ctx = n_ctx / n_ubatch;
|
||||
|
||||
struct llama_batch batch = llama_batch_init(n_batch, 0, 1);
|
||||
llama_batch_ext batch(this);
|
||||
std::vector<llama_token> tokens(n_ctx);
|
||||
std::vector<llama_token> labels_sparse(n_ctx);
|
||||
|
||||
@@ -4409,8 +4408,6 @@ void llama_context::opt_epoch(
|
||||
opt_epoch_iter(dataset, result_eval, tokens, labels_sparse, batch,
|
||||
callback_eval, train, idata_in_loop, ndata_in_loop, t_loop_start);
|
||||
}
|
||||
|
||||
llama_batch_free(batch);
|
||||
}
|
||||
|
||||
//
|
||||
|
||||
Reference in new issue
Block a user