@@ -1390,8 +1390,6 @@ common_init_result_ptr common_init_from_params(common_params & params, bool mode
13901390 if (params.warmup ) {
13911391 LOG_INF (" %s: warming up the model with an empty run - please wait ... (--no-warmup to disable)\n " , __func__);
13921392
1393- llama_set_warmup (lctx, true );
1394-
13951393 std::vector<llama_token> tmp;
13961394 llama_token bos = llama_vocab_bos (vocab);
13971395 llama_token eos = llama_vocab_eos (vocab);
@@ -1422,7 +1420,6 @@ common_init_result_ptr common_init_from_params(common_params & params, bool mode
14221420 llama_memory_clear (llama_get_memory (lctx), true );
14231421 llama_synchronize (lctx);
14241422 llama_perf_context_reset (lctx);
1425- llama_set_warmup (lctx, false );
14261423
14271424 // reset samplers to reset RNG state after warmup to the seeded state
14281425 res->reset_samplers ();
@@ -2011,36 +2008,37 @@ bool common_replay_last_token(struct llama_context * ctx, llama_token last_token
20112008
20122009bool common_prompt_batch_decode (
20132010 struct llama_context * ctx,
2014- const std::vector<llama_token> & tokens,
2011+ const std::vector<llama_token> & all_tokens,
2012+ int n_new,
20152013 int & n_past,
20162014 int n_batch,
20172015 std::string_view state_path,
20182016 bool save_state) {
2019- const int n_eval = tokens.size ();
2020- if (n_eval == 0 ) {
2017+ if (n_new == 0 ) {
20212018 return true ;
20222019 }
2020+ const int offset = all_tokens.size () - n_new;
20232021
2024- if (save_state && n_eval > 1 ) {
2025- const int n_tokens_before_last = n_eval - 1 ;
2022+ if (save_state && n_new > 1 ) {
2023+ const int n_tokens_before_last = n_new - 1 ;
20262024
2027- GGML_ASSERT (n_eval <= n_batch);
2025+ GGML_ASSERT (n_new <= n_batch);
20282026
20292027 // Decode all but the last token so we can save the memory state before decoding the last token.
20302028 // This is done so we can restore the session state later and replay the last token.
20312029 // Memory implementations in recurrent/hybrid models don't support removing tokens from their
20322030 // memory, so we can't just remove the last token from the memory and replay the last token which
20332031 // is the reason for this logic.
2034- if (llama_decode (ctx, llama_batch_get_one (const_cast <llama_token*>(tokens .data ()), n_tokens_before_last))) {
2032+ if (llama_decode (ctx, llama_batch_get_one (const_cast <llama_token*>(all_tokens .data () + offset ), n_tokens_before_last))) {
20352033 LOG_ERR (" %s : failed to eval\n " , __func__);
20362034 return false ;
20372035 }
20382036 n_past += n_tokens_before_last;
20392037
2040- llama_state_save_file (ctx, state_path.data (), tokens .data (), n_tokens_before_last );
2041- LOG_INF (" saved session before last token to %s, n_tokens = %d \n " , state_path.data (), n_tokens_before_last );
2038+ llama_state_save_file (ctx, state_path.data (), all_tokens .data (), all_tokens. size () );
2039+ LOG_INF (" saved session before last token to %s, n_new = %zu \n " , state_path.data (), all_tokens. size () );
20422040
2043- llama_token last_token = tokens .back ();
2041+ llama_token last_token = all_tokens .back ();
20442042 llama_batch batch = llama_batch_get_one (&last_token, 1 );
20452043 int32_t pos = n_past;
20462044 batch.pos = &pos;
@@ -2051,11 +2049,11 @@ bool common_prompt_batch_decode(
20512049 }
20522050 n_past++;
20532051 } else {
2054- if (llama_decode (ctx, llama_batch_get_one (const_cast <llama_token*>(tokens .data ()), n_eval ))) {
2052+ if (llama_decode (ctx, llama_batch_get_one (const_cast <llama_token*>(all_tokens .data () + offset ), n_new ))) {
20552053 LOG_ERR (" %s : failed to eval\n " , __func__);
20562054 return false ;
20572055 }
2058- n_past += n_eval ;
2056+ n_past += n_new ;
20592057 }
20602058
20612059 return true ;
0 commit comments