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
gaoqiong
lm-evaluation-harness
Commits
0e4f5361
Commit
0e4f5361
authored
Jun 20, 2023
by
haileyschoelkopf
Committed by
lintangsutawika
Jun 22, 2023
Browse files
init tensors on-device where possible
parent
bc7f52e6
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
6 deletions
+12
-6
lm_eval/models/hf_merged.py
lm_eval/models/hf_merged.py
+4
-2
lm_eval/utils.py
lm_eval/utils.py
+8
-4
No files found.
lm_eval/models/hf_merged.py
View file @
0e4f5361
...
@@ -379,14 +379,16 @@ class HFLM(LM):
...
@@ -379,14 +379,16 @@ class HFLM(LM):
inp
=
torch
.
tensor
(
inp
=
torch
.
tensor
(
(
context_enc
)[
-
self
.
max_length
:],
(
context_enc
)[
-
self
.
max_length
:],
dtype
=
torch
.
long
,
dtype
=
torch
.
long
,
).
to
(
self
.
device
)
device
=
self
.
device
)
(
inplen
,)
=
inp
.
shape
(
inplen
,)
=
inp
.
shape
cont
=
torch
.
tensor
(
cont
=
torch
.
tensor
(
(
continuation_enc
)[
-
self
.
max_length
:],
(
continuation_enc
)[
-
self
.
max_length
:],
# TODO: left-shift these?
# TODO: left-shift these?
# TODO: our code assumes we never end up truncating conts for either model type
# TODO: our code assumes we never end up truncating conts for either model type
dtype
=
torch
.
long
,
dtype
=
torch
.
long
,
).
to
(
self
.
device
)
device
=
self
.
device
,
)
(
contlen
,)
=
cont
.
shape
(
contlen
,)
=
cont
.
shape
conts
.
append
(
cont
)
conts
.
append
(
cont
)
...
...
lm_eval/utils.py
View file @
0e4f5361
...
@@ -448,8 +448,10 @@ def pad_and_concat(max_length:int, tensors: List[torch.Tensor], padding_side="ri
...
@@ -448,8 +448,10 @@ def pad_and_concat(max_length:int, tensors: List[torch.Tensor], padding_side="ri
tensors
[
i
]
=
torch
.
cat
(
tensors
[
i
]
=
torch
.
cat
(
[
[
tensor
,
# [seq]
tensor
,
# [seq]
torch
.
zeros
(
max_length
-
tensor_len
,
dtype
=
torch
.
long
).
to
(
torch
.
zeros
(
tensor
.
device
max_length
-
tensor_len
,
dtype
=
torch
.
long
,
device
=
tensor
.
device
,
),
# [padding_length - seq]
),
# [padding_length - seq]
],
],
dim
=
0
,
dim
=
0
,
...
@@ -458,8 +460,10 @@ def pad_and_concat(max_length:int, tensors: List[torch.Tensor], padding_side="ri
...
@@ -458,8 +460,10 @@ def pad_and_concat(max_length:int, tensors: List[torch.Tensor], padding_side="ri
# left-pad
# left-pad
tensors
[
i
]
=
torch
.
cat
(
tensors
[
i
]
=
torch
.
cat
(
[
[
torch
.
zeros
(
max_length
-
tensor_len
,
dtype
=
torch
.
long
).
to
(
torch
.
zeros
(
tensor
.
device
max_length
-
tensor_len
,
dtype
=
torch
.
long
,
device
=
tensor
.
device
,
),
# [padding_length - seq]
),
# [padding_length - seq]
tensor
,
# [seq]
tensor
,
# [seq]
],
],
...
...
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