Skip to content

Commit b0486ff

Browse files
ericcurtinarthw
authored andcommitted
Introduce llama-run (ggml-org#10291)
It's like simple-chat but it uses smart pointers to avoid manual memory cleanups. Less memory leaks in the code now. Avoid printing multiple dots. Split code into smaller functions. Uses no exception handling. Signed-off-by: Eric Curtin <[email protected]>
1 parent afadaa1 commit b0486ff

File tree

7 files changed

+458
-2
lines changed

7 files changed

+458
-2
lines changed

CMakeLists.txt

+5-2
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,11 @@ if (GGML_TARGET_DEFINES)
163163
list(APPEND GGML_TRANSIENT_DEFINES ${GGML_TARGET_DEFINES})
164164
endif()
165165
get_target_property(GGML_LINK_LIBRARIES ggml LINK_LIBRARIES)
166-
167-
set_target_properties(llama PROPERTIES PUBLIC_HEADER ${CMAKE_CURRENT_SOURCE_DIR}/include/llama.h)
166+
# all public headers
167+
set(LLAMA_PUBLIC_HEADERS
168+
${CMAKE_CURRENT_SOURCE_DIR}/include/llama.h
169+
${CMAKE_CURRENT_SOURCE_DIR}/include/llama-cpp.h)
170+
set_target_properties(llama PROPERTIES PUBLIC_HEADER "${LLAMA_PUBLIC_HEADERS}")
168171
install(TARGETS llama LIBRARY PUBLIC_HEADER)
169172

170173
configure_package_config_file(

Makefile

+6
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ BUILD_TARGETS = \
3434
llama-server \
3535
llama-simple \
3636
llama-simple-chat \
37+
llama-run \
3738
llama-speculative \
3839
llama-tokenize \
3940
llama-vdot \
@@ -1167,6 +1168,11 @@ llama-infill: examples/infill/infill.cpp \
11671168
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
11681169
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
11691170

1171+
llama-run: examples/run/run.cpp \
1172+
$(OBJ_ALL)
1173+
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)
1174+
$(CXX) $(CXXFLAGS) $(filter-out %.h $<,$^) $(call GET_OBJ_FILE, $<) -o $@ $(LDFLAGS)
1175+
11701176
llama-simple: examples/simple/simple.cpp \
11711177
$(OBJ_ALL)
11721178
$(CXX) $(CXXFLAGS) -c $< -o $(call GET_OBJ_FILE, $<)

examples/CMakeLists.txt

+1
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ else()
3636
add_subdirectory(server)
3737
endif()
3838
add_subdirectory(save-load-state)
39+
add_subdirectory(run)
3940
add_subdirectory(simple)
4041
add_subdirectory(simple-chat)
4142
add_subdirectory(speculative)

examples/run/CMakeLists.txt

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

examples/run/README.md

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# llama.cpp/example/run
2+
3+
The purpose of this example is to demonstrate a minimal usage of llama.cpp for running models.
4+
5+
```bash
6+
./llama-run Meta-Llama-3.1-8B-Instruct.gguf
7+
...

0 commit comments

Comments
 (0)