Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
OpenDAS
ktransformers
Commits
67042d11
Unverified
Commit
67042d11
authored
Apr 23, 2025
by
Atream
Committed by
GitHub
Apr 23, 2025
Browse files
Merge pull request #1193 from kvcache-ai/fix-chat-template-encoding
fix chat template encoding
parents
449a83df
46493789
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
2 additions
and
14 deletions
+2
-14
ktransformers/server/backend/interfaces/balance_serve.py
ktransformers/server/backend/interfaces/balance_serve.py
+2
-14
No files found.
ktransformers/server/backend/interfaces/balance_serve.py
View file @
67042d11
...
@@ -387,23 +387,11 @@ class BalanceServeInterface(BackendInterfaceBase):
...
@@ -387,23 +387,11 @@ class BalanceServeInterface(BackendInterfaceBase):
return
input_ids
return
input_ids
def
format_and_tokenize_input_ids
(
self
,
thread_id
:
ObjectID
,
messages
:
List
):
def
format_and_tokenize_input_ids
(
self
,
thread_id
:
ObjectID
,
messages
:
List
):
for
m
in
messages
:
input_str
:
str
=
self
.
tokenizer
.
apply_chat_template
(
messages
,
tokenize
=
False
,
add_generation_prompt
=
True
)
if
m
[
"role"
]
==
"system"
:
logger
.
warning
(
f
'change
{
m
[
"role"
]
}
to user'
)
m
[
"role"
]
=
"user"
new_messages
=
[
messages
[
0
]]
for
m
in
messages
[
1
:]:
if
m
[
"role"
]
==
"user"
and
new_messages
[
-
1
][
"role"
]
==
"user"
:
logger
.
warning
(
"merge two adjacent user messages"
)
new_messages
[
-
1
][
"content"
]
+=
'
\n
'
+
m
[
"content"
]
else
:
new_messages
.
append
(
m
)
input_str
:
str
=
self
.
tokenizer
.
apply_chat_template
(
new_messages
,
tokenize
=
False
,
add_generation_prompt
=
True
)
# drop <think> token in chat template
# drop <think> token in chat template
if
input_str
.
endswith
(
'<think>
\n
'
):
if
input_str
.
endswith
(
'<think>
\n
'
):
input_str
=
input_str
[:
-
len
(
'<think>
\n
'
)]
input_str
=
input_str
[:
-
len
(
'<think>
\n
'
)]
input_ids
=
self
.
tokenizer
.
encode
(
input_str
,
return_tensors
=
"pt"
).
to
(
self
.
args
.
device
)
input_ids
=
self
.
tokenizer
.
encode
(
input_str
,
return_tensors
=
"pt"
,
add_special_tokens
=
False
).
to
(
self
.
args
.
device
)
logger
.
debug
(
f
"get input ids of shape
{
input_ids
.
shape
}
"
)
logger
.
debug
(
f
"get input ids of shape
{
input_ids
.
shape
}
"
)
return
input_ids
return
input_ids
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment