Pause sampling if waiting for user input.
This commit is contained in:
parent
10f1c9ed30
commit
b78caa6bff
1 changed files with 24 additions and 22 deletions
46
main.cpp
46
main.cpp
|
@ -935,35 +935,37 @@ int main(int argc, char ** argv) {
|
||||||
embd.clear();
|
embd.clear();
|
||||||
|
|
||||||
if (embd_inp.size() <= input_consumed) {
|
if (embd_inp.size() <= input_consumed) {
|
||||||
// out of user input, sample next token
|
if (!is_interacting) {
|
||||||
const float top_k = params.top_k;
|
// out of user input, sample next token
|
||||||
const float top_p = params.top_p;
|
const float top_k = params.top_k;
|
||||||
const float temp = params.temp;
|
const float top_p = params.top_p;
|
||||||
const float repeat_penalty = params.repeat_penalty;
|
const float temp = params.temp;
|
||||||
|
const float repeat_penalty = params.repeat_penalty;
|
||||||
|
|
||||||
const int n_vocab = model.hparams.n_vocab;
|
const int n_vocab = model.hparams.n_vocab;
|
||||||
|
|
||||||
gpt_vocab::id id = 0;
|
gpt_vocab::id id = 0;
|
||||||
|
|
||||||
{
|
{
|
||||||
const int64_t t_start_sample_us = ggml_time_us();
|
const int64_t t_start_sample_us = ggml_time_us();
|
||||||
|
|
||||||
id = llama_sample_top_p_top_k(vocab, logits.data() + (logits.size() - n_vocab), last_n_tokens, repeat_penalty, top_k, top_p, temp, rng);
|
id = llama_sample_top_p_top_k(vocab, logits.data() + (logits.size() - n_vocab), last_n_tokens, repeat_penalty, top_k, top_p, temp, rng);
|
||||||
|
|
||||||
last_n_tokens.erase(last_n_tokens.begin());
|
last_n_tokens.erase(last_n_tokens.begin());
|
||||||
last_n_tokens.push_back(id);
|
last_n_tokens.push_back(id);
|
||||||
|
|
||||||
t_sample_us += ggml_time_us() - t_start_sample_us;
|
t_sample_us += ggml_time_us() - t_start_sample_us;
|
||||||
|
}
|
||||||
|
|
||||||
|
// add it to the context
|
||||||
|
embd.push_back(id);
|
||||||
|
|
||||||
|
// echo this to console
|
||||||
|
input_noecho = false;
|
||||||
|
|
||||||
|
// decrement remaining sampling budget
|
||||||
|
--remaining_tokens;
|
||||||
}
|
}
|
||||||
|
|
||||||
// add it to the context
|
|
||||||
embd.push_back(id);
|
|
||||||
|
|
||||||
// echo this to console
|
|
||||||
input_noecho = false;
|
|
||||||
|
|
||||||
// decrement remaining sampling budget
|
|
||||||
--remaining_tokens;
|
|
||||||
} else {
|
} else {
|
||||||
// some user input remains from prompt or interaction, forward it to processing
|
// some user input remains from prompt or interaction, forward it to processing
|
||||||
while (embd_inp.size() > input_consumed) {
|
while (embd_inp.size() > input_consumed) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue