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
e4d68afc
Unverified
Commit
e4d68afc
authored
Sep 09, 2024
by
Lianmin Zheng
Committed by
GitHub
Sep 09, 2024
Browse files
[Minor] Many cleanup (#1357)
parent
c9b75917
Changes
24
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
43 additions
and
45 deletions
+43
-45
python/sglang/test/test_programs.py
python/sglang/test/test_programs.py
+7
-5
python/sglang/utils.py
python/sglang/utils.py
+32
-37
test/srt/test_moe_eval_accuracy_large.py
test/srt/test_moe_eval_accuracy_large.py
+2
-2
test/srt/test_server_args.py
test/srt/test_server_args.py
+2
-1
No files found.
python/sglang/test/test_programs.py
View file @
e4d68afc
...
@@ -7,7 +7,7 @@ import time
...
@@ -7,7 +7,7 @@ import time
import
numpy
as
np
import
numpy
as
np
import
sglang
as
sgl
import
sglang
as
sgl
from
sglang.utils
import
fetch
_and_cache_jsonl
from
sglang.utils
import
download
_and_cache_
file
,
read_
jsonl
def
test_few_shot_qa
():
def
test_few_shot_qa
():
...
@@ -456,10 +456,6 @@ def test_chat_completion_speculative():
...
@@ -456,10 +456,6 @@ def test_chat_completion_speculative():
def
test_hellaswag_select
():
def
test_hellaswag_select
():
"""Benchmark the accuracy of sgl.select on the HellaSwag dataset."""
"""Benchmark the accuracy of sgl.select on the HellaSwag dataset."""
url
=
"https://raw.githubusercontent.com/rowanz/hellaswag/master/data/hellaswag_val.jsonl"
lines
=
fetch_and_cache_jsonl
(
url
)
# Construct prompts
def
get_one_example
(
lines
,
i
,
include_answer
):
def
get_one_example
(
lines
,
i
,
include_answer
):
ret
=
lines
[
i
][
"activity_label"
]
+
": "
+
lines
[
i
][
"ctx"
]
+
" "
ret
=
lines
[
i
][
"activity_label"
]
+
": "
+
lines
[
i
][
"ctx"
]
+
" "
if
include_answer
:
if
include_answer
:
...
@@ -472,6 +468,12 @@ def test_hellaswag_select():
...
@@ -472,6 +468,12 @@ def test_hellaswag_select():
ret
+=
get_one_example
(
lines
,
i
,
True
)
+
"
\n\n
"
ret
+=
get_one_example
(
lines
,
i
,
True
)
+
"
\n\n
"
return
ret
return
ret
# Read data
url
=
"https://raw.githubusercontent.com/rowanz/hellaswag/master/data/hellaswag_val.jsonl"
filename
=
download_and_cache_file
(
url
)
lines
=
list
(
read_jsonl
(
filename
))
# Construct prompts
num_questions
=
200
num_questions
=
200
num_shots
=
20
num_shots
=
20
few_shot_examples
=
get_few_shot_examples
(
lines
,
num_shots
)
few_shot_examples
=
get_few_shot_examples
(
lines
,
num_shots
)
...
...
python/sglang/utils.py
View file @
e4d68afc
...
@@ -12,7 +12,7 @@ import urllib.request
...
@@ -12,7 +12,7 @@ import urllib.request
from
concurrent.futures
import
ThreadPoolExecutor
from
concurrent.futures
import
ThreadPoolExecutor
from
io
import
BytesIO
from
io
import
BytesIO
from
json
import
dumps
from
json
import
dumps
from
typing
import
Union
from
typing
import
Optional
,
Union
import
numpy
as
np
import
numpy
as
np
import
requests
import
requests
...
@@ -38,13 +38,11 @@ def is_same_type(values: list):
...
@@ -38,13 +38,11 @@ def is_same_type(values: list):
def
read_jsonl
(
filename
:
str
):
def
read_jsonl
(
filename
:
str
):
"""Read a JSONL file."""
"""Read a JSONL file."""
rets
=
[]
with
open
(
filename
)
as
fin
:
with
open
(
filename
)
as
fin
:
for
line
in
fin
:
for
line
in
fin
:
if
line
.
startswith
(
"#"
):
if
line
.
startswith
(
"#"
):
continue
continue
rets
.
append
(
json
.
loads
(
line
))
yield
json
.
loads
(
line
)
return
rets
def
dump_state_text
(
filename
:
str
,
states
:
list
,
mode
:
str
=
"w"
):
def
dump_state_text
(
filename
:
str
,
states
:
list
,
mode
:
str
=
"w"
):
...
@@ -264,16 +262,17 @@ class LazyImport:
...
@@ -264,16 +262,17 @@ class LazyImport:
return
module
(
*
args
,
**
kwargs
)
return
module
(
*
args
,
**
kwargs
)
def
fetch_and_cache_jsonl
(
url
,
cache_file
=
"cached_data.jsonl"
):
def
download_and_cache_file
(
url
:
str
,
filename
:
Optional
[
str
]
=
None
):
"""Read and cache a jsonl file from a url."""
"""Read and cache a file from a url."""
if
filename
is
None
:
filename
=
os
.
path
.
join
(
"/tmp"
,
url
.
split
(
"/"
)[
-
1
])
# Check if the cache file already exists
# Check if the cache file already exists
if
os
.
path
.
exists
(
cache_file
):
if
os
.
path
.
exists
(
filename
):
print
(
"Loading data from cache..."
)
return
filename
with
open
(
cache_file
,
"r"
)
as
f
:
data
=
[
json
.
loads
(
line
)
for
line
in
f
]
print
(
f
"Downloading from
{
url
}
to
{
filename
}
"
)
else
:
print
(
"Downloading data from URL..."
)
# Stream the response to show the progress bar
# Stream the response to show the progress bar
response
=
requests
.
get
(
url
,
stream
=
True
)
response
=
requests
.
get
(
url
,
stream
=
True
)
response
.
raise_for_status
()
# Check for request errors
response
.
raise_for_status
()
# Check for request errors
...
@@ -283,8 +282,8 @@ def fetch_and_cache_jsonl(url, cache_file="cached_data.jsonl"):
...
@@ -283,8 +282,8 @@ def fetch_and_cache_jsonl(url, cache_file="cached_data.jsonl"):
chunk_size
=
1024
# Download in chunks of 1KB
chunk_size
=
1024
# Download in chunks of 1KB
# Use tqdm to display the progress bar
# Use tqdm to display the progress bar
with
open
(
cache_fil
e
,
"wb"
)
as
f
,
tqdm
(
with
open
(
filenam
e
,
"wb"
)
as
f
,
tqdm
(
desc
=
cache_fil
e
,
desc
=
filenam
e
,
total
=
total_size
,
total
=
total_size
,
unit
=
"B"
,
unit
=
"B"
,
unit_scale
=
True
,
unit_scale
=
True
,
...
@@ -294,8 +293,4 @@ def fetch_and_cache_jsonl(url, cache_file="cached_data.jsonl"):
...
@@ -294,8 +293,4 @@ def fetch_and_cache_jsonl(url, cache_file="cached_data.jsonl"):
f
.
write
(
chunk
)
f
.
write
(
chunk
)
bar
.
update
(
len
(
chunk
))
bar
.
update
(
len
(
chunk
))
# Convert the data to a list of dictionaries
return
filename
with
open
(
cache_file
,
"r"
)
as
f
:
data
=
[
json
.
loads
(
line
)
for
line
in
f
]
return
data
test/srt/test_moe_eval_accuracy_large.py
View file @
e4d68afc
...
@@ -42,7 +42,7 @@ class TestEvalAccuracyLarge(unittest.TestCase):
...
@@ -42,7 +42,7 @@ class TestEvalAccuracyLarge(unittest.TestCase):
)
)
metrics
=
run_eval
(
args
)
metrics
=
run_eval
(
args
)
assert
metrics
[
"score"
]
>=
0.6
3
,
f
"
{
metrics
}
"
assert
metrics
[
"score"
]
>=
0.6
2
,
f
"
{
metrics
}
"
def
test_human_eval
(
self
):
def
test_human_eval
(
self
):
args
=
SimpleNamespace
(
args
=
SimpleNamespace
(
...
@@ -66,7 +66,7 @@ class TestEvalAccuracyLarge(unittest.TestCase):
...
@@ -66,7 +66,7 @@ class TestEvalAccuracyLarge(unittest.TestCase):
)
)
metrics
=
run_eval
(
args
)
metrics
=
run_eval
(
args
)
assert
metrics
[
"score"
]
>=
0.6
3
,
f
"
{
metrics
}
"
assert
metrics
[
"score"
]
>=
0.6
2
,
f
"
{
metrics
}
"
if
__name__
==
"__main__"
:
if
__name__
==
"__main__"
:
...
...
test/srt/test_server_args.py
View file @
e4d68afc
import
json
import
unittest
import
unittest
from
sglang.srt.server_args
import
prepare_server_args
from
sglang.srt.server_args
import
prepare_server_args
...
@@ -15,7 +16,7 @@ class TestPrepareServerArgs(unittest.TestCase):
...
@@ -15,7 +16,7 @@ class TestPrepareServerArgs(unittest.TestCase):
)
)
self
.
assertEqual
(
server_args
.
model_path
,
"model_path"
)
self
.
assertEqual
(
server_args
.
model_path
,
"model_path"
)
self
.
assertEqual
(
self
.
assertEqual
(
server_args
.
json_model_override_args
,
json
.
loads
(
server_args
.
json_model_override_args
)
,
{
"rope_scaling"
:
{
"factor"
:
2.0
,
"type"
:
"linear"
}},
{
"rope_scaling"
:
{
"factor"
:
2.0
,
"type"
:
"linear"
}},
)
)
...
...
Prev
1
2
Next
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