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
chenpangpang
transformers
Commits
74cae670
Unverified
Commit
74cae670
authored
Dec 15, 2023
by
Ke Wen
Committed by
GitHub
Dec 15, 2023
Browse files
Make GPT2 traceable in meta state (#28054)
* Put device in tensor constructor instead of to() * Fix copy
parent
e2b6df79
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
2 additions
and
2 deletions
+2
-2
src/transformers/models/decision_transformer/modeling_decision_transformer.py
...els/decision_transformer/modeling_decision_transformer.py
+1
-1
src/transformers/models/gpt2/modeling_gpt2.py
src/transformers/models/gpt2/modeling_gpt2.py
+1
-1
No files found.
src/transformers/models/decision_transformer/modeling_decision_transformer.py
View file @
74cae670
...
...
@@ -185,7 +185,7 @@ class DecisionTransformerGPT2Attention(nn.Module):
mask_value
=
torch
.
finfo
(
attn_weights
.
dtype
).
min
# Need to be a tensor, otherwise we get error: `RuntimeError: expected scalar type float but found double`.
# Need to be on the same device, otherwise `RuntimeError: ..., x and y to be on the same device`
mask_value
=
torch
.
full
([],
mask_value
,
dtype
=
attn_weights
.
dtype
).
to
(
attn_weights
.
device
)
mask_value
=
torch
.
full
([],
mask_value
,
dtype
=
attn_weights
.
dtype
,
device
=
attn_weights
.
device
)
attn_weights
=
torch
.
where
(
causal_mask
,
attn_weights
.
to
(
attn_weights
.
dtype
),
mask_value
)
if
attention_mask
is
not
None
:
...
...
src/transformers/models/gpt2/modeling_gpt2.py
View file @
74cae670
...
...
@@ -198,7 +198,7 @@ class GPT2Attention(nn.Module):
mask_value
=
torch
.
finfo
(
attn_weights
.
dtype
).
min
# Need to be a tensor, otherwise we get error: `RuntimeError: expected scalar type float but found double`.
# Need to be on the same device, otherwise `RuntimeError: ..., x and y to be on the same device`
mask_value
=
torch
.
full
([],
mask_value
,
dtype
=
attn_weights
.
dtype
).
to
(
attn_weights
.
device
)
mask_value
=
torch
.
full
([],
mask_value
,
dtype
=
attn_weights
.
dtype
,
device
=
attn_weights
.
device
)
attn_weights
=
torch
.
where
(
causal_mask
,
attn_weights
.
to
(
attn_weights
.
dtype
),
mask_value
)
if
attention_mask
is
not
None
:
...
...
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