From 68f9786ed9776393f4195166508f71133b6db1e3 Mon Sep 17 00:00:00 2001 From: niansa/tuxifan Date: Fri, 16 Jun 2023 21:56:22 +0200 Subject: [PATCH] Use operator ""_MiB (#991) --- gpt4all-backend/gptj.cpp | 6 ++---- gpt4all-backend/mpt.cpp | 6 ++---- gpt4all-backend/replit.cpp | 3 +-- gpt4all-backend/utils.h | 7 +++++++ 4 files changed, 12 insertions(+), 10 deletions(-) diff --git a/gpt4all-backend/gptj.cpp b/gpt4all-backend/gptj.cpp index 457bce7e..6cb81161 100644 --- a/gpt4all-backend/gptj.cpp +++ b/gpt4all-backend/gptj.cpp @@ -30,8 +30,6 @@ namespace { const char *modelType_ = "GPT-J"; - -static const size_t MB = 1024*1024; } // default hparams (GPT-J 6B) @@ -139,7 +137,7 @@ static bool kv_cache_init( const int64_t n_mem = (int64_t)n_layer*n_ctx; const int64_t n_elements = n_embd*n_mem; - cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2u*MB); + cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2_MiB); struct ggml_init_params params; params.mem_size = cache.buf.size; @@ -501,7 +499,7 @@ bool gptj_eval( const int n_vocab = hparams.n_vocab; const int n_rot = hparams.n_rot; - const size_t init_buf_size = 1024u*MB; + const size_t init_buf_size = 1024_MiB; if (!model.buf.addr || model.buf.size < init_buf_size) model.buf.resize(init_buf_size); diff --git a/gpt4all-backend/mpt.cpp b/gpt4all-backend/mpt.cpp index ec33c20c..dea12965 100644 --- a/gpt4all-backend/mpt.cpp +++ b/gpt4all-backend/mpt.cpp @@ -33,8 +33,6 @@ namespace { const char *modelType_ = "MPT"; - -static const size_t MB = 1024*1024; } // default hparams (MPT 7B) @@ -134,7 +132,7 @@ static bool kv_cache_init( const int64_t n_mem = (int64_t)n_layer*n_ctx; const int64_t n_elements = n_embd*n_mem; - cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2u*MB); + cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2_MiB); struct ggml_init_params params; params.mem_size = cache.buf.size; @@ -455,7 +453,7 @@ bool mpt_eval( const int n_head = hparams.n_head; const int n_vocab = hparams.n_vocab; - const size_t init_buf_size = 1024u*MB; + const size_t init_buf_size = 1024_MiB; if (!model.buf.addr || model.buf.size < init_buf_size) model.buf.resize(init_buf_size); diff --git a/gpt4all-backend/replit.cpp b/gpt4all-backend/replit.cpp index ef09af6c..568b6441 100644 --- a/gpt4all-backend/replit.cpp +++ b/gpt4all-backend/replit.cpp @@ -47,7 +47,6 @@ using piece_map_t = std::unordered_map; namespace { const char *modelType_ = "Replit"; -const size_t MB = 1024*1024; const std::string ws_symbol = "\342\226\201"; } @@ -251,7 +250,7 @@ static bool kv_cache_init( const int64_t n_mem = (int64_t)n_layer*n_ctx; const int64_t n_elements = n_embd*n_mem; - cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2u*MB); + cache.buf.resize(2u*n_elements*ggml_type_size(wtype) + 2_MiB); struct ggml_init_params params; params.mem_size = cache.buf.size; params.mem_buffer = cache.buf.addr; diff --git a/gpt4all-backend/utils.h b/gpt4all-backend/utils.h index e3b90efe..b190643d 100644 --- a/gpt4all-backend/utils.h +++ b/gpt4all-backend/utils.h @@ -8,6 +8,13 @@ #include #include +// +// General purpose inline functions +// +constexpr inline unsigned long long operator ""_MiB(unsigned long long bytes) { + return bytes*1024*1024; +} + // // CLI argument parsing //