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
change
sglang
Commits
007eeb4e
"...python/git@developer.sourcefind.cn:change/sglang.git" did not exist on "62d065ca4ab15eba9b5237258145ffb2d9b2ca49"
Unverified
Commit
007eeb4e
authored
Jan 21, 2024
by
Lianmin Zheng
Committed by
GitHub
Jan 21, 2024
Browse files
Fix the error message and dependency of openai backend (#71)
parent
e8f2b155
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
26 additions
and
16 deletions
+26
-16
README.md
README.md
+2
-1
python/pyproject.toml
python/pyproject.toml
+5
-4
python/sglang/backend/openai.py
python/sglang/backend/openai.py
+9
-1
python/sglang/lang/interpreter.py
python/sglang/lang/interpreter.py
+10
-10
No files found.
README.md
View file @
007eeb4e
...
@@ -164,7 +164,8 @@ def image_qa(s, image_file, question):
...
@@ -164,7 +164,8 @@ def image_qa(s, image_file, question):
```
```
### Constrained Decoding
### Constrained Decoding
Use
`regex=`
to specify a regular expression as a decoding constraint.
Use
`regex`
to specify a regular expression as a decoding constraint.
This is only supported for local models.
```
python
```
python
@
sgl
.
function
@
sgl
.
function
...
...
python/pyproject.toml
View file @
007eeb4e
...
@@ -18,10 +18,11 @@ dependencies = [
...
@@ -18,10 +18,11 @@ dependencies = [
]
]
[project.optional-dependencies]
[project.optional-dependencies]
srt
=
[
"fastapi"
,
"psutil"
,
"rpyc"
,
"torch"
,
"uvloop"
,
"uvicorn"
,
"zmq"
,
"vllm>=0.2.5"
,
srt
=
[
"fastapi"
,
"psutil"
,
"rpyc"
,
"torch"
,
"uvloop"
,
"uvicorn"
,
"interegular"
,
"lark"
,
"numba"
,
"pydantic"
,
"diskcache"
,
"cloudpickle"
]
"zmq"
,
"vllm>=0.2.5"
,
"interegular"
,
"lark"
,
"numba"
,
openai
=
["openai>=1.0"]
"pydantic"
,
"diskcache"
,
"cloudpickle"
]
anthropic
=
["anthropic"]
openai
=
[
"openai>=1.0"
,
"numpy"
]
anthropic
=
[
"anthropic"
,
"numpy"
]
all
=
["sglang[srt]
", "
sglang
[openai]
", "
sglang
[anthropic]"]
all
=
["sglang[srt]
", "
sglang
[openai]
", "
sglang
[anthropic]"]
[project.urls]
[project.urls]
...
...
python/sglang/backend/openai.py
View file @
007eeb4e
...
@@ -77,7 +77,9 @@ class OpenAI(BaseBackend):
...
@@ -77,7 +77,9 @@ class OpenAI(BaseBackend):
):
):
if
sampling_params
.
dtype
is
None
:
if
sampling_params
.
dtype
is
None
:
if
self
.
is_chat_model
:
if
self
.
is_chat_model
:
assert
s
.
text_
.
endswith
(
"ASSISTANT:"
)
if
not
s
.
text_
.
endswith
(
"ASSISTANT:"
):
raise
RuntimeError
(
"This use case is not supported. "
"For OpenAI chat models, sgl.gen must be right after sgl.assistant"
)
prompt
=
s
.
messages_
prompt
=
s
.
messages_
else
:
else
:
prompt
=
s
.
text_
prompt
=
s
.
text_
...
@@ -149,6 +151,12 @@ class OpenAI(BaseBackend):
...
@@ -149,6 +151,12 @@ class OpenAI(BaseBackend):
choices
:
List
[
str
],
choices
:
List
[
str
],
temperature
:
float
,
temperature
:
float
,
):
):
if
self
.
is_chat_model
:
raise
NotImplementedError
(
"select/choices is not supported for chat models. "
"Please try to use a non-chat model such as gpt-3.5-turbo-instruct"
)
n_choices
=
len
(
choices
)
n_choices
=
len
(
choices
)
token_ids
=
[
self
.
tokenizer
.
encode
(
x
)
for
x
in
choices
]
token_ids
=
[
self
.
tokenizer
.
encode
(
x
)
for
x
in
choices
]
scores
=
[
0
]
*
n_choices
scores
=
[
0
]
*
n_choices
...
...
python/sglang/lang/interpreter.py
View file @
007eeb4e
...
@@ -197,16 +197,7 @@ class StreamExecutor:
...
@@ -197,16 +197,7 @@ class StreamExecutor:
self
.
stream_var_event
=
None
self
.
stream_var_event
=
None
def
submit
(
self
,
expr
:
SglExpr
):
def
submit
(
self
,
expr
:
SglExpr
):
if
isinstance
(
expr
,
(
SglGen
,
SglSelect
,
SglVarScopeBegin
)):
self
.
_init_var_event
(
expr
)
self
.
variable_event
[
expr
.
name
]
=
threading
.
Event
()
if
self
.
stream
:
self
.
stream_var_event
[
expr
.
name
]
=
threading
.
Event
()
elif
isinstance
(
expr
,
SglExprList
):
for
e
in
expr
.
expr_list
:
if
isinstance
(
e
,
(
SglGen
,
SglSelect
,
SglVarScopeBegin
)):
self
.
variable_event
[
e
.
name
]
=
threading
.
Event
()
if
self
.
stream
:
self
.
stream_var_event
[
e
.
name
]
=
threading
.
Event
()
if
self
.
use_thread
:
if
self
.
use_thread
:
self
.
queue
.
put
(
expr
)
self
.
queue
.
put
(
expr
)
...
@@ -467,6 +458,15 @@ class StreamExecutor:
...
@@ -467,6 +458,15 @@ class StreamExecutor:
src_rids
=
[
state
.
stream_executor
.
sid
for
state
in
expr
.
states
]
src_rids
=
[
state
.
stream_executor
.
sid
for
state
in
expr
.
states
]
self
.
backend
.
concatenate_and_append
(
src_rids
,
self
.
sid
)
self
.
backend
.
concatenate_and_append
(
src_rids
,
self
.
sid
)
def
_init_var_event
(
self
,
expr
):
if
isinstance
(
expr
,
(
SglGen
,
SglSelect
,
SglVarScopeBegin
)):
self
.
variable_event
[
expr
.
name
]
=
threading
.
Event
()
if
self
.
stream
:
self
.
stream_var_event
[
expr
.
name
]
=
threading
.
Event
()
elif
isinstance
(
expr
,
SglExprList
):
for
e
in
expr
.
expr_list
:
self
.
_init_var_event
(
e
)
def
_resolve_sampling_params
(
self
,
sampling_params
):
def
_resolve_sampling_params
(
self
,
sampling_params
):
clone
=
None
clone
=
None
for
item
in
[
for
item
in
[
...
...
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