8000 We could use std::unordered_map over std::map by Fabio3rs · Pull Request #305 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

We could use std::unordered_map over std::map #305

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

Merged
merged 7 commits into from
Mar 21, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
8000 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
Prev Previous commit
Resolved recent conflicts with master
  • Loading branch information
Fabio3rs committed Mar 21, 2023
commit cfdf363a0c2f18b89d91be43d061c0f7b3acde27
20 changes: 6 additions & 14 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ bool llama_model_load(const std::string & fname, llama_model & model, llama_voca
{
std::string word;
vocab.id_to_token.resize(model.hparams.n_vocab);
std::vector<char> tmp(64);

for (int i = 0; i < model.hparams.n_vocab; i++) {
uint32_t len;
fin.read((char *) &len, sizeof(len));
Expand All @@ -199,10 +201,6 @@ bool llama_model_load(const std::string & fname, llama_model & model, llama_voca
auto &tok_score = vocab.id_to_token[i];
tok_score.tok = word;
tok_score.score = score;

//if (i < 30000) {
// fprintf(stderr, "%s: vocab[%d] = '%s'\n", __func__, i, word.c_str());
//}
}
}

Expand Down Expand Up @@ -1014,15 +1012,9 @@ int main(int argc, char ** argv) {

fprintf(stderr, "%s: interactive mode on.\n", __func__);

if(antipromptv_inp.size()) {
for (size_t apindex = 0; apindex < antipromptv_inp.size(); ++apindex) {
auto antiprompt_inp = antipromptv_inp.at(apindex);
fprintf(stderr, "%s: reverse prompt: '%s'\n", __func__, params.antiprompt.at(apindex).c_str());
fprintf(stderr, "%s: number of tokens in reverse prompt = %zu\n", __func__, antiprompt_inp.size());
for (int i = 0; i < (int) antiprompt_inp.size(); i++) {
fprintf(stderr, "%6d -> '%s'\n", antiprompt_inp[i], vocab.id_to_token.at(antiprompt_inp[i]).tok.c_str());
}
fprintf(stderr, "\n");
if(params.antiprompt.size()) {
for (auto antiprompt : params.antiprompt) {
fprintf(stderr, "Reverse prompt: '%s'\n", antiprompt.c_str());
}
}
}
Expand Down Expand Up @@ -1145,7 +1137,7 @@ int main(int argc, char ** argv) {
// check for reverse prompt
std::string last_output;
for (auto id : last_n_tokens) {
last_output += vocab.id_to_token[id];
last_output += vocab.id_to_token[id].tok;
}

// Check if each of the reverse prompts appears at the end of the output.
Expand Down
31 changes: 7 additions & 24 deletions utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,8 @@ bool llama_vocab_load(const std::string & fname, llama_vocab & vocab) {
std::string word;
std::vector<char> tmp(64);

vocab.id_to_token.resize(n_vocab);

for (int i = 0; i < n_vocab; i++) {
uint32_t len;
fin.read((char *) &len, sizeof(len));
Expand All @@ -410,8 +412,10 @@ bool llama_vocab_load(const std::string & fname, llama_vocab & vocab) {
fin.read((char *) &score, sizeof(score));

vocab.token_to_id[word] = i;
vocab.id_to_token[i] = word;
vocab.score[i] = score;

auto &tok_score = vocab.id_to_token[i];
tok_score.tok = word;
tok_score.score = score;
}

return true;
Expand All @@ -433,28 +437,7 @@ std::vector<llama_vocab::id> llama_tokenize(const llama_vocab & vocab, const std
return output;
}

bool gpt_vocab_init(const std::string & fname, gpt_vocab & vocab) {
printf("%s: loading vocab from '%s'\n", __func__, fname.c_str());

vocab.token_to_id = ::json_parse(fname);

vocab.id_to_token.resize(vocab.token_to_id.size());
for (const auto & kv : vocab.token_to_id) {
vocab.id_to_token[kv.second].tok = kv.first;
}

printf("%s: vocab size = %d\n", __func__, (int) vocab.token_to_id.size());

// print the vocabulary
//for (auto kv : vocab.token_to_id) {
// printf("'%s' -> %d\n", kv.first.data(), kv.second);
//}

return true;
}


void sample_top_k(std::vector<std::pair<double, gpt_vocab::id>> & logits_id, int top_k) {
void sample_top_k(std::vector<std::pair<double, llama_vocab::id>> & logits_id, int top_k) {
// find the top K tokens
std::partial_sort(
logits_id.begin(),
Expand Down
You are viewing a condensed version of this merge commit. You can view the full changes here.
0