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
40e53d65
"vscode:/vscode.git/clone" did not exist on "b4fc4d0b8d247f013e53c04aede0cc45000f13a3"
Unverified
Commit
40e53d65
authored
Jun 13, 2024
by
Liangsheng Yin
Committed by
GitHub
Jun 13, 2024
Browse files
Add disk cache for loading ShareGPT dataset. (#542)
parent
fb9296f0
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
55 additions
and
35 deletions
+55
-35
benchmark/latency_throughput/bench_throughput.py
benchmark/latency_throughput/bench_throughput.py
+55
-35
No files found.
benchmark/latency_throughput/bench_throughput.py
View file @
40e53d65
...
@@ -19,6 +19,7 @@ On the client side, run:
...
@@ -19,6 +19,7 @@ On the client side, run:
import
argparse
import
argparse
import
asyncio
import
asyncio
import
json
import
json
import
os
import
random
import
random
import
time
import
time
from
typing
import
AsyncGenerator
,
List
,
Tuple
from
typing
import
AsyncGenerator
,
List
,
Tuple
...
@@ -37,8 +38,9 @@ def sample_requests(
...
@@ -37,8 +38,9 @@ def sample_requests(
num_requests
:
int
,
num_requests
:
int
,
tokenizer
:
AutoTokenizer
,
tokenizer
:
AutoTokenizer
,
)
->
List
[
Tuple
[
str
,
int
,
int
]]:
)
->
List
[
Tuple
[
str
,
int
,
int
]]:
# Load the dataset.
with
open
(
dataset_path
)
as
f
:
def
load_dataset
():
with
open
(
dataset_path
,
encoding
=
"utf-8"
)
as
f
:
dataset
=
json
.
load
(
f
)
dataset
=
json
.
load
(
f
)
# Filter out the conversations with less than 2 turns.
# Filter out the conversations with less than 2 turns.
dataset
=
[
data
for
data
in
dataset
if
len
(
data
[
"conversations"
])
>=
2
]
dataset
=
[
data
for
data
in
dataset
if
len
(
data
[
"conversations"
])
>=
2
]
...
@@ -72,8 +74,26 @@ def sample_requests(
...
@@ -72,8 +74,26 @@ def sample_requests(
continue
continue
filtered_dataset
.
append
((
prompt
,
prompt_len
,
output_len
))
filtered_dataset
.
append
((
prompt
,
prompt_len
,
output_len
))
return
filtered_dataset
try
:
from
diskcache
import
Cache
home_dir
=
os
.
path
.
expanduser
(
"~"
)
cache
=
Cache
(
f
"
{
home_dir
}
/.cache/sglang"
)
with
Cache
(
cache
.
directory
)
as
reference
:
reference_key
=
f
"
{
dataset_path
}
_
{
tokenizer
.
name_or_path
}
"
if
reference_key
in
reference
:
print
(
"Reading dataset from cache..."
)
dataset
=
reference
[
reference_key
]
else
:
dataset
=
load_dataset
()
reference
[
reference_key
]
=
dataset
except
ImportError
:
dataset
=
load_dataset
()
# Sample the requests.
# Sample the requests.
sampled_requests
=
random
.
sample
(
filtered_
dataset
,
num_requests
)
sampled_requests
=
random
.
sample
(
dataset
,
num_requests
)
return
sampled_requests
return
sampled_requests
...
...
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