default penalize_nl to false + format
This commit is contained in:
parent
40e13805d9
commit
d58e48663d
1 changed files with 114 additions and 173 deletions
|
@ -507,210 +507,151 @@ bool server_params_parse(int argc, char **argv, server_params &sparams, gpt_para
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool parse_options_completion(json body, llama_server_context& llama, Response &res) {
|
bool parse_options_completion(json body, llama_server_context& llama, Response &res)
|
||||||
|
{
|
||||||
gpt_params default_params;
|
gpt_params default_params;
|
||||||
if (!body["stream"].is_null())
|
if (!body["stream"].is_null()) {
|
||||||
{
|
llama.stream = body["stream"].get<bool>();
|
||||||
llama.stream = body["stream"].get<bool>();
|
} else {
|
||||||
|
llama.stream = false;
|
||||||
}
|
}
|
||||||
else
|
if (!body["n_predict"].is_null()) {
|
||||||
{
|
llama.params.n_predict = body["n_predict"].get<int>();
|
||||||
llama.stream = false;
|
} else {
|
||||||
|
llama.params.n_predict = default_params.n_predict;
|
||||||
}
|
}
|
||||||
if (!body["n_predict"].is_null())
|
if (!body["top_k"].is_null()) {
|
||||||
{
|
llama.params.top_k = body["top_k"].get<int>();
|
||||||
llama.params.n_predict = body["n_predict"].get<int>();
|
} else {
|
||||||
|
llama.params.top_k = default_params.top_k;
|
||||||
}
|
}
|
||||||
else
|
if (!body["top_p"].is_null()) {
|
||||||
{
|
llama.params.top_p = body["top_p"].get<float>();
|
||||||
llama.params.n_predict = default_params.n_predict;
|
} else {
|
||||||
|
llama.params.top_p = default_params.top_p;
|
||||||
}
|
}
|
||||||
if (!body["top_k"].is_null())
|
if (!body["tfs_z"].is_null()) {
|
||||||
{
|
llama.params.tfs_z = body["tfs_z"].get<float>();
|
||||||
llama.params.top_k = body["top_k"].get<int>();
|
} else {
|
||||||
|
llama.params.tfs_z = default_params.tfs_z;
|
||||||
}
|
}
|
||||||
else
|
if (!body["typical_p"].is_null()) {
|
||||||
{
|
llama.params.typical_p = body["typical_p"].get<float>();
|
||||||
llama.params.top_k = default_params.top_k;
|
} else {
|
||||||
|
llama.params.typical_p = default_params.typical_p;
|
||||||
}
|
}
|
||||||
if (!body["top_p"].is_null())
|
if (!body["repeat_last_n"].is_null()) {
|
||||||
{
|
llama.params.repeat_last_n = body["repeat_last_n"].get<int>();
|
||||||
llama.params.top_p = body["top_p"].get<float>();
|
} else {
|
||||||
|
llama.params.repeat_last_n = default_params.repeat_last_n;
|
||||||
}
|
}
|
||||||
else
|
if (!body["temperature"].is_null()) {
|
||||||
{
|
llama.params.temp = body["temperature"].get<float>();
|
||||||
llama.params.top_p = default_params.top_p;
|
} else {
|
||||||
|
llama.params.temp = default_params.temp;
|
||||||
}
|
}
|
||||||
if (!body["tfs_z"].is_null())
|
if (!body["repeat_penalty"].is_null()) {
|
||||||
{
|
llama.params.repeat_penalty = body["repeat_penalty"].get<float>();
|
||||||
llama.params.tfs_z = body["tfs_z"].get<float>();
|
} else {
|
||||||
|
llama.params.repeat_penalty = default_params.repeat_penalty;
|
||||||
}
|
}
|
||||||
else
|
if (!body["presence_penalty"].is_null()) {
|
||||||
{
|
llama.params.presence_penalty = body["presence_penalty"].get<float>();
|
||||||
llama.params.tfs_z = default_params.tfs_z;
|
} else {
|
||||||
|
llama.params.presence_penalty = default_params.presence_penalty;
|
||||||
}
|
}
|
||||||
if (!body["typical_p"].is_null())
|
if (!body["frequency_penalty"].is_null()) {
|
||||||
{
|
llama.params.frequency_penalty = body["frequency_penalty"].get<float>();
|
||||||
llama.params.typical_p = body["typical_p"].get<float>();
|
} else {
|
||||||
|
llama.params.frequency_penalty = default_params.frequency_penalty;
|
||||||
}
|
}
|
||||||
else
|
if (!body["mirostat"].is_null()) {
|
||||||
{
|
llama.params.mirostat = body["mirostat"].get<float>();
|
||||||
llama.params.typical_p = default_params.typical_p;
|
} else {
|
||||||
|
llama.params.mirostat = default_params.mirostat;
|
||||||
}
|
}
|
||||||
if (!body["repeat_last_n"].is_null())
|
if (!body["mirostat_tau"].is_null()) {
|
||||||
{
|
llama.params.mirostat_tau = body["mirostat_tau"].get<float>();
|
||||||
llama.params.repeat_last_n = body["repeat_last_n"].get<int>();
|
} else {
|
||||||
|
llama.params.mirostat_tau = default_params.mirostat_tau;
|
||||||
}
|
}
|
||||||
else
|
if (!body["mirostat_eta"].is_null()) {
|
||||||
{
|
llama.params.mirostat_eta = body["mirostat_eta"].get<float>();
|
||||||
llama.params.repeat_last_n = default_params.repeat_last_n;
|
} else {
|
||||||
|
llama.params.mirostat_eta = default_params.mirostat_eta;
|
||||||
}
|
}
|
||||||
if (!body["temperature"].is_null())
|
if (!body["penalize_nl"].is_null()) {
|
||||||
{
|
llama.params.penalize_nl = body["penalize_nl"].get<float>();
|
||||||
llama.params.temp = body["temperature"].get<float>();
|
} else {
|
||||||
|
llama.params.penalize_nl = false;
|
||||||
}
|
}
|
||||||
else
|
if (!body["n_keep"].is_null()) {
|
||||||
{
|
llama.params.n_keep = body["n_keep"].get<int>();
|
||||||
llama.params.temp = default_params.temp;
|
} else {
|
||||||
|
llama.params.n_keep = default_params.n_keep;
|
||||||
}
|
}
|
||||||
if (!body["repeat_penalty"].is_null())
|
if (!body["seed"].is_null()) {
|
||||||
{
|
|
||||||
llama.params.repeat_penalty = body["repeat_penalty"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.repeat_penalty = default_params.repeat_penalty;
|
|
||||||
}
|
|
||||||
if (!body["presence_penalty"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.presence_penalty = body["presence_penalty"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.presence_penalty = default_params.presence_penalty;
|
|
||||||
}
|
|
||||||
if (!body["frequency_penalty"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.frequency_penalty = body["frequency_penalty"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.frequency_penalty = default_params.frequency_penalty;
|
|
||||||
}
|
|
||||||
if (!body["mirostat"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.mirostat = body["mirostat"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.mirostat = default_params.mirostat;
|
|
||||||
}
|
|
||||||
if (!body["mirostat_tau"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.mirostat_tau = body["mirostat_tau"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.mirostat_tau = default_params.mirostat_tau;
|
|
||||||
}
|
|
||||||
if (!body["mirostat_eta"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.mirostat_eta = body["mirostat_eta"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.mirostat_eta = default_params.mirostat_eta;
|
|
||||||
}
|
|
||||||
if (!body["penalize_nl"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.penalize_nl = body["penalize_nl"].get<float>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.penalize_nl = default_params.penalize_nl;
|
|
||||||
}
|
|
||||||
if (!body["n_keep"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.n_keep = body["n_keep"].get<int>();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.n_keep = default_params.n_keep;
|
|
||||||
}
|
|
||||||
if (!body["seed"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.seed = body["seed"].get<int>();
|
llama.params.seed = body["seed"].get<int>();
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
llama.params.seed = time(NULL);
|
llama.params.seed = time(NULL);
|
||||||
}
|
}
|
||||||
if (!body["ignore_eos"].is_null() && body["ignore_eos"].get<bool>())
|
if (!body["ignore_eos"].is_null() && body["ignore_eos"].get<bool>()) {
|
||||||
{
|
llama.params.logit_bias[llama_token_eos()] = -INFINITY;
|
||||||
llama.params.logit_bias[llama_token_eos()] = -INFINITY;
|
} else {
|
||||||
|
llama.params.logit_bias.erase(llama_token_eos());
|
||||||
}
|
}
|
||||||
else
|
if (!body["prompt"].is_null()) {
|
||||||
{
|
|
||||||
llama.params.logit_bias.erase(llama_token_eos());
|
|
||||||
}
|
|
||||||
if (!body["prompt"].is_null())
|
|
||||||
{
|
|
||||||
llama.params.prompt = body["prompt"].get<std::string>();
|
llama.params.prompt = body["prompt"].get<std::string>();
|
||||||
}
|
} else {
|
||||||
else
|
json data = {{"status", "error"}, {"reason", "You need to pass the prompt"}};
|
||||||
{
|
|
||||||
json data = {
|
|
||||||
{"status", "error"},
|
|
||||||
{"reason", "You need to pass the prompt"}};
|
|
||||||
res.set_content(data.dump(llama.json_indent), "application/json");
|
res.set_content(data.dump(llama.json_indent), "application/json");
|
||||||
res.status = 400;
|
res.status = 400;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!body["stop"].is_null())
|
if (!body["stop"].is_null()) {
|
||||||
{
|
|
||||||
llama.params.antiprompt = body["stop"].get<std::vector<std::string>>();
|
llama.params.antiprompt = body["stop"].get<std::vector<std::string>>();
|
||||||
}
|
} else {
|
||||||
else
|
llama.params.antiprompt.clear();
|
||||||
{
|
|
||||||
llama.params.antiprompt.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (llama.verbose) {
|
if (llama.verbose) {
|
||||||
std::string tmp_stop =
|
std::string tmp_stop =
|
||||||
std::accumulate(llama.params.antiprompt.begin(), llama.params.antiprompt.end(),
|
std::accumulate(llama.params.antiprompt.begin(), llama.params.antiprompt.end(),
|
||||||
std::string{}, [](std::string a, std::string b) {
|
std::string{}, [](std::string a, std::string b) {
|
||||||
return a + (a != "" ? ", \"" : "\"") + b + "\"";
|
return a + (a != "" ? ", \"" : "\"") + b + "\"";
|
||||||
});
|
});
|
||||||
|
|
||||||
fprintf(stderr,
|
fprintf(stderr,
|
||||||
"-------------------------\n"
|
"-------------------------\n"
|
||||||
"/completion parameters: {\n"
|
"/completion parameters: {\n"
|
||||||
" stream: %d,\n"
|
" stream: %d,\n"
|
||||||
" frequency_penalty: %f,\n"
|
" ignore_eos: %d,\n"
|
||||||
" mirostat: %d,\n"
|
" frequency_penalty: %f,\n"
|
||||||
" mirostat_eta: %f,\n"
|
" mirostat: %d,\n"
|
||||||
" mirostat_tau: %f,\n"
|
" mirostat_eta: %f,\n"
|
||||||
" n_keep: %d,\n"
|
" mirostat_tau: %f,\n"
|
||||||
" n_predict: %d,\n"
|
" n_keep: %d,\n"
|
||||||
" penalize_nl: %d,\n"
|
" n_predict: %d,\n"
|
||||||
" presence_penalty: %f,\n"
|
" penalize_nl: %d,\n"
|
||||||
" repeat_last_n: %d,\n"
|
" presence_penalty: %f,\n"
|
||||||
" repeat_penalty: %f,\n"
|
" repeat_last_n: %d,\n"
|
||||||
" seed: %d,\n"
|
" repeat_penalty: %f,\n"
|
||||||
" stop: [%s],\n"
|
" seed: %d,\n"
|
||||||
" temperature: %f,\n"
|
" stop: [%s],\n"
|
||||||
" tfs_z: %f,\n"
|
" temperature: %f,\n"
|
||||||
" top_k: %d,\n"
|
" tfs_z: %f,\n"
|
||||||
" top_p: %f,\n"
|
" top_k: %d,\n"
|
||||||
" typical_p: %f,\n"
|
" top_p: %f,\n"
|
||||||
"}\nPROMPT[%s]\n",
|
" typical_p: %f,\n"
|
||||||
llama.stream, llama.params.frequency_penalty, llama.params.mirostat,
|
"}\nPROMPT[%s]\n",
|
||||||
llama.params.mirostat_eta, llama.params.mirostat_tau, llama.params.n_keep,
|
llama.stream, -INFINITY == llama.params.logit_bias[llama_token_eos()],
|
||||||
llama.params.n_predict, llama.params.penalize_nl,
|
llama.params.frequency_penalty, llama.params.mirostat,
|
||||||
llama.params.presence_penalty, llama.params.repeat_last_n,
|
llama.params.mirostat_eta, llama.params.mirostat_tau, llama.params.n_keep,
|
||||||
llama.params.repeat_penalty, llama.params.seed, tmp_stop.c_str(),
|
llama.params.n_predict, llama.params.penalize_nl,
|
||||||
llama.params.temp, llama.params.tfs_z, llama.params.top_k,
|
llama.params.presence_penalty, llama.params.repeat_last_n,
|
||||||
llama.params.top_p, llama.params.typical_p, llama.params.prompt.c_str());
|
llama.params.repeat_penalty, llama.params.seed, tmp_stop.c_str(),
|
||||||
|
llama.params.temp, llama.params.tfs_z, llama.params.top_k, llama.params.top_p,
|
||||||
|
llama.params.typical_p, llama.params.prompt.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue