Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NVIDIA] Add config option to use cudnn flash attention #73

Merged
merged 1 commit into from
Jul 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions paxml/tasks/lm/model_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
from praxis import schedules
from praxis.layers import activations
from praxis.layers import embedding_softmax
from praxis.layers import gpu_fast_attention
from praxis.layers import models
from praxis.layers import transformer_models
from praxis.layers.injection import fp8_nvidia_gpu as fp8_ops
Expand Down Expand Up @@ -583,6 +584,7 @@ class TransformerLmSpmdAdafactor(base_experiment.BaseExperiment):
DECAY_END = 100000
USE_FP8 = False
USE_EXPERT_PARALLEL = False # GPU specific.
USE_CUDNN_FLASH_ATTENTION = False

# optimizer related
DROPOUT_PROB = 0.0
Expand Down Expand Up @@ -699,6 +701,17 @@ def task(self) -> pax_fiddle.Config[tasks_lib.SingleTask]:
if self.USE_ROTARY_POSITION_EMB:
transformer_layer_p.tr_atten_tpl.use_rotary_position_emb = True

if self.USE_CUDNN_FLASH_ATTENTION:
assert transformer_layer_p.tr_atten_tpl.cls == layers.DotProductAttention
causal_mode = transformer_models.LanguageModelType.CAUSAL
assert model_p.lm_tpl.model_type == causal_mode
fused_tr_atten_tpl = pax_fiddle.Config(
gpu_fast_attention.GpuCudnnFusedDotProductAttention,
is_causal=True,
)
fused_tr_atten_tpl.copy_fields_from(transformer_layer_p.tr_atten_tpl)
transformer_layer_p.tr_atten_tpl = fused_tr_atten_tpl

if self.USE_REPEATED_LAYER:
model_p.lm_tpl.stacked_transformer_tpl = pax_fiddle.Config(
layers.StackedTransformerRepeated
Expand Down