From: Georgi Gerganov Date: Tue, 16 Apr 2024 06:28:33 +0000 (+0300) Subject: perplexity : require positive --ctx-size arg (#6695) X-Git-Tag: upstream/0.0.4488~1806 X-Git-Url: https://git.djapps.eu/?a=commitdiff_plain;h=58227ffdeb4fb89cacb0cffaadf76b1914324ad3;p=pkg%2Fggml%2Fsources%2Fllama.cpp perplexity : require positive --ctx-size arg (#6695) --- diff --git a/examples/perplexity/perplexity.cpp b/examples/perplexity/perplexity.cpp index bab79aae..9a3374fd 100644 --- a/examples/perplexity/perplexity.cpp +++ b/examples/perplexity/perplexity.cpp @@ -1852,12 +1852,20 @@ int main(int argc, char ** argv) { const int32_t n_ctx = params.n_ctx; + if (n_ctx <= 0) { + fprintf(stderr, "%s: perplexity tool requires '--ctx-size' > 0\n", __func__); + return 1; + } + const bool ppl = !params.hellaswag && !params.winogrande && !params.multiple_choice && !params.kl_divergence; + if (ppl) { - int n_seq = std::max(1, params.n_batch / n_ctx); - int32_t n_kv = n_seq * n_ctx; + const int32_t n_seq = std::max(1, params.n_batch / n_ctx); + const int32_t n_kv = n_seq * n_ctx; + params.n_parallel = n_seq; - params.n_ctx = n_kv; + params.n_ctx = n_kv; + params.n_batch = std::min(params.n_batch, n_kv); } else { params.n_batch = std::min(params.n_batch, params.n_ctx);