]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
llama : allow 0 as a seed number. (#1275)
authorRobert Brisita <redacted>
Tue, 2 May 2023 16:23:44 +0000 (12:23 -0400)
committerGitHub <redacted>
Tue, 2 May 2023 16:23:44 +0000 (19:23 +0300)
examples/common.cpp
examples/embedding/embedding.cpp
examples/main/README.md
examples/main/main.cpp
examples/perplexity/perplexity.cpp
llama.cpp
llama.h

index ad7b0bba32f1f1e68adc2a1f38582efe9e7785ab..2bf0dc597eeadcbc56830fdeb85f93ef1a3e724c 100644 (file)
@@ -324,7 +324,7 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
     fprintf(stderr, "                        run in interactive mode and poll user input upon seeing PROMPT (can be\n");
     fprintf(stderr, "                        specified more than once for multiple prompts).\n");
     fprintf(stderr, "  --color               colorise output to distinguish prompt and user input from generations\n");
-    fprintf(stderr, "  -s SEED, --seed SEED  RNG seed (default: -1, use random seed for <= 0)\n");
+    fprintf(stderr, "  -s SEED, --seed SEED  RNG seed (default: -1, use random seed for < 0)\n");
     fprintf(stderr, "  -t N, --threads N     number of threads to use during computation (default: %d)\n", params.n_threads);
     fprintf(stderr, "  -p PROMPT, --prompt PROMPT\n");
     fprintf(stderr, "                        prompt to start generation with (default: empty)\n");
index b3e001476ea95f75ba0d70208a7d3d9d74d48951..1e9d8a8ce75d5b67d5fa5aba9dd975e5897e4640 100644 (file)
@@ -21,7 +21,7 @@ int main(int argc, char ** argv) {
 
     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
 
-    if (params.seed <= 0) {
+    if (params.seed < 0) {
         params.seed = time(NULL);
     }
 
index 234bf2eb5663939af427e8893120891af264e165..ba210d14a28fa2e41a658b0203ef5a0149d8b727 100644 (file)
@@ -130,7 +130,7 @@ It is important to note that the generated text may be shorter than the specifie
 
 -   `-s SEED, --seed SEED`: Set the random number generator (RNG) seed (default: -1).
 
-The RNG seed is used to initialize the random number generator that influences the text generation process. By setting a specific seed value, you can obtain consistent and reproducible results across multiple runs with the same input and settings. This can be helpful for testing, debugging, or comparing the effects of different options on the generated text to see when they diverge. If the seed is set to a value less than or equal to 0, a random seed will be used, which will result in different outputs on each run.
+The RNG seed is used to initialize the random number generator that influences the text generation process. By setting a specific seed value, you can obtain consistent and reproducible results across multiple runs with the same input and settings. This can be helpful for testing, debugging, or comparing the effects of different options on the generated text to see when they diverge. If the seed is set to a value less than 0, a random seed will be used, which will result in different outputs on each run.
 
 ### Temperature
 
index 051418660f653c690c0007ce627a1293d3945366..727c96c562eddffd4023d9d497660bad706828ba 100644 (file)
@@ -84,7 +84,7 @@ int main(int argc, char ** argv) {
 
     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
 
-    if (params.seed <= 0) {
+    if (params.seed < 0) {
         params.seed = time(NULL);
     }
 
index 2ca3388355bd0688248342a07784b8fc32e9243a..d474bc50f72e4b0dde6bb2200b3d22f4ab874500 100644 (file)
@@ -109,7 +109,7 @@ int main(int argc, char ** argv) {
 
     fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT);
 
-    if (params.seed <= 0) {
+    if (params.seed < 0) {
         params.seed = time(NULL);
     }
 
index b8751be7bf3c75b838a40454cea37fd713d9aae3..a8156bcc25e6753a039ec9a297a0cce5915899ba 100644 (file)
--- a/llama.cpp
+++ b/llama.cpp
@@ -809,7 +809,7 @@ struct llama_context_params llama_context_default_params() {
     struct llama_context_params result = {
         /*.n_ctx                       =*/ 512,
         /*.n_parts                     =*/ -1,
-        /*.seed                        =*/ 0,
+        /*.seed                        =*/ -1,
         /*.f16_kv                      =*/ false,
         /*.logits_all                  =*/ false,
         /*.vocab_only                  =*/ false,
@@ -2053,7 +2053,7 @@ struct llama_context * llama_init_from_file(
 
     llama_context * ctx = new llama_context;
 
-    if (params.seed <= 0) {
+    if (params.seed < 0) {
         params.seed = time(NULL);
     }
 
@@ -2395,7 +2395,7 @@ int llama_get_kv_cache_token_count(const struct llama_context * ctx) {
 #define LLAMA_MAX_RNG_STATE 64*1024
 
 void llama_set_rng_seed(struct llama_context * ctx, int seed) {
-    if (seed <= 0) {
+    if (seed < 0) {
         seed = time(NULL);
     }
     ctx->rng.seed(seed);
diff --git a/llama.h b/llama.h
index 2f6ce8d831e6c2dabc717545685e1fbaf586b3fa..4052a8ca2c3a984761cb204e5a202f1cde077554 100644 (file)
--- a/llama.h
+++ b/llama.h
@@ -56,7 +56,7 @@ extern "C" {
     struct llama_context_params {
         int n_ctx;   // text context
         int n_parts; // -1 for default
-        int seed;    // RNG seed, 0 for random
+        int seed;    // RNG seed, -1 for random
 
         bool f16_kv;     // use fp16 for KV cache
         bool logits_all; // the llama_eval() call computes all logits, not just the last one