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

lookahead: set parameter W,N,G from environment variable #5677

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 2 additions & 0 deletions examples/lookahead/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ Demonstration of lookahead decoding technique:
https://lmsys.org/blog/2023-11-21-lookahead-decoding/

More info: https://github.com/ggerganov/llama.cpp/pull/4207

To set W, N and G manually, set them as environment variables.
19 changes: 16 additions & 3 deletions examples/lookahead/lookahead.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>

Expand Down Expand Up @@ -34,16 +35,28 @@ struct ngram_container {
std::vector<llama_token> tokens;
};

int int_from_env(const char *name, int default_value) {
char *value = std::getenv(name);
if (value != nullptr) {
int v = atoi(value);
v = v ? v : default_value;
return v;
} else {
return default_value;
}
}

int main(int argc, char ** argv) {
gpt_params params;

if (gpt_params_parse(argc, argv, params) == false) {
return 1;
}

const int W = 15; // lookahead window
const int N = 5; // n-gram size
const int G = 15; // max verification n-grams
int W = int_from_env("W",15); // lookahead window
int N = int_from_env("N",5); // n-gram size
int G = int_from_env("G",15); // max verification n-grams


const bool dump_kv_cache = params.dump_kv_cache;

Expand Down