@@ -3387,14 +3387,8 @@ struct server_context {
33873387 slot.n_prompt_tokens_processed += n_pos;
33883388 }
33893389
3390- const size_t n_to_log = slot.mtp_kv_update_batch .size ();
3391- if (n_to_log > 0 ) {
3392- SLT_INF (slot,
3393- " DEBUG-KV-REQ Cache Warm-up: Requesting KV update for %zu tokens. Positions: %d ... %d\n " ,
3394- n_to_log,
3395- slot.mtp_kv_update_batch .front ().n_past ,
3396- slot.mtp_kv_update_batch .back ().n_past
3397- );
3390+ if (slot.has_mtp ) {
3391+ slot.mtp_kv_update_batch .clear ();
33983392 }
33993393 // add prompt tokens for processing in the current batch
34003394 while (slot.n_past < slot.n_prompt_tokens && batch.n_tokens < n_batch) {
@@ -3484,6 +3478,7 @@ struct server_context {
34843478 batch.seq_id + i,
34853479 batch.logits + i,
34863480 };
3481+ LOG_INF (" \n [DEBUG-CHUNK] Processing main model chunk. Batch size: %d\n " , n_tokens);
34873482
34883483 const int ret = llama_decode (ctx, batch_view);
34893484
@@ -3525,16 +3520,18 @@ struct server_context {
35253520
35263521 continue ; // continue loop of n_batch
35273522 }
3523+
3524+ // This should only trigger on a non-empty update batch once, after prompt processing but not during token generation
3525+ // Aquece o cache MTP para os pedaços do prompt que acabaram de ser processados.
3526+ // Esta lógica SÓ deve ser executada durante o processamento do prompt.
35283527 for (auto & slot : slots) {
3529- if (slot.has_mtp && slot.n_past == slot.n_prompt_tokens ) {
3530- SLT_INF (slot, " Prompt processing finished. Warming up MTP KV cache for %d tokens.\n " , slot.n_prompt_tokens );
3531- slot.mtp_kv_update_batch .clear ();
3532-
3533- for (int j = 0 ; j < slot.n_prompt_tokens ; ++j) {
3534- slot.mtp_kv_update_batch .push_back ({ slot.prompt_tokens [j], (llama_pos)j, j });
3535- }
3536-
3537- mtp_update_kv_cache (ctx, slot.mtp_kv_update_batch );
3528+ if (slot.state == SLOT_STATE_PROCESSING_PROMPT && slot.has_mtp && !slot.mtp_kv_update_batch .empty ()) {
3529+ SLT_INF (slot, " DEBUG-KV-REQ: Warming up MTP cache for prompt chunk of size %zu. Positions: %d ... %d\n " ,
3530+ slot.mtp_kv_update_batch .size (),
3531+ slot.mtp_kv_update_batch .front ().n_past ,
3532+ slot.mtp_kv_update_batch .back ().n_past
3533+ );
3534+ mtp_update_kv_cache (ctx, slot.mtp_kv_update_batch , " PROMPT_WARMUP" );
35383535 }
35393536 }
35403537
@@ -3581,11 +3578,6 @@ struct server_context {
35813578
35823579 common_sampler_accept (slot.smpl , id, true );
35833580
3584- // This should only trigger on a non-empty update batch once, after prompt processing but not during token generation
3585- // if (slot.has_mtp) {
3586- // mtp_update_kv_cache(ctx, slot.mtp_kv_update_batch);
3587- // }
3588-
35893581 slot.n_decoded += 1 ;
35903582
35913583 const int64_t t_current = ggml_time_us ();
@@ -3670,11 +3662,6 @@ struct server_context {
36703662 draft = common_speculative_gen_draft (slot.spec , params_spec, cached_text_tokens, id);
36713663 }
36723664
3673- // llama_token draft_id = mtp_speculative_gen_draft(slot.smpl, ctx, id, slot.n_past, slot.last_tok_idx);
3674- // llama_tokens draft;
3675- // draft.reserve(1);
3676- // draft.push_back(draft_id);
3677-
36783665 // ignore small drafts
36793666 if (slot.params .speculative .n_min > (int )draft.size ()) {
36803667 SLT_DBG (slot, " ignoring small draft: %d < %d\n " , (int )draft.size (), slot.params .speculative .n_min );
@@ -3706,7 +3693,7 @@ struct server_context {
37063693 for (int32_t i = 0 ; i < ids.size (); ++i) {
37073694 slot.mtp_kv_update_batch .push_back ({ ids[i], slot.n_past + i, i });
37083695 }
3709- mtp_update_kv_cache (ctx, slot.mtp_kv_update_batch );
3696+ mtp_update_kv_cache (ctx, slot.mtp_kv_update_batch , " GEN_ACCEPTED " );
37103697 }
37113698
37123699 slot.n_past += ids.size ();
0 commit comments