From 74fe5fc1ea45b37d325b9f815756969f9ad8ef68 Mon Sep 17 00:00:00 2001 From: Howard Su Date: Tue, 27 Jun 2023 08:17:35 +0800 Subject: [PATCH] Change according to the review --- examples/common.cpp | 2 +- examples/embedding/embedding.cpp | 2 +- examples/main/main.cpp | 2 +- examples/perplexity/perplexity.cpp | 2 +- .../train-text-from-scratch.cpp | 2 +- llama.cpp | 4 ++-- llama.h | 12 +++++++----- 7 files changed, 14 insertions(+), 12 deletions(-) diff --git a/examples/common.cpp b/examples/common.cpp index 002302734..534ca84ce 100644 --- a/examples/common.cpp +++ b/examples/common.cpp @@ -110,7 +110,7 @@ bool gpt_params_parse(int argc, char ** argv, gpt_params & params) { invalid_param = true; break; } - params.seed = std::stoi(argv[i]); + params.seed = std::stoul(argv[i]); } else if (arg == "-t" || arg == "--threads") { if (++i >= argc) { invalid_param = true; diff --git a/examples/embedding/embedding.cpp b/examples/embedding/embedding.cpp index dd590a7d2..2b7eb39c5 100644 --- a/examples/embedding/embedding.cpp +++ b/examples/embedding/embedding.cpp @@ -24,7 +24,7 @@ int main(int argc, char ** argv) { fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); - if (params.seed == -1) { + if (params.seed == LLAMA_DEFAULT_SEED) { params.seed = time(NULL); } diff --git a/examples/main/main.cpp b/examples/main/main.cpp index 5439bd178..3a171925b 100644 --- a/examples/main/main.cpp +++ b/examples/main/main.cpp @@ -94,7 +94,7 @@ int main(int argc, char ** argv) { fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); - if (params.seed == -1) { + if (params.seed == LLAMA_DEFAULT_SEED) { params.seed = time(NULL); } diff --git a/examples/perplexity/perplexity.cpp b/examples/perplexity/perplexity.cpp index 0782a2847..dd54ed3c4 100644 --- a/examples/perplexity/perplexity.cpp +++ b/examples/perplexity/perplexity.cpp @@ -136,7 +136,7 @@ int main(int argc, char ** argv) { fprintf(stderr, "%s: build = %d (%s)\n", __func__, BUILD_NUMBER, BUILD_COMMIT); - if (params.seed == -1) { + if (params.seed == LLAMA_DEFAULT_SEED) { params.seed = time(NULL); } diff --git a/examples/train-text-from-scratch/train-text-from-scratch.cpp b/examples/train-text-from-scratch/train-text-from-scratch.cpp index 026305431..05bfa8016 100644 --- a/examples/train-text-from-scratch/train-text-from-scratch.cpp +++ b/examples/train-text-from-scratch/train-text-from-scratch.cpp @@ -3034,7 +3034,7 @@ int main(int argc, char ** argv) { return 1; } - if (params.seed == -1) { + if (params.seed == LLAMA_DEFAULT_SEED) { params.seed = time(NULL); } printf("%s: seed: %u\n", __func__, params.seed); diff --git a/llama.cpp b/llama.cpp index 232df6b4e..b5c9c18d5 100644 --- a/llama.cpp +++ b/llama.cpp @@ -938,7 +938,7 @@ static bool kv_cache_init( struct llama_context_params llama_context_default_params() { struct llama_context_params result = { - /*.seed =*/ (unsigned int)-1, + /*.seed =*/ LLAMA_DEFAULT_SEED, /*.n_ctx =*/ 512, /*.n_batch =*/ 512, /*.gpu_layers =*/ 0, @@ -2692,7 +2692,7 @@ struct llama_context * llama_new_context_with_model( llama_context * ctx = new llama_context(*model, model->vocab); - if (params.seed < 0) { + if (params.seed == LLAMA_DEFAULT_SEED) { params.seed = time(NULL); } diff --git a/llama.h b/llama.h index b5cdc4b17..90a219abb 100644 --- a/llama.h +++ b/llama.h @@ -46,6 +46,8 @@ #define LLAMA_SESSION_MAGIC LLAMA_FILE_MAGIC_GGSN #define LLAMA_SESSION_VERSION 1 +#define LLAMA_DEFAULT_SEED 0xFFFFFFFF + #if defined(GGML_USE_CUBLAS) || defined(GGML_USE_CLBLAST) || defined(GGML_USE_METAL) // Defined when llama.cpp is compiled with support for offloading model layers to GPU. #define LLAMA_SUPPORTS_GPU_OFFLOAD @@ -81,11 +83,11 @@ extern "C" { typedef void (*llama_progress_callback)(float progress, void *ctx); struct llama_context_params { - unsigned int seed; // RNG seed, -1 for random - int n_ctx; // text context - int n_batch; // prompt processing batch size - int n_gpu_layers; // number of layers to store in VRAM - int main_gpu; // the GPU that is used for scratch and small tensors + uint32_t seed; // RNG seed, -1 for random + int32_t n_ctx; // text context + int32_t n_batch; // prompt processing batch size + int32_t n_gpu_layers; // number of layers to store in VRAM + int32_t main_gpu; // the GPU that is used for scratch and small tensors float tensor_split[LLAMA_MAX_DEVICES]; // how to split layers across multiple GPUs // called with a progress value between 0 and 1, pass NULL to disable llama_progress_callback progress_callback;