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
ox696c
ktransformers
Commits
4385e850
Commit
4385e850
authored
Feb 12, 2025
by
liam
Browse files
⚡
support force thinking
parent
6f3a39be
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
7 additions
and
5 deletions
+7
-5
ktransformers/local_chat.py
ktransformers/local_chat.py
+1
-1
ktransformers/server/args.py
ktransformers/server/args.py
+1
-0
ktransformers/server/backend/interfaces/transformers.py
ktransformers/server/backend/interfaces/transformers.py
+5
-4
No files found.
ktransformers/local_chat.py
View file @
4385e850
...
...
@@ -160,7 +160,7 @@ def local_chat(
messages
,
add_generation_prompt
=
True
,
return_tensors
=
"pt"
)
if
force_think
:
token_thinks
=
torch
.
tensor
([
tokenizer
.
encode
(
"<think>
\\
n"
,
add_special_tokens
=
False
)])
token_thinks
=
torch
.
tensor
([
tokenizer
.
encode
(
"<think>
\\
n"
,
add_special_tokens
=
False
)]
,
device
=
input_tensor
.
device
)
input_tensor
=
torch
.
cat
(
[
input_tensor
,
token_thinks
],
dim
=
1
)
...
...
ktransformers/server/args.py
View file @
4385e850
...
...
@@ -122,4 +122,5 @@ class ArgumentParser:
self
.
cfg
.
server_ip
=
args
.
host
self
.
cfg
.
server_port
=
args
.
port
self
.
cfg
.
backend_type
=
args
.
type
self
.
cfg
.
user_force_think
=
args
.
force_think
return
args
ktransformers/server/backend/interfaces/transformers.py
View file @
4385e850
...
...
@@ -325,7 +325,7 @@ class TransformersInterface(BackendInterfaceBase):
else
:
raise
ValueError
(
"local_messages should be List or str"
)
if
Config
().
user_force_think
:
token_thinks
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
"<think>
\\
n"
,
add_special_tokens
=
False
)])
token_thinks
=
torch
.
tensor
([
self
.
tokenizer
.
encode
(
"<think>
\\
n"
,
add_special_tokens
=
False
)]
,
device
=
input_ids
.
device
)
input_ids
=
torch
.
cat
(
[
input_ids
,
token_thinks
],
dim
=
1
)
...
...
@@ -334,8 +334,9 @@ class TransformersInterface(BackendInterfaceBase):
self
.
profiler
.
create_and_start_timer
(
"prefill"
)
if
Config
().
user_force_think
:
print
(
"<think>
\n
"
)
yield
"<think>
\n
"
t
=
"<think>
\n
"
print
(
t
,
end
=
""
,
flush
=
True
)
yield
t
for
t
in
self
.
prefill
(
input_ids
,
self
.
check_is_new
(
thread_id
)):
if
t
is
not
None
:
print
(
t
,
end
=
""
,
flush
=
True
)
...
...
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