From f056beb3840492e182a50052c25ecbd46b8343c6 Mon Sep 17 00:00:00 2001 From: Georgi Gerganov Date: Wed, 15 Mar 2023 21:35:48 +0200 Subject: [PATCH] Apply suggestions from code review --- main.cpp | 6 ++++-- utils.cpp | 4 ++-- utils.h | 1 + 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/main.cpp b/main.cpp index feb9edade..e29f94b57 100644 --- a/main.cpp +++ b/main.cpp @@ -218,7 +218,7 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab ctx_size += n_ctx*n_layer*n_embd*ggml_type_sizef(GGML_TYPE_F32); // memory_k ctx_size += n_ctx*n_layer*n_embd*ggml_type_sizef(GGML_TYPE_F32); // memory_v - ctx_size += (5 + 10*n_layer)*hparams.n_ctx; // object overhead + ctx_size += (5 + 10*n_layer)*256; // object overhead fprintf(stderr, "%s: ggml ctx size = %6.2f MB\n", __func__, ctx_size/(1024.0*1024.0)); } @@ -547,7 +547,9 @@ bool llama_eval( const int d_key = n_embd/n_head; - static size_t buf_size = hparams.n_ctx*1024*1024; + // TODO: check if this size scales with n_ctx linearly and remove constant. somehow I feel it wasn't the case + // static size_t buf_size = hparams.n_ctx*1024*1024; + static size_t buf_size = 512u*1024*1024; static void * buf = malloc(buf_size); if (mem_per_token > 0 && mem_per_token*N > buf_size) { diff --git a/utils.cpp b/utils.cpp index 189ec231c..aa3ad1053 100644 --- a/utils.cpp +++ b/utils.cpp @@ -38,8 +38,8 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { } else if (arg == "--top_k") { params.top_k = std::stoi(argv[++i]); } else if (arg == "-c" || arg == "--ctx_size") { - params.n_ctx = std::stoi(argv[++i]); - } else if (arg == "--top_p") { + params.n_ctx = std::stoi(argv[++i]); + } else if (arg == "--top_p") { params.top_p = std::stof(argv[++i]); } else if (arg == "--temp") { params.temp = std::stof(argv[++i]); diff --git a/utils.h b/utils.h index 36c1153e6..021120b05 100644 --- a/utils.h +++ b/utils.h @@ -18,6 +18,7 @@ struct gpt_params { int32_t n_predict = 128; // new tokens to predict int32_t repeat_last_n = 64; // last n tokens to penalize int32_t n_ctx = 512; //context size + // sampling parameters int32_t top_k = 40; float top_p = 0.95f;