MCPcopy Create free account
hub / github.com/appdevforall/CodeOnTheGo / main

Function main

subprojects/llama.cpp/tools/perplexity/perplexity.cpp:1978–2070  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1976}
1977
1978int main(int argc, char ** argv) {
1979 common_params params;
1980
1981 params.n_ctx = 512;
1982 params.escape = false;
1983
1984 if (!common_params_parse(argc, argv, params, LLAMA_EXAMPLE_PERPLEXITY)) {
1985 return 1;
1986 }
1987
1988 common_init();
1989
1990 const int32_t n_ctx = params.n_ctx;
1991
1992 if (n_ctx <= 0) {
1993 LOG_ERR("%s: perplexity tool requires '--ctx-size' > 0\n", __func__);
1994 return 1;
1995 }
1996
1997 const bool ppl = !params.hellaswag && !params.winogrande && !params.multiple_choice && !params.kl_divergence;
1998
1999 if (ppl) {
2000 const int32_t n_seq = std::max(1, params.n_batch / n_ctx);
2001 const int32_t n_kv = n_seq * n_ctx;
2002
2003 params.n_parallel = n_seq;
2004 params.n_ctx = n_kv;
2005
2006 params.n_batch = std::min(params.n_batch, n_kv);
2007 } else {
2008 params.n_batch = std::min(params.n_batch, params.n_ctx);
2009 if (params.kl_divergence) {
2010 params.n_parallel = 1;
2011 } else {
2012 // ensure there's at least enough seq_ids for HellaSwag
2013 params.n_parallel = std::max(4, params.n_parallel);
2014 }
2015 }
2016
2017 if (params.ppl_stride > 0) {
2018 LOG_INF("Will perform strided perplexity calculation -> adjusting context size from %d to %d\n",
2019 params.n_ctx, params.n_ctx + params.ppl_stride/2);
2020 params.n_ctx += params.ppl_stride/2;
2021 }
2022
2023 llama_backend_init();
2024 llama_numa_init(params.numa);
2025
2026 // load the model and apply lora adapter, if any
2027 auto llama_init = common_init_from_params(params);
2028
2029 auto * model = llama_init->model();
2030 auto * ctx = llama_init->context();
2031
2032 if (model == NULL) {
2033 LOG_ERR("%s: unable to load model\n", __func__);
2034 return 1;
2035 }

Callers

nothing calls this directly

Calls 15

common_params_parseFunction · 0.85
common_initFunction · 0.85
maxFunction · 0.85
minFunction · 0.85
llama_backend_initFunction · 0.85
llama_numa_initFunction · 0.85
common_init_from_paramsFunction · 0.85
llama_model_n_ctx_trainFunction · 0.85
hellaswag_scoreFunction · 0.85
winogrande_scoreFunction · 0.85
multiple_choice_scoreFunction · 0.85

Tested by

no test coverage detected