Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mpt : fix n_ctx #165

Closed
wants to merge 6 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
mpt : move global variable n_ctx to mpt_hparams
  • Loading branch information
marella committed May 18, 2023
commit fcf734c58122237de6fb39ad12820a6c22bf6edd
9 changes: 6 additions & 3 deletions examples/mpt/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,9 @@
#include <utility>
#include <vector>

int n_ctx = 4096;

// no defaults for now
struct mpt_hparams {
int32_t n_ctx = 4096;
int32_t d_model = 0;
int32_t max_seq_len = 0;
int32_t n_heads = 0;
Expand Down Expand Up @@ -141,6 +140,7 @@ bool mpt_model_load(const std::string & fname, mpt_model & model, gpt_vocab & vo
{
const auto & hparams = model.hparams;

const int32_t n_ctx = hparams.n_ctx;
const size_t n_embd = hparams.d_model;
const size_t n_layer = hparams.n_layers;
const size_t n_vocab = hparams.n_vocab;
Expand Down Expand Up @@ -220,6 +220,7 @@ bool mpt_model_load(const std::string & fname, mpt_model & model, gpt_vocab & vo
{
const auto & hparams = model.hparams;

const int32_t n_ctx = hparams.n_ctx;
const size_t n_embd = hparams.d_model;
const size_t n_layer = hparams.n_layers;

Expand All @@ -231,7 +232,7 @@ bool mpt_model_load(const std::string & fname, mpt_model & model, gpt_vocab & vo

const size_t memory_size = ggml_nbytes(model.memory_k) + ggml_nbytes(model.memory_v);

printf("%s: memory_size = %8.2f MB, n_mem = %lld\n", __func__, memory_size / 1024.0 / 1024.0, n_mem);
printf("%s: memory_size = %8.2f MB, n_mem = %ld\n", __func__, memory_size / 1024.0 / 1024.0, n_mem);
}

// load weights
Expand Down Expand Up @@ -332,6 +333,7 @@ bool mpt_eval(const mpt_model & model, const int n_threads, const int n_past,

const auto & hparams = model.hparams;

const int32_t n_ctx = hparams.n_ctx;
const int n_embd = hparams.d_model;
const int n_layer = hparams.n_layers;
const int n_head = hparams.n_heads;
Expand Down Expand Up @@ -593,6 +595,7 @@ int main(int argc, char ** argv) {
}
printf("\n");

const int32_t n_ctx = model.hparams.n_ctx;
params.n_predict = std::min(params.n_predict, n_ctx - (int)embd_inp.size());

std::vector<gpt_vocab::id> embd;
Expand Down