Skip to content

Commit 8415f1e

Browse files
committed
test(server): keep server unit tests CPU-only
1 parent 599217d commit 8415f1e

5 files changed

Lines changed: 82 additions & 73 deletions

File tree

server/CMakeLists.txt

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@ add_library(dflash_common STATIC
266266
src/common/daemon_loop.cpp
267267
src/common/gguf_inspect.cpp
268268
src/common/backend_factory.cpp
269+
src/placement/placement_config.cpp
269270
src/common/layer_split_utils.cpp
270271
src/common/ddtree.cpp
271272
src/common/peer_access.cpp
@@ -772,20 +773,21 @@ if(DFLASH27B_TESTS)
772773
src/server/http_server.cpp
773774
src/server/model_card.cpp)
774775
target_include_directories(test_server_unit PRIVATE ${DFLASH27B_SRC_INCLUDE_DIRS})
776+
target_include_directories(test_server_unit PRIVATE
777+
${CMAKE_CURRENT_SOURCE_DIR}/deps/llama.cpp/ggml/src
778+
${CMAKE_CURRENT_SOURCE_DIR}/deps/llama.cpp/common)
775779
if(DFLASH27B_GPU_BACKEND STREQUAL "hip")
776780
target_compile_definitions(test_server_unit PRIVATE DFLASH27B_BACKEND_HIP=1 GGML_USE_HIP)
777781
else()
778782
target_compile_definitions(test_server_unit PRIVATE
779783
DFLASH27B_BACKEND_CUDA=1
780784
DFLASH27B_CUDA_MIN_SM=${_dflash_cuda_min_sm})
781785
endif()
782-
target_link_libraries(test_server_unit PRIVATE dflash_common ggml ${DFLASH27B_GGML_BACKEND_TARGET})
783-
if(DFLASH27B_GPU_BACKEND STREQUAL "cuda")
784-
find_package(CUDAToolkit REQUIRED)
785-
target_link_libraries(test_server_unit PRIVATE CUDA::cudart)
786-
else()
787-
target_link_libraries(test_server_unit PRIVATE hip::host)
788-
endif()
786+
target_link_libraries(test_server_unit PRIVATE
787+
ggml-base
788+
ggml-cpu
789+
nlohmann_json::nlohmann_json
790+
pthread)
789791
add_test(NAME server_unit COMMAND test_server_unit)
790792
endif()
791793

server/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

server/src/common/layer_split_utils.h

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

88-
// Validate a DevicePlacement against system constraints.
89-
// If device_count is negative, only validates structural constraints that do
90-
// not require querying the runtime-visible GPU count.
91-
// Returns empty string on success, error description on failure.
92-
std::string validate_device_placement(
93-
const DevicePlacement & dp,
94-
int device_count);
95-
9688
} // 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

server/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)