10000 Remove unprintable characters from vocab list by beiller · Pull Request #25 · ggml-org/llama.cpp · GitHub
[go: up one dir, main page]

Skip to content

Remove unprintable characters from vocab list #25

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

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
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
23 changes: 21 additions & 2 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include <map>
#include <string>
#include <vector>
#include <unordered_set>

// determine number of model parts based on the dimension
static const std::map<int, int> LLAMA_N_PARTS = {
Expand Down Expand Up @@ -123,6 +124,9 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
}

// load vocab

std::unordered_set<std::string> unprintable_characters = {"", "�", "��"};

{
const int32_t n_vocab = model.hparams.n_vocab;

Expand All @@ -132,6 +136,7 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
return false;
}


std::string word;
for (int i = 0; i < n_vocab; i++) {
uint32_t len;
Expand All @@ -140,6 +145,10 @@ bool llama_model_load(const std::string & fname, llama_model & model, gpt_vocab
word.resize(len);
fin.read((char *) word.data(), len);

if(unprintable_characters.find(word) != unprintable_characters.end()) {
continue;
}

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

Expand Down Expand Up @@ -792,7 +801,7 @@ int main(int argc, char CFEF ** argv) {
printf("%6d -> '%s'\n", embd_inp[i], vocab.id_to_token.at(embd_inp[i]).c_str());
}
printf("\n");
printf("sampling parameters: temp = %f, top_k = %d, top_p = %f\n", params.temp, params.top_k, params.top_p);
printf("sampling parameters: temp = %f, top_k = %d, top_p = %f, repeat_last_n = %i, repeat_penalty = %f\n", params.temp, params.top_k, params.top_p, params.repeat_last_n, params.repeat_penalty);
printf("\n\n");

std::vector<gpt_vocab::id> embd;
Expand All @@ -801,6 +810,10 @@ int main(int argc, char ** argv) {
size_t mem_per_token = 0;
llama_eval(model, params.n_threads, 0, { 0, 1, 2, 3 }, logits, mem_per_token);

int last_n_size = params.repeat_last_n;
std::vector<gpt_vocab::id> last_n_tokens(last_n_size);
std::fill(last_n_tokens.begin(), last_n_tokens.end(), 0);

for (int i = embd.size(); i < embd_inp.size() + params.n_predict; i++) {
// predict
if (embd.size() > 0) {
Expand All @@ -821,6 +834,7 @@ int main(int argc, char ** argv) {
// sample next token
const float top_p = params.top_p;
const float temp = params.temp;
const float repeat_penalty = params.repeat_penalty;

const int n_vocab = model.hparams.n_vocab;

Expand All @@ -829,7 +843,10 @@ int main(int argc, char ** argv) {
{
const int64_t t_start_sample_us = ggml_time_us();

id = llama_sample_top_p(vocab, logits.data() + (logits.size() - n_vocab), top_p, temp, rng);
id = llama_sample_top_p(vocab, logits.data() + (logits.size() - n_vocab), last_n_tokens, repeat_penalty, top_p, temp, rng);

last_n_tokens.erase(last_n_tokens.begin());
last_n_tokens.push_back(id);

t_sample_us += ggml_time_us() - t_start_sample_us;
}
Expand All @@ -840,6 +857,8 @@ int main(int argc, char ** argv) {
// if here, it means we are still processing the input prompt
for (int k = i; k < embd_inp.size(); k++) {
embd.push_back(embd_inp[k]);
last_n_tokens.erase(last_n_tokens.begin());
last_n_tokens.push_back(embd_inp[k]);
if (embd.size() > params.n_batch) {
break;
}
Expand Down
0