Skip to content

Commit 922754a

Browse files
ggerganovslaren
andauthored
lookahead : add example for lookahead decoding (#4207)
* lookahead : init * lookahead : generate and store n-grams * lookahead : use loop instead recursion to generate n-grams * lookahead : initial working implementation * lookahead : filter repeating n-grams * lookahead : use deterministic init * lookahead : add to Makefile * lookahead : fix a bug in the seq_id of the lookahead tokens * lookahead : add comments --------- Co-authored-by: slaren <slarengh@gmail.com>
1 parent 22da055 commit 922754a

File tree

5 files changed

+498
-1
lines changed

5 files changed

+498
-1
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ models-mnt
4747
/libllama.so
4848
/llama-bench
4949
/llava-cli
50+
/lookahead
5051
/main
5152
/metal
5253
/perplexity

Makefile

+4-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
BUILD_TARGETS = \
33
main quantize quantize-stats perplexity embedding vdot q8dot train-text-from-scratch convert-llama2c-to-ggml \
44
simple batched batched-bench save-load-state server gguf llama-bench libllava.a llava-cli baby-llama beam-search \
5-
speculative infill tokenize benchmark-matmult parallel finetune export-lora tests/test-c.o
5+
speculative infill tokenize benchmark-matmult parallel finetune export-lora lookahead tests/test-c.o
66

77
# Binaries only useful for tests
88
TEST_TARGETS = \
@@ -657,6 +657,9 @@ speculative: examples/speculative/speculative.cpp ggml.o llama.o $(COMMON_DEPS)
657657
parallel: examples/parallel/parallel.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
658658
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
659659

660+
lookahead: examples/lookahead/lookahead.cpp ggml.o llama.o $(COMMON_DEPS) $(OBJS)
661+
$(CXX) $(CXXFLAGS) $(filter-out %.h,$^) -o $@ $(LDFLAGS)
662+
660663
ifdef LLAMA_METAL
661664
metal: examples/metal/metal.cpp ggml.o $(OBJS)
662665
$(CXX) $(CXXFLAGS) $^ -o $@ $(LDFLAGS)

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ else()
3232
add_subdirectory(save-load-state)
3333
add_subdirectory(simple)
3434
add_subdirectory(speculative)
35+
add_subdirectory(lookahead)
3536
add_subdirectory(train-text-from-scratch)
3637
if (LLAMA_METAL)
3738
add_subdirectory(metal)

examples/lookahead/CMakeLists.txt

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
set(TARGET lookahead)
2+
add_executable(${TARGET} lookahead.cpp)
3+
install(TARGETS ${TARGET} RUNTIME)
4+
target_link_libraries(${TARGET} PRIVATE common llama ${CMAKE_THREAD_LIBS_INIT})
5+
target_compile_features(${TARGET} PRIVATE cxx_std_11)

0 commit comments

Comments
 (0)