sampler log function
This commit is contained in:
parent
abbf7e7a61
commit
aa6c2bd5d2
1 changed files with 23 additions and 0 deletions
23
utils.cpp
23
utils.cpp
|
@ -591,6 +591,29 @@ struct SoftMaxSampler {
|
||||||
) const {
|
) const {
|
||||||
return logits_id[dist(rng)].second;
|
return logits_id[dist(rng)].second;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void print(FILE* log_file, const gpt_vocab & vocab, const float * logits, int max_print, int selected=-1) const {
|
||||||
|
if (log_file == nullptr) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
int n = probs.size();
|
||||||
|
if (n > max_print) {
|
||||||
|
n = max_print;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < n; i++) {
|
||||||
|
const auto& entry = logits_id[i];
|
||||||
|
const int id = entry.second;
|
||||||
|
const double scaled_logit = entry.first;
|
||||||
|
fprintf(log_file, "%s%d: '%s' p=%f act=%.3f temp=%.2f\n",
|
||||||
|
selected >= 0 && id == selected ? "->" : " ",
|
||||||
|
i,
|
||||||
|
vocab.id_to_token.at(id).c_str(),
|
||||||
|
probs[i],
|
||||||
|
logits[id],
|
||||||
|
logits[id] / scaled_logit
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
gpt_vocab::id sample_top_k_top_p(
|
gpt_vocab::id sample_top_k_top_p(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue