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

This commit is contained in:
pomoke 2024-02-23 13:38:33 +08:00
parent 15499eb942
commit 593627a8b1
2 changed files with 18 additions and 3 deletions

View file

@ -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.

View file

@ -3,6 +3,7 @@
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <vector>
@ -34,6 +35,17 @@ 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;
@ -41,9 +53,10 @@ int main(int argc, char ** argv) {
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;