Skip to content

Commit e9e40ce

Browse files
committed
fix lmdeploy bug
1 parent 66c300f commit e9e40ce

File tree

3 files changed

+14
-16
lines changed

3 files changed

+14
-16
lines changed

docker-compose.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ services:
2525
count: all
2626
# count: 2 # 两种方式
2727
capabilities: [ gpu ]
28-
command: uv run gpt_server/serving/main.py
28+
command: python gpt_server/serving/main.py

gpt_server/model_backend/lmdeploy_backend.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
)
88
from typing import Any, Dict, AsyncGenerator
99
from lmdeploy.archs import get_task
10+
from lmdeploy.serve.async_engine import get_names_from_model
1011
from loguru import logger
1112
from gpt_server.model_backend.base import ModelBackend
1213

@@ -73,6 +74,10 @@ def __init__(self, model_path) -> None:
7374
backend=backend,
7475
backend_config=backend_config,
7576
)
77+
model_type = get_names_from_model(model_path=model_path)[1]
78+
self.messages_type_select = (
79+
model_type[1] == "base"
80+
) # 如果为True 则使用 prompt:str 否则: messages:list
7681

7782
async def stream_chat(self, params: Dict[str, Any]) -> AsyncGenerator:
7883
prompt = params.get("prompt", "")
@@ -112,6 +117,8 @@ async def stream_chat(self, params: Dict[str, Any]) -> AsyncGenerator:
112117
logger.info(f"request_id {int(request_id)}")
113118
if params.get("tools", None):
114119
messages = prompt or messages # 解决lmdeploy 的提示模板不支持 tools
120+
if self.messages_type_select:
121+
messages = prompt or messages
115122
results_generator = self.async_engine.generate(
116123
messages=messages, session_id=int(request_id), gen_config=gen_config
117124
)

gpt_server/utils.py

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -316,19 +316,10 @@ def is_port_in_use(port):
316316
}
317317

318318

319-
def infer_model_type(model_path: str) -> str:
320-
"""自动推测模型类型,未使用此代码"""
321-
from lmdeploy.model import best_match_model
322-
from transformers import AutoConfig
323-
324-
match_model_type = best_match_model(model_path)
325-
model_config = AutoConfig.from_pretrained(model_path, trust_remote_code=True)
326-
config_model_type = model_config.get("model_type", False)
327-
return model_type_mapping[match_model_type]
328-
329-
330319
if __name__ == "__main__":
331-
# ckpt = "deepseek-ai/deepseek-moe-16b-base" # internlm2
332-
# model_type = best_match_model(ckpt)
333-
# print(model_type)
334-
pass
320+
# /home/dev/model/KirillR/QwQ-32B-Preview-AWQ
321+
from lmdeploy.serve.async_engine import get_names_from_model
322+
323+
ckpt = "/home/dev/model/KirillR/QwQ-32B-Preview-AWQ" # internlm2
324+
model_type = get_names_from_model(ckpt)
325+
print(model_type[1] == "base")

0 commit comments

Comments
 (0)