@@ -220,8 +220,6 @@ struct server_slot {
220220 return false ;
221221 }
222222
223- GGML_ASSERT (prompt.data .size () == 0 );
224-
225223 const size_t cur_size_tgt = llama_state_seq_get_size_ext (ctx_tgt, id, LLAMA_STATE_SEQ_FLAGS_NONE );
226224 const size_t cur_size_dft = ctx_dft ? llama_state_seq_get_size_ext (ctx_dft, id, LLAMA_STATE_SEQ_FLAGS_NONE ) : 0 ;
227225
@@ -252,19 +250,15 @@ struct server_slot {
252250 return res;
253251 }
254252
255- void prompt_clear (bool allow_processing) {
256- if (!allow_processing) {
257- GGML_ASSERT (!is_processing ());
258- }
259-
253+ void prompt_clear () {
260254 SLT_TRC (*this , " clearing prompt with %zu tokens\n " , prompt.tokens .size ());
261255
262256 common_context_seq_rm (ctx_tgt, id, -1 , -1 );
263257 if (ctx_dft) {
264258 common_context_seq_rm (ctx_dft, id, -1 , -1 );
265259 }
266260
267- prompt.tokens . clear ();
261+ prompt.clear ();
268262 }
269263
270264 std::vector<common_adapter_lora_info> lora;
@@ -493,7 +487,7 @@ struct server_slot {
493487
494488 // do not keep context of the child slots - the parent's context is enough
495489 if (task->is_child ()) {
496- prompt_clear (false );
490+ prompt_clear ();
497491 }
498492
499493 reset ();
@@ -1626,7 +1620,7 @@ struct server_context_impl {
16261620 ret->prompt_save (*prompt_cache);
16271621
16281622 if (!ret->prompt_load (*prompt_cache, task.tokens )) {
1629- ret->prompt_clear (false );
1623+ ret->prompt_clear ();
16301624 }
16311625
16321626 prompt_cache->update ();
@@ -1658,7 +1652,7 @@ struct server_context_impl {
16581652 if (slot.prompt .n_tokens () > 0 ) {
16591653 SRV_WRN (" purging slot %d with %zu tokens\n " , slot.id , slot.prompt .tokens .size ());
16601654
1661- slot.prompt_clear (false );
1655+ slot.prompt_clear ();
16621656
16631657 res = true ;
16641658
@@ -1691,7 +1685,7 @@ struct server_context_impl {
16911685 // if lora has changed, check to see if the cache should be cleared
16921686 if (lora_should_clear_cache (slot.lora , task_loras)) {
16931687 SLT_TRC (slot, " clearing cache for lora change. %zu loras -> %zu loras\n " , slot.lora .size (), task.params .lora .size ());
1694- slot.prompt .tokens . clear ();
1688+ slot.prompt .clear ();
16951689 } else {
16961690 SLT_TRC (slot, " keeping cache for alora. %zu target loras\n " , task_loras.size ());
16971691 }
@@ -2405,7 +2399,7 @@ struct server_context_impl {
24052399
24062400 if (params_base.kv_unified ) {
24072401 // [TAG_IDLE_SLOT_CLEAR]
2408- slot.prompt_clear (false );
2402+ slot.prompt_clear ();
24092403 }
24102404 }
24112405 }
@@ -2573,12 +2567,12 @@ struct server_context_impl {
25732567 size_t token_count = 0 ;
25742568 size_t nread = llama_state_seq_load_file (ctx_tgt, filepath.c_str (), slot->id , tokens.data (), tokens.size (), &token_count);
25752569 if (nread == 0 ) {
2576- slot->prompt .tokens . clear (); // KV may already been invalidated?
2570+ slot->prompt .clear (); // KV may already been invalidated?
25772571 send_error (task, " Unable to restore slot, no available space in KV cache or invalid slot save file" , ERROR_TYPE_INVALID_REQUEST );
25782572 break ;
25792573 }
25802574 tokens.resize (token_count);
2581- slot->prompt .tokens . clear ();
2575+ slot->prompt .clear ();
25822576 slot->prompt .tokens .insert (tokens);
25832577
25842578 const int64_t t_end = ggml_time_us ();
@@ -2615,7 +2609,7 @@ struct server_context_impl {
26152609 // Erase token cache
26162610 const size_t n_erased = slot->prompt .tokens .size ();
26172611
2618- slot->prompt_clear (false );
2612+ slot->prompt_clear ();
26192613
26202614 auto res = std::make_unique<server_task_result_slot_erase>();
26212615 res->id = task.id ;
@@ -2775,6 +2769,27 @@ struct server_context_impl {
27752769 abort_all_slots (" pre_decode() failed: " + std::string (e.what ()));
27762770 }
27772771
2772+ GGML_ASSERT (batch.slot_batched || batch.size () == 0 );
2773+
2774+ if (batch.slot_batched ) {
2775+ auto & slot_batched = batch.slot_batched ;
2776+ auto & alora_scale = batch.alora_scale ;
2777+ auto & alora_disabled_id = batch.alora_disabled_id ;
2778+
2779+ // TODO @ngxson : alora handling is too messy, need to refactor it to be more clear and maintainable
2780+ // apply lora, only need to do it once per batch
2781+ common_set_adapter_lora (ctx_tgt, slot_batched->lora );
2782+
2783+ // if the lora is temporarily disabled for an alora, re-enable it
2784+ // for next time
2785+ if (alora_scale > 0 .0f ) {
2786+ SRV_DBG (" re-enabling alora with scale %f\n " , alora_scale);
2787+ slot_batched->lora [alora_disabled_id].scale = alora_scale;
2788+ }
2789+
2790+ llama_set_embeddings (ctx_tgt, slot_batched->need_embd ());
2791+ }
2792+
27782793 llama_batch batch_view;
27792794 int32_t off_next = 0 ;
27802795 int32_t n_batch = llama_n_batch (ctx_tgt);
@@ -2814,7 +2829,6 @@ struct server_context_impl {
28142829 abort_all_slots (" post_decode() failed: " + std::string (e.what ()));
28152830 break ; // stop any further processing
28162831 }
2817-
28182832 }
28192833 }
28202834
@@ -2880,7 +2894,7 @@ struct server_context_impl {
28802894
28812895 new_tokens.resize (slot.prompt .tokens .size () - n_discard);
28822896
2883- slot.prompt .tokens . clear ();
2897+ slot.prompt .clear ();
28842898 slot.prompt .tokens .insert (new_tokens);
28852899 }
28862900
@@ -3556,25 +3570,6 @@ struct server_context_impl {
35563570 bool decode (int32_t & n_batch, int32_t off, llama_batch & batch_view) {
35573571 SRV_DBG (" n_batch (effective) = %d, off = %d\n " , n_batch, off);
35583572
3559- auto & slot_batched = batch.slot_batched ;
3560- auto & alora_scale = batch.alora_scale ;
3561- auto & alora_disabled_id = batch.alora_disabled_id ;
3562-
3563- // TODO @ngxson : alora handling is too messy, need to refactor it to be more clear and maintainable
3564- if (slot_batched) {
3565- // apply lora, only need to do it once per batch
3566- common_set_adapter_lora (ctx_tgt, slot_batched->lora );
3567-
3568- // if the lora is temporarily disabled for an alora, re-enable it
3569- // for next time
3570- if (alora_scale > 0 .0f ) {
3571- SRV_DBG (" re-enabling alora with scale %f\n " , alora_scale);
3572- slot_batched->lora [alora_disabled_id].scale = alora_scale;
3573- }
3574-
3575- llama_set_embeddings (ctx_tgt, slot_batched->need_embd ());
3576- }
3577-
35783573 if (batch.size () == 0 ) {
35793574 SRV_WRN (" %s" , " no tokens to decode\n " );
35803575
@@ -3622,7 +3617,7 @@ struct server_context_impl {
36223617
36233618 // note: it's complicated to keep track of how much of the current batch has been
36243619 // processed before the error occurred, so we simply clear the entire context
3625- slot.prompt_clear (false );
3620+ slot.prompt_clear ();
36263621 }
36273622 }
36283623
0 commit comments