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
OpenDAS
TransformerEngine
Commits
06d5fa97
Unverified
Commit
06d5fa97
authored
Jul 25, 2023
by
Kirthi Shankar Sivamani
Committed by
GitHub
Jul 25, 2023
Browse files
Make QK layer scaling opt-in (#339)
Signed-off-by:
Kirthi Shankar Sivamani
<
ksivamani@nvidia.com
>
parent
7a30ba45
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
5 additions
and
1 deletion
+5
-1
transformer_engine/pytorch/attention.py
transformer_engine/pytorch/attention.py
+5
-1
No files found.
transformer_engine/pytorch/attention.py
View file @
06d5fa97
...
...
@@ -157,6 +157,10 @@ class UnfusedDotProductAttention(torch.nn.Module):
# on average it should not be partition dependent.
self
.
attention_dropout
=
torch
.
nn
.
Dropout
(
attention_dropout
)
# An FP16 training trick required for certain GPT-like models.
self
.
apply_qk_layer_scaling
=
(
bool
(
int
(
os
.
getenv
(
"NVTE_APPLY_QK_LAYER_SCALING"
,
"0"
)))
and
layer_number
is
not
None
)
def
forward
(
self
,
query_layer
:
torch
.
Tensor
,
...
...
@@ -166,7 +170,7 @@ class UnfusedDotProductAttention(torch.nn.Module):
)
->
torch
.
Tensor
:
"""core attention fprop"""
batch_size
,
seqlen
=
query_layer
.
shape
[
1
],
query_layer
.
shape
[
0
]
apply_qk_layer_scaling
=
self
.
layer_number
is
not
None
and
key_layer
.
dtype
==
torch
.
float16
apply_qk_layer_scaling
=
self
.
apply_qk_layer_scaling
and
key_layer
.
dtype
==
torch
.
float16
# [b, np, sq, sk]
output_size
=
(
...
...
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