Skip to content

Commit 9ce1829

Browse files
committed
fix web_ui infer error (#5106)
1 parent 106def4 commit 9ce1829

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

examples/deploy/server/sglang.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
CUDA_VISIBLE_DEVICES=0,1 \
2+
swift deploy \
3+
--model Qwen/Qwen3-8B \
4+
--infer_backend sglang \
5+
--max_new_tokens 2048 \
6+
--sglang_context_length 8192 \
7+
--sglang_tp_size 2 \
8+
--served_model_name Qwen3-8B
9+
10+
# After the server-side deployment above is successful, use the command below to perform a client call test.
11+
12+
# curl http://localhost:8000/v1/chat/completions \
13+
# -H "Content-Type: application/json" \
14+
# -d '{
15+
# "model": "Qwen3-8B",
16+
# "messages": [{"role": "user", "content": "What is your name?"}],
17+
# "temperature": 0
18+
# }'
File renamed without changes.

swift/llm/infer/infer_engine/infer_engine.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def _run_async_iter():
7272
else:
7373
queue.put(None)
7474

75-
loop = asyncio.get_event_loop()
75+
loop = asyncio.new_event_loop()
7676
thread = Thread(target=lambda: loop.run_until_complete(_run_async_iter()))
7777
thread.start()
7878
pre_output = None
@@ -81,6 +81,7 @@ async def _run_async_iter():
8181
if output is None or isinstance(output, Exception):
8282
prog_bar.update()
8383
self._update_metrics(pre_output, metrics)
84+
loop.close()
8485
return
8586
pre_output = output
8687
yield output
@@ -255,10 +256,13 @@ def func(target, queue, args, kwargs):
255256

256257
@staticmethod
257258
def safe_asyncio_run(coro):
258-
loop = asyncio.get_event_loop()
259+
loop = asyncio.new_event_loop()
259260

260261
def asyncio_run(core):
261-
return loop.run_until_complete(core)
262+
try:
263+
return loop.run_until_complete(core)
264+
finally:
265+
loop.close()
262266

263267
return InferEngine.thread_run(asyncio_run, args=(coro, ))
264268

0 commit comments

Comments
 (0)