Skip to content

Commit 0d439d1

Browse files
authored
Merge pull request #541 from docker/unfork-llamacpp
Remove llama.cpp server fork and build upstream
2 parents a9cba1a + ab75308 commit 0d439d1

19 files changed

+38
-10731
lines changed

llamacpp/native/CMakeLists.txt

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,22 +8,43 @@ project(
88

99
option(DDLLAMA_BUILD_SERVER "Build the DD llama.cpp server executable" ON)
1010
option(DDLLAMA_BUILD_UTILS "Build utilities, e.g. nv-gpu-info" OFF)
11-
set(DDLLAMA_PATCH_COMMAND "patch" CACHE STRING "patch command")
1211

1312
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1413
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
1514

1615
if (DDLLAMA_BUILD_SERVER)
17-
set(LLAMA_BUILD_COMMON ON)
16+
# Build upstream llama.cpp with server enabled
17+
# Only set these options if they're not already defined to allow consumers to override
18+
if(NOT DEFINED LLAMA_BUILD_COMMON)
19+
set(LLAMA_BUILD_COMMON ON CACHE BOOL "Build common utils library")
20+
endif()
21+
if(NOT DEFINED LLAMA_BUILD_TOOLS)
22+
set(LLAMA_BUILD_TOOLS ON CACHE BOOL "Build tools")
23+
endif()
24+
if(NOT DEFINED LLAMA_BUILD_SERVER)
25+
set(LLAMA_BUILD_SERVER ON CACHE BOOL "Build server")
26+
endif()
1827
add_subdirectory(vendor/llama.cpp)
19-
# Get build info and set version for mtmd just like it's done in llama.cpp/CMakeLists.txt
20-
include(vendor/llama.cpp/cmake/build-info.cmake)
21-
if (NOT DEFINED LLAMA_BUILD_NUMBER)
22-
set(LLAMA_BUILD_NUMBER ${BUILD_NUMBER})
28+
29+
# Create custom target to copy llama-server to com.docker.llama-server
30+
if (WIN32)
31+
set(LLAMA_SERVER_DST "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/com.docker.llama-server.exe")
32+
else()
33+
set(LLAMA_SERVER_DST "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/com.docker.llama-server")
2334
endif()
24-
set(LLAMA_INSTALL_VERSION 0.0.${LLAMA_BUILD_NUMBER})
25-
add_subdirectory(vendor/llama.cpp/tools/mtmd)
26-
add_subdirectory(src/server)
35+
36+
add_custom_command(OUTPUT "${LLAMA_SERVER_DST}"
37+
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:llama-server>" "${LLAMA_SERVER_DST}"
38+
DEPENDS llama-server
39+
COMMENT "Creating com.docker.llama-server from llama-server"
40+
)
41+
42+
add_custom_target(com.docker.llama-server ALL DEPENDS "${LLAMA_SERVER_DST}")
43+
44+
# Install the renamed binary using TARGETS instead of PROGRAMS for better cross-platform support
45+
install(TARGETS llama-server
46+
RUNTIME DESTINATION bin
47+
RENAME "com.docker.llama-server${CMAKE_EXECUTABLE_SUFFIX}")
2748
endif()
2849

2950
if (WIN32 AND DDLLAMA_BUILD_UTILS)

llamacpp/native/README.md

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Native llama-server
22

3+
This project builds the upstream llama.cpp server (`llama-server`) directly from the llama.cpp submodule and renames it to `com.docker.llama-server`.
4+
35
## Building
46

57
cmake -B build
@@ -15,7 +17,7 @@
1517

1618
This project uses llama.cpp as a git submodule located at `vendor/llama.cpp`, which points to the official llama.cpp repository at https://github.com/ggml-org/llama.cpp.git.
1719

18-
The project applies custom patches to llama.cpp's server implementation (`server.cpp` and `utils.hpp`) to integrate with the Docker model-runner architecture. These patches are maintained in `src/server/server.patch`.
20+
We build the upstream `llama-server` binary directly without any modifications.
1921

2022
### Prerequisites
2123

@@ -45,32 +47,20 @@ If the submodule is already initialized, this command is safe to run and will en
4547
popd
4648
```
4749

48-
3. **Apply the custom llama-server patch:**
50+
3. **Build and test:**
4951

5052
```bash
51-
make -C src/server clean
52-
make -C src/server
53-
```
54-
55-
This will:
56-
- Clean the previous patched files
57-
- Copy the new `server.cpp` and `utils.hpp` from the updated llama.cpp
58-
- Apply our custom patches from `src/server/server.patch`
59-
60-
4. **Build and test:**
53+
# Build from the native directory
54+
cmake -B build
55+
cmake --build build --parallel 8 --config Release
6156

62-
```bash
63-
# Build from the native directory
64-
cmake -B build
65-
cmake --build build --parallel 8 --config Release
66-
6757
# Test the build
6858
./build/bin/com.docker.llama-server --model <path to model>
6959
```
7060

7161
Make sure everything builds cleanly without errors.
7262

73-
5. **Commit the submodule update:**
63+
4. **Commit the submodule update:**
7464

7565
```bash
7666
git add vendor/llama.cpp

llamacpp/native/src/server/CMakeLists.txt

Lines changed: 0 additions & 31 deletions
This file was deleted.

llamacpp/native/src/server/Makefile

Lines changed: 0 additions & 18 deletions
This file was deleted.

llamacpp/native/src/server/README.md

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)