Skip to content

Commit 63e78a8

Browse files
committed
test(server): keep server unit tests CPU-only
1 parent 35ae645 commit 63e78a8

5 files changed

Lines changed: 106 additions & 74 deletions

File tree

dflash/CMakeLists.txt

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ add_library(dflash_common STATIC
256256
src/common/daemon_loop.cpp
257257
src/common/gguf_inspect.cpp
258258
src/common/backend_factory.cpp
259+
src/placement/placement_config.cpp
259260
src/common/layer_split_utils.cpp
260261
src/common/ddtree.cpp
261262
src/common/peer_access.cpp
@@ -720,22 +721,46 @@ if(DFLASH27B_TESTS)
720721

721722
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/test/test_server_unit.cpp")
722723
add_executable(test_server_unit test/test_server_unit.cpp)
723-
target_sources(test_server_unit PRIVATE src/server/http_server.cpp)
724+
target_sources(test_server_unit PRIVATE
725+
src/common/backend_ipc.cpp
726+
src/common/daemon_loop.cpp
727+
src/common/layer_split_backend.cpp
728+
src/common/sampler.cpp
729+
src/placement/placement_config.cpp
730+
src/server/chat_template.cpp
731+
src/server/disk_prefix_cache.cpp
732+
src/server/http_server.cpp
733+
src/server/prefix_cache.cpp
734+
src/server/reasoning.cpp
735+
src/server/sse_emitter.cpp
736+
src/server/tokenizer.cpp
737+
src/server/tool_hint.cpp
738+
src/server/tool_memory.cpp
739+
src/server/tool_parser.cpp
740+
deps/llama.cpp/common/jinja/lexer.cpp
741+
deps/llama.cpp/common/jinja/parser.cpp
742+
deps/llama.cpp/common/jinja/runtime.cpp
743+
deps/llama.cpp/common/jinja/value.cpp
744+
deps/llama.cpp/common/jinja/string.cpp
745+
deps/llama.cpp/common/jinja/caps.cpp
746+
deps/llama.cpp/common/unicode.cpp
747+
)
724748
target_include_directories(test_server_unit PRIVATE ${DFLASH27B_SRC_INCLUDE_DIRS})
749+
target_include_directories(test_server_unit PRIVATE
750+
${CMAKE_CURRENT_SOURCE_DIR}/deps/llama.cpp/ggml/src
751+
${CMAKE_CURRENT_SOURCE_DIR}/deps/llama.cpp/common)
725752
if(DFLASH27B_GPU_BACKEND STREQUAL "hip")
726753
target_compile_definitions(test_server_unit PRIVATE DFLASH27B_BACKEND_HIP=1 GGML_USE_HIP)
727754
else()
728755
target_compile_definitions(test_server_unit PRIVATE
729756
DFLASH27B_BACKEND_CUDA=1
730757
DFLASH27B_CUDA_MIN_SM=${_dflash_cuda_min_sm})
731758
endif()
732-
target_link_libraries(test_server_unit PRIVATE dflash_common ggml ${DFLASH27B_GGML_BACKEND_TARGET})
733-
if(DFLASH27B_GPU_BACKEND STREQUAL "cuda")
734-
find_package(CUDAToolkit REQUIRED)
735-
target_link_libraries(test_server_unit PRIVATE CUDA::cudart)
736-
else()
737-
target_link_libraries(test_server_unit PRIVATE hip::host)
738-
endif()
759+
target_link_libraries(test_server_unit PRIVATE
760+
ggml-base
761+
ggml-cpu
762+
nlohmann_json::nlohmann_json
763+
pthread)
739764
add_test(NAME server_unit COMMAND test_server_unit)
740765
endif()
741766

dflash/src/common/layer_split_utils.cpp

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
#include <algorithm>
88
#include <cmath>
99
#include <cstdio>
10-
#include <set>
1110

1211
namespace dflash::common {
1312

@@ -110,61 +109,4 @@ void free_layer_split_snapshot_backends(
110109
snapshot_backends.clear();
111110
}
112111

113-
std::string validate_device_placement(
114-
const DevicePlacement & dp,
115-
int device_count)
116-
{
117-
const bool validate_device_count = device_count >= 0;
118-
if (validate_device_count && device_count == 0) {
119-
return "no GPU devices available";
120-
}
121-
122-
if (dp.gpu < 0 ||
123-
(validate_device_count && dp.gpu >= device_count)) {
124-
return "primary gpu " + std::to_string(dp.gpu) + " out of range" +
125-
(validate_device_count
126-
? " [0, " + std::to_string(device_count) + ")"
127-
: "");
128-
}
129-
130-
if (!dp.layer_split_gpus.empty()) {
131-
if (dp.layer_split_gpus.size() < 2) {
132-
return "layer_split_gpus must have at least 2 entries";
133-
}
134-
135-
std::set<int> seen;
136-
for (int g : dp.layer_split_gpus) {
137-
if (g < 0 ||
138-
(validate_device_count && g >= device_count)) {
139-
return "layer_split gpu " + std::to_string(g) +
140-
" out of range" +
141-
(validate_device_count
142-
? " [0, " + std::to_string(device_count) + ")"
143-
: "");
144-
}
145-
if (!seen.insert(g).second) {
146-
return "duplicate gpu " + std::to_string(g) + " in layer_split_gpus";
147-
}
148-
}
149-
150-
if (!dp.layer_split_weights.empty() &&
151-
dp.layer_split_weights.size() != dp.layer_split_gpus.size()) {
152-
return "layer_split_weights size (" +
153-
std::to_string(dp.layer_split_weights.size()) +
154-
") != gpu count (" +
155-
std::to_string(dp.layer_split_gpus.size()) + ")";
156-
}
157-
158-
for (double w : dp.layer_split_weights) {
159-
if (w <= 0.0 || !std::isfinite(w)) {
160-
return "layer_split_weights must be positive finite values";
161-
}
162-
}
163-
}
164-
165-
if (dp.max_ctx <= 0) return "max_ctx must be positive";
166-
167-
return {}; // ok
168-
}
169-
170112
} // namespace dflash::common

dflash/src/common/layer_split_utils.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,12 +91,4 @@ void free_layer_split_snapshot_backends(
9191
const std::vector<LayerSplitShardMeta *> & shards,
9292
std::vector<ggml_backend_t> & snapshot_backends);
9393

94-
// Validate a DevicePlacement against system constraints.
95-
// If device_count is negative, only validates structural constraints that do
96-
// not require querying the runtime-visible GPU count.
97-
// Returns empty string on success, error description on failure.
98-
std::string validate_device_placement(
99-
const DevicePlacement & dp,
100-
int device_count);
101-
10294
} // namespace dflash::common
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
#include "placement_config.h"
2+
3+
#include <cmath>
4+
#include <set>
5+
6+
namespace dflash::common {
7+
8+
std::string validate_device_placement(
9+
const DevicePlacement & dp,
10+
int device_count)
11+
{
12+
const bool validate_device_count = device_count >= 0;
13+
if (validate_device_count && device_count == 0) {
14+
return "no GPU devices available";
15+
}
16+
17+
if (dp.gpu < 0 ||
18+
(validate_device_count && dp.gpu >= device_count)) {
19+
return "primary gpu " + std::to_string(dp.gpu) + " out of range" +
20+
(validate_device_count
21+
? " [0, " + std::to_string(device_count) + ")"
22+
: "");
23+
}
24+
25+
if (!dp.layer_split_gpus.empty()) {
26+
if (dp.layer_split_gpus.size() < 2) {
27+
return "layer_split_gpus must have at least 2 entries";
28+
}
29+
30+
std::set<int> seen;
31+
for (int g : dp.layer_split_gpus) {
32+
if (g < 0 ||
33+
(validate_device_count && g >= device_count)) {
34+
return "layer_split gpu " + std::to_string(g) +
35+
" out of range" +
36+
(validate_device_count
37+
? " [0, " + std::to_string(device_count) + ")"
38+
: "");
39+
}
40+
if (!seen.insert(g).second) {
41+
return "duplicate gpu " + std::to_string(g) + " in layer_split_gpus";
42+
}
43+
}
44+
45+
if (!dp.layer_split_weights.empty() &&
46+
dp.layer_split_weights.size() != dp.layer_split_gpus.size()) {
47+
return "layer_split_weights size (" +
48+
std::to_string(dp.layer_split_weights.size()) +
49+
") != gpu count (" +
50+
std::to_string(dp.layer_split_gpus.size()) + ")";
51+
}
52+
53+
for (double w : dp.layer_split_weights) {
54+
if (w <= 0.0 || !std::isfinite(w)) {
55+
return "layer_split_weights must be positive finite values";
56+
}
57+
}
58+
}
59+
60+
if (dp.max_ctx <= 0) return "max_ctx must be positive";
61+
62+
return {};
63+
}
64+
65+
} // namespace dflash::common

dflash/src/placement/placement_config.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,4 +102,12 @@ inline bool parse_placement_device_list(const std::string & value,
102102
return true;
103103
}
104104

105+
// Validate a DevicePlacement against system constraints.
106+
// If device_count is negative, only validates structural constraints that do
107+
// not require querying the runtime-visible GPU count.
108+
// Returns empty string on success, error description on failure.
109+
std::string validate_device_placement(
110+
const DevicePlacement & dp,
111+
int device_count);
112+
105113
} // namespace dflash::common

0 commit comments

Comments
 (0)