Skip to content

Commit 9267a13

Browse files
committed
common : include llama_encode() in model warm-up sequence
1 parent caca54c commit 9267a13

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Diff for: common/common.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -2364,7 +2364,18 @@ std::tuple<struct llama_model *, struct llama_context *> llama_init_from_gpt_par
23642364
if (params.warmup) {
23652365
LOG("warming up the model with an empty run\n");
23662366

2367-
std::vector<llama_token> tmp = { llama_token_bos(model), llama_token_eos(model), };
2367+
std::vector<llama_token> tmp;
2368+
llama_token bos = llama_token_bos(model);
2369+
llama_token eos = llama_token_eos(model);
2370+
// some models (e.g. T5) don't have a BOS token
2371+
if (bos != -1) {
2372+
tmp.push_back(bos);
2373+
}
2374+
tmp.push_back(eos);
2375+
2376+
if (llama_model_has_encoder(model)) {
2377+
llama_encode(lctx, llama_batch_get_one(tmp.data(), tmp.size(), 0, 0));
2378+
}
23682379
llama_decode(lctx, llama_batch_get_one(tmp.data(), std::min(tmp.size(), (size_t) params.n_batch), 0, 0));
23692380
llama_kv_cache_clear(lctx);
23702381
llama_synchronize(lctx);

Diff for: examples/main/main.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ int main(int argc, char ** argv) {
193193
g_model = &model;
194194
g_ctx = &ctx;
195195

196-
params.warmup = false;
197-
198196
// load the model and apply lora adapter, if any
199197
LOG("%s: load the model and apply lora adapter, if any\n", __func__);
200198
std::tie(model, ctx) = llama_init_from_gpt_params(params);

0 commit comments

Comments
 (0)