mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-04 09:32:00 +00:00 
			
		
		
		
	server : fix crash when prompt exceeds context size (#3996)
This commit is contained in:
		@@ -1557,15 +1557,6 @@ struct llama_server_context
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
                    slot.num_prompt_tokens = prompt_tokens.size();
 | 
					                    slot.num_prompt_tokens = prompt_tokens.size();
 | 
				
			||||||
 | 
					
 | 
				
			||||||
                    if (!slot.params.cache_prompt)
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                        llama_sampling_reset(slot.ctx_sampling);
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                        slot.n_past = 0;
 | 
					 | 
				
			||||||
                        slot.num_prompt_tokens_processed = slot.num_prompt_tokens;
 | 
					 | 
				
			||||||
                    }
 | 
					 | 
				
			||||||
                    else
 | 
					 | 
				
			||||||
                    {
 | 
					 | 
				
			||||||
                    if (slot.params.n_keep < 0)
 | 
					                    if (slot.params.n_keep < 0)
 | 
				
			||||||
                    {
 | 
					                    {
 | 
				
			||||||
                        slot.params.n_keep = slot.num_prompt_tokens;
 | 
					                        slot.params.n_keep = slot.num_prompt_tokens;
 | 
				
			||||||
@@ -1595,6 +1586,15 @@ struct llama_server_context
 | 
				
			|||||||
                        GGML_ASSERT(slot.num_prompt_tokens < slot.n_ctx);
 | 
					                        GGML_ASSERT(slot.num_prompt_tokens < slot.n_ctx);
 | 
				
			||||||
                    }
 | 
					                    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    if (!slot.params.cache_prompt)
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
 | 
					                        llama_sampling_reset(slot.ctx_sampling);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                        slot.n_past = 0;
 | 
				
			||||||
 | 
					                        slot.num_prompt_tokens_processed = slot.num_prompt_tokens;
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else
 | 
				
			||||||
 | 
					                    {
 | 
				
			||||||
                        // push the prompt into the sampling context (do not apply grammar)
 | 
					                        // push the prompt into the sampling context (do not apply grammar)
 | 
				
			||||||
                        for (auto &token : prompt_tokens)
 | 
					                        for (auto &token : prompt_tokens)
 | 
				
			||||||
                        {
 | 
					                        {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user