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
flash-attention
Commits
b3177dfa
"git@developer.sourcefind.cn:wangsen/paddle_dbnet.git" did not exist on "5a8fed914f96c05f299b46142fed5b76ba6e6db4"
Commit
b3177dfa
authored
Jul 21, 2023
by
Tri Dao
Browse files
[GPT] Enable FlashAttention for GPT-J
parent
6fc1e07d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
5 additions
and
2 deletions
+5
-2
flash_attn/modules/block.py
flash_attn/modules/block.py
+3
-0
tests/models/test_gptj.py
tests/models/test_gptj.py
+2
-2
No files found.
flash_attn/modules/block.py
View file @
b3177dfa
...
@@ -276,6 +276,9 @@ class ParallelBlock(nn.Module):
...
@@ -276,6 +276,9 @@ class ParallelBlock(nn.Module):
for
p
in
self
.
norm2
.
parameters
():
for
p
in
self
.
norm2
.
parameters
():
p
.
_shared_params
=
True
p
.
_shared_params
=
True
def
allocate_inference_cache
(
self
,
batch_size
,
max_seqlen
,
dtype
=
None
,
**
kwargs
):
return
self
.
mixer
.
allocate_inference_cache
(
batch_size
,
max_seqlen
,
dtype
=
dtype
,
**
kwargs
)
def
forward
(
self
,
hidden_states1
:
Tensor
,
hidden_states2
:
Optional
[
Tensor
]
=
None
,
def
forward
(
self
,
hidden_states1
:
Tensor
,
hidden_states2
:
Optional
[
Tensor
]
=
None
,
residual
:
Optional
[
Tensor
]
=
None
,
mixer_kwargs
=
None
):
residual
:
Optional
[
Tensor
]
=
None
,
mixer_kwargs
=
None
):
r
"""Pass the input through the encoder layer.
r
"""Pass the input through the encoder layer.
...
...
tests/models/test_gptj.py
View file @
b3177dfa
...
@@ -36,7 +36,7 @@ def test_gptj_optimized(model_name):
...
@@ -36,7 +36,7 @@ def test_gptj_optimized(model_name):
dtype
=
torch
.
float16
dtype
=
torch
.
float16
device
=
'cuda'
device
=
'cuda'
config
=
gptj_config_to_gpt2_config
(
GPTJConfig
.
from_pretrained
(
model_name
))
config
=
gptj_config_to_gpt2_config
(
GPTJConfig
.
from_pretrained
(
model_name
))
config
.
use_flash_attn
=
Fals
e
# FlashAttention
doesn't
support hdim 256
yet
config
.
use_flash_attn
=
Tru
e
# FlashAttention
-2
support
s
h
ead
dim 256
config
.
fused_bias_fc
=
True
config
.
fused_bias_fc
=
True
config
.
fused_mlp
=
True
config
.
fused_mlp
=
True
config
.
fused_dropout_add_ln
=
True
config
.
fused_dropout_add_ln
=
True
...
@@ -93,7 +93,7 @@ def test_gptj_generation(model_name):
...
@@ -93,7 +93,7 @@ def test_gptj_generation(model_name):
dtype
=
torch
.
float16
dtype
=
torch
.
float16
device
=
'cuda'
device
=
'cuda'
config
=
gptj_config_to_gpt2_config
(
GPTJConfig
.
from_pretrained
(
model_name
))
config
=
gptj_config_to_gpt2_config
(
GPTJConfig
.
from_pretrained
(
model_name
))
config
.
use_flash_attn
=
Fals
e
# FlashAttention
doesn't
support hdim 256
yet
config
.
use_flash_attn
=
Tru
e
# FlashAttention
-2
support
s
h
ead
dim 256
config
.
fused_bias_fc
=
True
config
.
fused_bias_fc
=
True
config
.
fused_mlp
=
True
config
.
fused_mlp
=
True
config
.
fused_dropout_add_ln
=
True
config
.
fused_dropout_add_ln
=
True
...
...
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