Skip to content

Commit 45cb565

Browse files
lookup: evaluation tools, use corpus/previous gens
1 parent f9c7ba3 commit 45cb565

13 files changed

+773
-61
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ models-mnt
5757
/llava-cli
5858
/lookahead
5959
/lookup
60+
/lookup-create
61+
/lookup-merge
62+
/lookup-stats
6063
/main
6164
/metal
6265
/passkey

Makefile

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -669,14 +669,17 @@ grammar-parser.o: common/grammar-parser.cpp common/grammar-parser.h
669669
train.o: common/train.cpp common/train.h
670670
$(CXX) $(CXXFLAGS) -c $< -o $@
671671

672+
ngram-cache.o: common/ngram-cache.cpp common/ngram-cache.h
673+
$(CXX) $(CXXFLAGS) -c $< -o $@
674+
672675
libllama.so: llama.o ggml.o $(OBJS)
673676
$(CXX) $(CXXFLAGS) -shared -fPIC -o $@ $^ $(LDFLAGS)
674677

675678
libllama.a: llama.o ggml.o $(OBJS) $(COMMON_DEPS)
676679
ar rcs libllama.a llama.o ggml.o $(OBJS) $(COMMON_DEPS)
677680

678681
clean:
679-
rm -vrf *.o tests/*.o *.so *.a *.dll benchmark-matmult common/build-info.cpp *.dot $(COV_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
682+
rm -vrf *.o tests/*.o *.so *.a *.dll benchmark-matmult lookup-create lookup-merge lookup-stats common/build-info.cpp *.dot $(COV_TARGETS) $(BUILD_TARGETS) $(TEST_TARGETS)
680683
find examples pocs -type f -name "*.o" -delete
681684

682685
#
@@ -806,9 +809,15 @@ lookahead: examples/lookahead/lookahead.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS
806809
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
807810
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
808811

809-
lookup: examples/lookup/lookup.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
812+
lookup: examples/lookup/lookup.cpp ggml.o llama.o ngram-cache.o $(COMMON_DEPS) $(OBJS)
810813
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
811814
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
815+
$(CXX) $(CXXFLAGS) -c examples/lookup/lookup-create.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-create.cpp)
816+
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-create.cpp) -o lookup-create $(LDFLAGS)
817+
$(CXX) $(CXXFLAGS) -c examples/lookup/lookup-merge.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-merge.cpp)
818+
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-merge.cpp) -o lookup-merge $(LDFLAGS)
819+
$(CXX) $(CXXFLAGS) -c examples/lookup/lookup-stats.cpp -o $(call GET_OBJ_FILE, examples/lookup/lookup-stats.cpp)
820+
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, examples/lookup/lookup-stats.cpp) -o lookup-stats $(LDFLAGS)
812821

813822
passkey: examples/passkey/passkey.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
814823
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)

common/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ add_library(${TARGET} STATIC
6262
grammar-parser.cpp
6363
train.h
6464
train.cpp
65+
ngram-cache.h
66+
ngram-cache.cpp
6567
)
6668

6769
if (BUILD_SHARED_LIBS)

common/common.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -948,6 +948,22 @@ static bool gpt_params_find_arg(int argc, char ** argv, gpt_params & params, int
948948
}
949949
return true;
950950
}
951+
if (arg == "-lcs" || arg == "--lookup-cache-static") {
952+
if (++i >= argc) {
953+
invalid_param = true;
954+
return true;
955+
}
956+
params.lookup_cache_static = argv[i];
957+
return true;
958+
}
959+
if (arg == "-lcd" || arg == "--lookup-cache-dynamic") {
960+
if (++i >= argc) {
961+
invalid_param = true;
962+
return true;
963+
}
964+
params.lookup_cache_dynamic = argv[i];
965+
return true;
966+
}
951967
if (arg == "--save-all-logits" || arg == "--kl-divergence-base") {
952968
if (++i >= argc) {
953969
invalid_param = true;
@@ -1410,6 +1426,10 @@ void gpt_print_usage(int /*argc*/, char ** argv, const gpt_params & params) {
14101426
printf(" draft model for speculative decoding\n");
14111427
printf(" -ld LOGDIR, --logdir LOGDIR\n");
14121428
printf(" path under which to save YAML logs (no logging if unset)\n");
1429+
printf(" -lcs FNAME, --lookup-cache-static FNAME\n");
1430+
printf(" path to static lookup cache to use for lookup decoding (not updated by generation)\n");
1431+
printf(" -lcd FNAME, --lookup-cache-dynamic FNAME\n");
1432+
printf(" path to dynamic lookup cache to use for lookup decoding (updated by generation)\n");
14131433
printf(" --override-kv KEY=TYPE:VALUE\n");
14141434
printf(" advanced option to override model metadata by key. may be specified multiple times.\n");
14151435
printf(" types: int, float, bool. example: --override-kv tokenizer.ggml.add_bos_token=bool:false\n");

common/common.h

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -88,18 +88,20 @@ struct gpt_params {
8888
// // sampling parameters
8989
struct llama_sampling_params sparams;
9090

91-
std::string model = "models/7B/ggml-model-f16.gguf"; // model path
92-
std::string model_url = ""; // model url to download
93-
std::string model_draft = ""; // draft model for speculative decoding
94-
std::string model_alias = "unknown"; // model alias
95-
std::string prompt = "";
96-
std::string prompt_file = ""; // store the external prompt file name
97-
std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state
98-
std::string input_prefix = ""; // string to prefix user inputs with
99-
std::string input_suffix = ""; // string to suffix user inputs with
91+
std::string model = "models/7B/ggml-model-f16.gguf"; // model path
92+
std::string model_url = ""; // model url to download
93+
std::string model_draft = ""; // draft model for speculative decoding
94+
std::string model_alias = "unknown"; // model alias
95+
std::string prompt = "";
96+
std::string prompt_file = ""; // store the external prompt file name
97+
std::string path_prompt_cache = ""; // path to file for saving/loading prompt eval state
98+
std::string input_prefix = ""; // string to prefix user inputs with
99+
std::string input_suffix = ""; // string to suffix user inputs with
100100
std::vector<std::string> antiprompt; // string upon seeing which more user input is prompted
101-
std::string logdir = ""; // directory in which to save YAML log files
102-
std::string logits_file = ""; // file for saving *all* logits
101+
std::string logdir = ""; // directory in which to save YAML log files
102+
std::string lookup_cache_static = ""; // path of static ngram cache file for lookup decoding
103+
std::string lookup_cache_dynamic = ""; // path of dynamic ngram cache file for lookup decoding
104+
std::string logits_file = ""; // file for saving *all* logits
103105

104106
std::vector<llama_model_kv_override> kv_overrides;
105107

0 commit comments

Comments
 (0)