Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix grammar-based sampling issue in server #2566

Merged
merged 1 commit into from
Aug 10, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions examples/server/server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ struct llama_server_context
llama_context *ctx = nullptr;
gpt_params params;

grammar_parser::parse_state parsed_grammar;
llama_grammar *grammar = nullptr;

bool truncated = false;
Expand Down Expand Up @@ -241,10 +242,13 @@ struct llama_server_context
stopped_limit = false;
stopping_word = "";
multibyte_pending = 0;
grammar = nullptr;

n_remain = 0;
n_past = 0;

if (grammar != nullptr) {
llama_grammar_free(grammar);
grammar = nullptr;
}
}

bool loadModel(const gpt_params &params_)
Expand All @@ -265,8 +269,6 @@ struct llama_server_context
bool loadGrammar()
{
if (!params.grammar.empty()) {
grammar_parser::parse_state parsed_grammar;

parsed_grammar = grammar_parser::parse(params.grammar.c_str());
// will be empty (default) if there are parse errors
if (parsed_grammar.rules.empty()) {
Expand Down