Skip to content

Commit

Permalink
Use operator ""_MiB (nomic-ai#991)
Browse files Browse the repository at this point in the history
  • Loading branch information
niansa authored Jun 16, 2023
1 parent 0a0d4a7 commit 68f9786
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 10 deletions.
6 changes: 2 additions & 4 deletions gpt4all-backend/gptj.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@

namespace {
const char *modelType_ = "GPT-J";

static const size_t MB = 1024*1024;
}

// default hparams (GPT-J 6B)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
6 changes: 2 additions & 4 deletions gpt4all-backend/mpt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@

namespace {
const char *modelType_ = "MPT";

static const size_t MB = 1024*1024;
}

// default hparams (MPT 7B)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);

Expand Down
3 changes: 1 addition & 2 deletions gpt4all-backend/replit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ using piece_map_t = std::unordered_map<std::string, piece_t>;
namespace {
const char *modelType_ = "Replit";

const size_t MB = 1024*1024;
const std::string ws_symbol = "\342\226\201";
}

Expand Down Expand Up @@ -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;
Expand Down
7 changes: 7 additions & 0 deletions gpt4all-backend/utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@
#include <random>
#include <thread>

//
// General purpose inline functions
//
constexpr inline unsigned long long operator ""_MiB(unsigned long long bytes) {
return bytes*1024*1024;
}

//
// CLI argument parsing
//
Expand Down

0 comments on commit 68f9786

Please sign in to comment.