Skip to content

Commit a377f0b

Browse files
FuncSherlxuhao
andauthored
[Misc]: optimize eager mode host time (#4196)
Co-authored-by: xuhao <[email protected]>
1 parent e9d3aa0 commit a377f0b

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

vllm/utils.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
Hashable, List, Optional, OrderedDict, Tuple, TypeVar,
1818
Union)
1919

20+
import numpy as np
2021
import psutil
2122
import torch
2223

@@ -501,11 +502,6 @@ def str_to_int_tuple(s: str) -> Tuple[int, ...]:
501502
f"(e.g., 1, 2, 3). Given input: {s}") from e
502503

503504

504-
def pad_to_max_length(x: List[int], max_len: int, pad: int) -> List[int]:
505-
assert len(x) <= max_len
506-
return x + [pad] * (max_len - len(x))
507-
508-
509505
def make_tensor_with_pad(
510506
x: List[List[int]],
511507
max_len: int,
@@ -518,7 +514,10 @@ def make_tensor_with_pad(
518514
The padding is applied to the end of each inner list until it reaches
519515
`max_len`.
520516
"""
521-
padded_x = [pad_to_max_length(x_i, max_len, pad) for x_i in x]
517+
padded_x = np.zeros([len(x), max_len], dtype=np.int32) + pad
518+
for ind, blocktb in enumerate(x):
519+
assert len(blocktb) <= max_len
520+
padded_x[ind, :len(blocktb)] = blocktb
522521
return torch.tensor(padded_x, dtype=dtype, device=device)
523522

524523

0 commit comments

Comments
 (0)