File tree Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Expand file tree Collapse file tree 2 files changed +37
-0
lines changed Original file line number Diff line number Diff line change @@ -64,3 +64,33 @@ cmake --build build -j --target llama-server && ./tools/server/tests/tests.sh
64
64
```
65
65
66
66
To see all available arguments, please refer to [ pytest documentation] ( https://docs.pytest.org/en/stable/how-to/usage.html )
67
+
68
+ ### Debugging external llama-server
69
+ It can sometimes be useful to run the server in a debugger when invesigating test
70
+ failures. To do this, the environment variable ` DEBUG_EXTERNAL=1 ` can be set
71
+ which will cause the test to skip starting a llama-server itself. Instead, the
72
+ server can be started in a debugger.
73
+
74
+ Example using ` gdb ` :
75
+ ``` console
76
+ $ gdb --args ../../../build/bin/llama-server \
77
+ --host 127.0.0.1 --port 8080 \
78
+ --temp 0.8 --seed 42 \
79
+ --hf-repo ggml-org/models --hf-file tinyllamas/stories260K.gguf \
80
+ --batch-size 32 --no-slots --alias tinyllama-2 --ctx-size 512 \
81
+ --parallel 2 --n-predict 64
82
+ ```
83
+ And a break point can be set in before running:
84
+ ``` console
85
+ (gdb) br server.cpp:4604
86
+ (gdb) r
87
+ main: server is listening on http://127.0.0.1:8080 - starting the main loop
88
+ srv update_slots: all slots are idle
89
+ ```
90
+
91
+ And then the test in question can be run in another terminal:
92
+ ``` console
93
+ (venv) $ env DEBUG_EXTERNAL=1 ./tests.sh unit/test_chat_completion.py -v -x
94
+ ```
95
+ And this should trigger the breakpoint and allow inspection of the server state
96
+ in the debugger terminal.
Original file line number Diff line number Diff line change @@ -99,8 +99,12 @@ def __init__(self):
99
99
self .debug = True
100
100
if "PORT" in os .environ :
101
101
self .server_port = int (os .environ ["PORT" ])
102
+ self .external_server = "DEBUG_EXTERNAL" in os .environ
102
103
103
104
def start (self , timeout_seconds : int | None = DEFAULT_HTTP_TIMEOUT ) -> None :
105
+ if self .external_server :
106
+ print (f"[external_server]: Assuming external server running on { self .server_host } :{ self .server_port } " )
107
+ return
104
108
if self .server_path is not None :
105
109
server_path = self .server_path
106
110
elif "LLAMA_SERVER_BIN_PATH" in os .environ :
@@ -244,6 +248,9 @@ def start(self, timeout_seconds: int | None = DEFAULT_HTTP_TIMEOUT) -> None:
244
248
raise TimeoutError (f"Server did not start within { timeout_seconds } seconds" )
245
249
246
250
def stop (self ) -> None :
251
+ if self .external_server :
252
+ print ("[external_server]: Not stopping external server" )
253
+ return
247
254
if self in server_instances :
248
255
server_instances .remove (self )
249
256
if self .process :
You can’t perform that action at this time.
0 commit comments