Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
OpenDAS
vllm_cscc
Commits
a377f0bd
Unverified
Commit
a377f0bd
authored
May 31, 2024
by
functionxu123
Committed by
GitHub
May 31, 2024
Browse files
[Misc]: optimize eager mode host time (#4196)
Co-authored-by:
xuhao
<
xuhao@cambricon.com
>
parent
e9d3aa04
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
6 deletions
+5
-6
vllm/utils.py
vllm/utils.py
+5
-6
No files found.
vllm/utils.py
View file @
a377f0bd
...
...
@@ -17,6 +17,7 @@ from typing import (Any, AsyncIterator, Awaitable, Callable, Dict, Generic,
Hashable
,
List
,
Optional
,
OrderedDict
,
Tuple
,
TypeVar
,
Union
)
import
numpy
as
np
import
psutil
import
torch
...
...
@@ -501,11 +502,6 @@ def str_to_int_tuple(s: str) -> Tuple[int, ...]:
f
"(e.g., 1, 2, 3). Given input:
{
s
}
"
)
from
e
def
pad_to_max_length
(
x
:
List
[
int
],
max_len
:
int
,
pad
:
int
)
->
List
[
int
]:
assert
len
(
x
)
<=
max_len
return
x
+
[
pad
]
*
(
max_len
-
len
(
x
))
def
make_tensor_with_pad
(
x
:
List
[
List
[
int
]],
max_len
:
int
,
...
...
@@ -518,7 +514,10 @@ def make_tensor_with_pad(
The padding is applied to the end of each inner list until it reaches
`max_len`.
"""
padded_x
=
[
pad_to_max_length
(
x_i
,
max_len
,
pad
)
for
x_i
in
x
]
padded_x
=
np
.
zeros
([
len
(
x
),
max_len
],
dtype
=
np
.
int32
)
+
pad
for
ind
,
blocktb
in
enumerate
(
x
):
assert
len
(
blocktb
)
<=
max_len
padded_x
[
ind
,
:
len
(
blocktb
)]
=
blocktb
return
torch
.
tensor
(
padded_x
,
dtype
=
dtype
,
device
=
device
)
...
...
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