Skip to content

Commit 58227ff

Browse files
authored
perplexity : require positive --ctx-size arg (ggml-org#6695)
1 parent 4fbd809 commit 58227ff

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

examples/perplexity/perplexity.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1852,12 +1852,20 @@ int main(int argc, char ** argv) {
18521852

18531853
const int32_t n_ctx = params.n_ctx;
18541854

1855+
if (n_ctx <= 0) {
1856+
fprintf(stderr, "%s: perplexity tool requires '--ctx-size' > 0\n", __func__);
1857+
return 1;
1858+
}
1859+
18551860
const bool ppl = !params.hellaswag && !params.winogrande && !params.multiple_choice && !params.kl_divergence;
1861+
18561862
if (ppl) {
1857-
int n_seq = std::max(1, params.n_batch / n_ctx);
1858-
int32_t n_kv = n_seq * n_ctx;
1863+
const int32_t n_seq = std::max(1, params.n_batch / n_ctx);
1864+
const int32_t n_kv = n_seq * n_ctx;
1865+
18591866
params.n_parallel = n_seq;
1860-
params.n_ctx = n_kv;
1867+
params.n_ctx = n_kv;
1868+
18611869
params.n_batch = std::min(params.n_batch, n_kv);
18621870
} else {
18631871
params.n_batch = std::min(params.n_batch, params.n_ctx);

0 commit comments

Comments
 (0)