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
97f439ae
Unverified
Commit
97f439ae
authored
Sep 18, 2023
by
mksit
Committed by
GitHub
Sep 18, 2023
Browse files
Create the return value on device to avoid unnecessary copying from CPU (#26151)
parent
42791a57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
1 addition
and
1 deletion
+1
-1
src/transformers/models/switch_transformers/modeling_switch_transformers.py
...odels/switch_transformers/modeling_switch_transformers.py
+1
-1
No files found.
src/transformers/models/switch_transformers/modeling_switch_transformers.py
View file @
97f439ae
...
@@ -779,7 +779,7 @@ class SwitchTransformersBlock(nn.Module):
...
@@ -779,7 +779,7 @@ class SwitchTransformersBlock(nn.Module):
if
isinstance
(
hidden_states
,
tuple
):
if
isinstance
(
hidden_states
,
tuple
):
hidden_states
,
router_tuple
=
hidden_states
hidden_states
,
router_tuple
=
hidden_states
else
:
else
:
router_tuple
=
(
torch
.
tensor
([
0
]
,
device
=
hidden_states
.
device
),)
router_tuple
=
(
torch
.
zeros
((
1
,)
,
device
=
hidden_states
.
device
,
dtype
=
torch
.
int64
),)
# clamp inf values to enable fp16 training
# clamp inf values to enable fp16 training
if
hidden_states
.
dtype
==
torch
.
float16
and
torch
.
isinf
(
hidden_states
).
any
():
if
hidden_states
.
dtype
==
torch
.
float16
and
torch
.
isinf
(
hidden_states
).
any
():
...
...
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