-
Notifications
You must be signed in to change notification settings - Fork 596
add custom chat template #3251
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add custom chat template #3251
Conversation
Thanks for your contribution! |
@@ -161,6 +161,9 @@ The following extra parameters are supported: | |||
chat_template_kwargs: Optional[dict] = None | |||
# Additional parameters passed to the chat template, used for customizing dialogue formats (default None). | |||
|
|||
chat_template: Optional[str] = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docs/zh/parameters.md 和 docs/parameters.md 中补充启动参数说明。 中补充启动参数说明。
fastdeploy/entrypoints/llm.py
Outdated
|
||
messages_len = len(messages) | ||
for i in range(messages_len): | ||
messages[i] = {"messages": messages[i]} | ||
messages[i] = {"messages": messages[i], "chat_template": chat_template} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个参数,不建议放在 messages 中, 放在 chat_template_kwargs 中吧? 后面的透传行为可以继续传下去。
@@ -104,6 +105,7 @@ async def lifespan(app: FastAPI): | |||
pid = os.getppid() | |||
else: | |||
pid = os.getpid() | |||
chat_template = load_chat_template(args.chat_template) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这个适合放在外面进行 load, 这里面会启动多进程。
@@ -84,6 +85,8 @@ async def create_chat_completion(self, request: ChatCompletionRequest): | |||
api_server_logger.info(f"create chat completion request: {request_id}") | |||
|
|||
try: | |||
if request.chat_template is None: | |||
request.chat_template = self.chat_template |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
要放在 to_dict_for_infer 之后, 因为chat_template 不是 openai 标准参数, 不能直接放在 request 传递。
@@ -0,0 +1,22 @@ | |||
import os |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
单测除了验证模板打开, 还需要验证请求时增加 自定义模板。
增加自定义chat template
1.启动服务时通过--chat-template参数可以指定加载的chat-template,会覆盖模型原有的模板
2.请求时通过chat_template参数可以传递chat-template模板,传递的模板会覆盖模型原有的模板,以及启动服务时通过--chat-template指定的模板