From 4444575c4e9c72f8b8e3056713956853fa8d192d Mon Sep 17 00:00:00 2001 From: rdentato Date: Mon, 21 Aug 2023 06:43:39 +0000 Subject: [PATCH] Added check of generation parameters. --- run.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/run.c b/run.c index fb11362..818f6da 100644 --- a/run.c +++ b/run.c @@ -731,7 +731,6 @@ int main(int argc, char *argv[]) { else if (argv[i][1] == 'z') { tokenizer_path = argv[i + 1]; } else { error_usage(); } } - if(rng_seed == 0) { rng_seed = (unsigned int)time(NULL);} // build the Transformer via the model .bin file Transformer transformer; @@ -745,6 +744,16 @@ int main(int argc, char *argv[]) { Sampler sampler; build_sampler(&sampler, transformer.config.vocab_size); + + // Check for sound parameters and fallback to defaults if needed. + // This needs to stay close to the generation code since, in the future, + // it will be in the "chat loop" (one may change params from on prompts to the other). + if (rng_seed <= 0) { rng_seed = (unsigned int)time(NULL);} + if (temperature < 0.0 || 1.0 < temperature) temperature = 1.0; + if (topp < 0.0 || 1.0 < temperature) topp = 0.9; + if (steps <= 0 || transformer.config.seq_len < steps ) { steps = transformer.config.seq_len; } + + // encode the (string) prompt into tokens sequence, if any is given int *prompt_tokens = NULL; // the sequence of prompt tokens int num_prompt_tokens = 0; // the total number of prompt tokens