mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-10-31 08:51:55 +00:00 
			
		
		
		
	gguf : deduplicate (#2629)
* gguf : better type names * dedup : CPU + Metal is working * ggml : fix warnings about unused results * llama.cpp : fix line feed and compiler warning * llama : fix strncpy warning + note token_to_str does not write null * llama : restore the original load/save session implementation Will migrate this to GGUF in the future * convert-llama-h5-to-gguf.py : support alt ctx param name * ggml : assert when using ggml_mul with non-F32 src1 * examples : dedup simple --------- Co-authored-by: klosax <131523366+klosax@users.noreply.github.com>
This commit is contained in:
		| @@ -36,16 +36,17 @@ int main(int argc, char ** argv) { | ||||
|  | ||||
|     llama_backend_init(params.numa); | ||||
|  | ||||
|     llama_model * model; | ||||
|     llama_context * ctx; | ||||
|     llama_context_params ctx_params = llama_context_default_params(); | ||||
|  | ||||
|     std::tie(model, ctx) = llama_init_from_gpt_params(params); | ||||
|     llama_model * model = llama_load_model_from_file(params.model.c_str(), ctx_params); | ||||
|  | ||||
|     if (model == NULL) { | ||||
|         fprintf(stderr, "%s: error: unable to load model\n", __func__); | ||||
|         fprintf(stderr , "%s: error: unable to load model\n" , __func__); | ||||
|         return 1; | ||||
|     } | ||||
|  | ||||
|     llama_context * ctx = llama_new_context_with_model(model, ctx_params); | ||||
|  | ||||
|     // tokenize the prompt | ||||
|  | ||||
|     std::vector<llama_token> tokens_list; | ||||
| @@ -54,7 +55,7 @@ int main(int argc, char ** argv) { | ||||
|     const int max_context_size     = llama_n_ctx(ctx); | ||||
|     const int max_tokens_list_size = max_context_size - 4; | ||||
|  | ||||
|     if ((int)tokens_list.size() > max_tokens_list_size) { | ||||
|     if ((int) tokens_list.size() > max_tokens_list_size) { | ||||
|         fprintf(stderr, "%s: error: prompt too long (%d tokens, max %d)\n", __func__, (int) tokens_list.size(), max_tokens_list_size); | ||||
|         return 1; | ||||
|     } | ||||
| @@ -74,7 +75,9 @@ int main(int argc, char ** argv) { | ||||
|     // tokens (see "infinite text generation via context swapping" in the main example), but in this minimalist | ||||
|     // example, we will just stop the loop once this cache is full or once an end of stream is detected. | ||||
|  | ||||
|     while (llama_get_kv_cache_token_count( ctx ) < max_context_size) { | ||||
|     const int n_gen = std::min(32, max_context_size); | ||||
|  | ||||
|     while (llama_get_kv_cache_token_count(ctx) < n_gen) { | ||||
|         // evaluate the transformer | ||||
|  | ||||
|         if (llama_eval(ctx, tokens_list.data(), int(tokens_list.size()), llama_get_kv_cache_token_count(ctx), params.n_threads)) { | ||||
| @@ -114,7 +117,6 @@ int main(int argc, char ** argv) { | ||||
|  | ||||
|         // push this new token for next evaluation | ||||
|         tokens_list.push_back(new_token_id); | ||||
|  | ||||
|     } | ||||
|  | ||||
|     llama_free(ctx); | ||||
| @@ -122,5 +124,7 @@ int main(int argc, char ** argv) { | ||||
|  | ||||
|     llama_backend_free(); | ||||
|  | ||||
|     fprintf(stderr, "\n\n"); | ||||
|  | ||||
|     return 0; | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Georgi Gerganov
					Georgi Gerganov