Skip to content

Commit 3b77775

Browse files
authored
[CUDA] Remove TensorRT fused causal attention kernels (#29143)
### Description This PR removes the TensorRT fused **causal** attention kernels (the `fmha_v2_*_Causal_*` and `fmha_v2_flash_attention_*_Causal_*` cubins) and all of the code paths that selected them from the CUDA `Attention` operator. These causal fused kernels were disabled by default (since [#14732](#14732)) and were only reachable via the opt-in `ORT_ENABLE_FUSED_CAUSAL_ATTENTION` environment variable / `TRT_CAUSAL_ATTENTION` backend bit. They used fp16 accumulation, which can cause accuracy drops, and have been superseded by flash attention, memory-efficient attention, and cuDNN SDPA. Removing them deletes ~1.27M lines of generated cubin source and simplifies the attention dispatch logic. ### Key Changes - **Removed cubin sources**: Deleted all `causal/fmha_v2_fp16_Causal_*` and `flash_attention/fmha_v2_flash_attention_fp16_Causal_*` generated cubin files (70+ files). - **Dispatch simplification** ([attention.cc](onnxruntime/contrib_ops/cuda/bert/attention.cc)): Removed the `is_unidirectional_` / causal fused-runner branch in `ComputeInternal`; the fused runner path now only handles the BERT (non-causal) case. - **Kernel options** ([attention_kernel_options.cc](onnxruntime/contrib_ops/cuda/bert/attention_kernel_options.cc), [attention_kernel_options.h](onnxruntime/contrib_ops/cuda/bert/attention_kernel_options.h)): Removed `use_trt_causal_attention_`, `UseTrtCausalAttention()`, the `TRT_CAUSAL_ATTENTION` debug print, and the `causal` argument of `SetTrtFusedKernel`. - **QKV format** ([attention_common.h](onnxruntime/contrib_ops/cpu/bert/attention_common.h), [attention_prepare_qkv.cu](onnxruntime/contrib_ops/cuda/bert/attention_prepare_qkv.cu)): Removed the `Q_K_V_BNSH_QKV_BS3NH` format and the fused-causal gemm-buffer-with-bias preparation path. - **Runner API** ([mha_runner.cu](onnxruntime/contrib_ops/cuda/bert/tensorrt_fused_multihead_attention/mha_runner.cu), [mha_runner.h](onnxruntime/contrib_ops/cuda/bert/tensorrt_fused_multihead_attention/mha_runner.h), [fused_multihead_attention_v2.h](onnxruntime/contrib_ops/cuda/bert/tensorrt_fused_multihead_attention/fused_multihead_attention_v2.h)): Dropped the `causal` parameter from `FusedMHARunnerFP16v2::Create` / `IsSupported` and removed the causal kernel metadata. - **Env var removed**: `ORT_ENABLE_FUSED_CAUSAL_ATTENTION` (`kEnableFusedCausalAttention`) is no longer recognized. - **Callers updated**: [multihead_attention.cc](onnxruntime/contrib_ops/cuda/bert/multihead_attention.cc), [packed_attention.cc](onnxruntime/contrib_ops/cuda/bert/packed_attention.cc), [packed_multihead_attention.cc](onnxruntime/contrib_ops/cuda/bert/packed_multihead_attention.cc), [attention_impl.cu](onnxruntime/contrib_ops/cuda/bert/attention_impl.cu) updated to the new no-causal signatures. - **Python helpers**: Removed stale `ORT_ENABLE_FUSED_CAUSAL_ATTENTION` references from the transformers benchmark helper and stable diffusion benchmark. - **Tests updated**: [attention_op_test.cc](onnxruntime/test/contrib_ops/attention_op_test.cc) and [attention_kernel_options_test.cc](onnxruntime/test/providers/cuda/test_cases/attention_kernel_options_test.cc) no longer set/assert the causal-fused option. ### Motivation and Context The fused causal kernels were off by default, carried potential fp16-accumulation accuracy risk, and added a large amount of generated cubin source to the repo. Causal attention is already well covered by flash attention, memory-efficient attention, and cuDNN SDPA, so these kernels can be safely removed to reduce binary size and simplify maintenance. ### Testing - Build the CUDA EP and run the attention contrib op tests (`ContribOpAttentionTest.*`, including `Causal_EmptyPastState`). - Run `AttentionKernelOptionsTest.*` to verify the kernel-option parsing no longer references the causal backend.
1 parent 89a23d8 commit 3b77775

90 files changed

Lines changed: 78 additions & 1270760 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

onnxruntime/contrib_ops/cpu/bert/attention_common.h

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ enum AttentionQkvFormat {
3737
Q_K_V_BNSH, // for non-packed qkv, permuted
3838
Q_K_V_BSNH, // for non-packed qkv, not permuted, used by memory efficient attention or MultiHeadAttention
3939
Q_K_V_BSNH_BNSH_BNSH, // for cross attention, k and v are permuted
40-
Q_K_V_BNSH_QKV_BS3NH, // for TRT fused causal attention, data has two formats (qkv is 3BNSH, gemm_buffer is BS3NH)
4140
Q_K_V_TNH, // for memory efficient attention, qkv are not packed, and paddings are removed.
4241
Q_KV_BSNH_BSN2H, // for TRT fused cross attention, kv are packed
4342
QKV_BSN3H, // for TRT fused attention, qkv are packed
@@ -106,7 +105,6 @@ enum class AttentionBackend : int {
106105
// The following TRT kernels might be deprecated in the future.
107106
TRT_FLASH_ATTENTION = 32,
108107
TRT_CROSS_ATTENTION = 64,
109-
TRT_CAUSAL_ATTENTION = 128,
110108

111109
// Experimental kernels
112110
LEAN_ATTENTION = 256,
@@ -122,14 +120,10 @@ constexpr const char* kDisableFusedSelfAttention = "ORT_DISABLE_FUSED_ATTENTION"
122120
// Environment variable to enable or disable fused cross attention kernel. Default is 0 (enabled).
123121
constexpr const char* kDisableFusedCrossAttention = "ORT_DISABLE_FUSED_CROSS_ATTENTION";
124122

125-
// Environment variable to enable or disable TRT fused causal attention kernels. Default is 0 (disabled).
126-
// Note that those causal attention kernels use fp16 accumulation. There is potential accuracy drop using those kernels.
127-
constexpr const char* kEnableFusedCausalAttention = "ORT_ENABLE_FUSED_CAUSAL_ATTENTION";
128-
129123
// Environment variable to enable or disable cuDNN flash attention.
130124
constexpr const char* kEnableCudnnFlashAttention = "ORT_ENABLE_CUDNN_FLASH_ATTENTION";
131125

132-
// Environment variable to enable or disable TRT flash attention. This applies to both self and causal attention. Default is 0 (enabled).
126+
// Environment variable to enable or disable TRT flash attention. Default is 0 (enabled).
133127
constexpr const char* kDisableTrtFlashAttention = "ORT_DISABLE_TRT_FLASH_ATTENTION";
134128

135129
// Environment variable to enable or disable cutlass memory efficient attention. Default is 0 (enabled).

onnxruntime/contrib_ops/cuda/bert/attention.cc

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,9 @@ Attention<T>::Attention(const OpKernelInfo& info) : CudaKernel(info), AttentionB
4646
constexpr bool kIsBf16 = std::is_same<T, BFloat16>::value;
4747
constexpr bool kIs16bit = kIsFp16 || kIsBf16;
4848

49-
// We only support FP16 for TRT fused/flash/causal attention.
49+
// We only support FP16 for TRT fused/flash attention.
5050
disable_fused_self_attention_ = !kIsFp16 || !kernel_options_->UseTrtFusedAttention();
5151
enable_trt_flash_attention_ = kIsFp16 && kernel_options_->UseTrtFlashAttention();
52-
enable_fused_causal_attention_ = kIsFp16 && kernel_options_->UseTrtCausalAttention();
5352

5453
disable_memory_efficient_attention_ = kIsBf16 || !kernel_options_->UseEfficientAttention();
5554

@@ -151,57 +150,29 @@ Status Attention<T>::ComputeInternal(OpKernelContext* context) const {
151150
auto out_accum_buffer = GetScratchBuffer<void>(0, GetComputeStream(context)); // nullptr
152151
#endif
153152

154-
if (!use_flash_attention) {
155-
if (is_unidirectional_) { // GPT
156-
if (enable_fused_causal_attention_) {
157-
// GPT fused kernels requires left side padding. mask can be:
158-
// none (no padding), 1D sequence lengths or 2d mask.
159-
// Fused kernels don't support different sequence lengths of q and kv, so only apply to the first token
160-
// where past state is empty.
161-
bool is_mask_2d_key_padding = parameters.mask_type == AttentionMaskType::MASK_2D_KEY_PADDING;
162-
bool use_causal_fused_runner = (nullptr == mask_index || is_mask_1d_seq_len || is_mask_2d_key_padding) &&
163-
nullptr == attention_bias &&
164-
parameters.past_sequence_length == 0 &&
165-
parameters.hidden_size == parameters.v_hidden_size &&
166-
FusedMHARunnerFP16v2::IsSupported(sm, parameters.head_size, sequence_length,
167-
enable_trt_flash_attention_, true);
168-
if (use_causal_fused_runner) {
169-
// Here we assume that num_heads, head_size and is_unidirectional does not change for an Attention node.
170-
if (nullptr == fused_fp16_runner_.get()) {
171-
std::call_once(fused_fp16_runner_created_, [&]() {
172-
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(num_heads_, parameters.head_size, sm, is_unidirectional_,
173-
enable_trt_flash_attention_, parameters.scale);
174-
});
175-
}
176-
177-
// Here we assume all causal kernels can be loaded into shared memory. TODO: add a function to check.
178-
fused_runner = fused_fp16_runner_.get();
179-
}
153+
if (!use_flash_attention && !is_unidirectional_) { // BERT
154+
bool use_fused_runner = !disable_fused_self_attention_ &&
155+
(nullptr == mask_index || is_mask_1d_seq_len) &&
156+
nullptr == past &&
157+
nullptr == present &&
158+
nullptr == attention_bias &&
159+
parameters.hidden_size == parameters.v_hidden_size &&
160+
FusedMHARunnerFP16v2::IsSupported(sm, parameters.head_size, sequence_length,
161+
enable_trt_flash_attention_);
162+
163+
if (use_fused_runner) {
164+
// Here we assume that num_heads, head_size and is_unidirectional does not change for an Attention node.
165+
if (nullptr == fused_fp16_runner_.get()) {
166+
std::call_once(fused_fp16_runner_created_, [&]() {
167+
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(num_heads_, parameters.head_size, sm,
168+
enable_trt_flash_attention_, parameters.scale);
169+
});
180170
}
181-
} else { // BERT
182-
bool use_fused_runner = !disable_fused_self_attention_ &&
183-
(nullptr == mask_index || is_mask_1d_seq_len) &&
184-
nullptr == past &&
185-
nullptr == present &&
186-
nullptr == attention_bias &&
187-
parameters.hidden_size == parameters.v_hidden_size &&
188-
FusedMHARunnerFP16v2::IsSupported(sm, parameters.head_size, sequence_length,
189-
enable_trt_flash_attention_, false);
190-
191-
if (use_fused_runner) {
192-
// Here we assume that num_heads, head_size and is_unidirectional does not change for an Attention node.
193-
if (nullptr == fused_fp16_runner_.get()) {
194-
std::call_once(fused_fp16_runner_created_, [&]() {
195-
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(num_heads_, parameters.head_size, sm, is_unidirectional_,
196-
enable_trt_flash_attention_, parameters.scale);
197-
});
198-
}
199-
200-
// In case some kernel not loaded due to shared memory limit, we need to double check here.
201-
const int normalized_seq_len = fused_fp16_runner_->NormalizeSequenceLength(sequence_length);
202-
if (fused_fp16_runner_->IsValid(normalized_seq_len)) {
203-
fused_runner = fused_fp16_runner_.get();
204-
}
171+
172+
// In case some kernel not loaded due to shared memory limit, we need to double check here.
173+
const int normalized_seq_len = fused_fp16_runner_->NormalizeSequenceLength(sequence_length);
174+
if (fused_fp16_runner_->IsValid(normalized_seq_len)) {
175+
fused_runner = fused_fp16_runner_.get();
205176
}
206177
}
207178
}
@@ -227,7 +198,7 @@ Status Attention<T>::ComputeInternal(OpKernelContext* context) const {
227198
debug_info.use_flash_attention = use_flash_attention;
228199
debug_info.use_efficient_attention = use_memory_efficient_attention;
229200
if (fused_runner != nullptr) {
230-
debug_info.SetTrtFusedKernel(is_unidirectional_, enable_trt_flash_attention_, sequence_length);
201+
debug_info.SetTrtFusedKernel(enable_trt_flash_attention_, sequence_length);
231202
}
232203

233204
debug_info.Print("Attention",

onnxruntime/contrib_ops/cuda/bert/attention.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ class Attention final : public CudaKernel, public AttentionBase {
2626
bool disable_flash_attention_;
2727
bool disable_fused_self_attention_;
2828
bool enable_trt_flash_attention_;
29-
bool enable_fused_causal_attention_;
3029
bool disable_memory_efficient_attention_;
3130
mutable std::unique_ptr<MHARunner> fused_fp16_runner_;
3231
mutable std::once_flag fused_fp16_runner_created_;

onnxruntime/contrib_ops/cuda/bert/attention_impl.cu

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ Status FusedTrtSelfAttention(
254254

255255
const int batch_size = parameters.batch_size;
256256
const int sequence_length = parameters.sequence_length;
257-
const bool causal = parameters.is_unidirectional;
258257

259258
const int32_t* sequence_offset = data.cumulated_sequence_length_q_cache;
260259
if (parameters.mask_type == AttentionMaskType::MASK_2D_KEY_PADDING) {
@@ -274,18 +273,13 @@ Status FusedTrtSelfAttention(
274273

275274
FusedMHARunnerFP16v2* fused_fp16_runner = reinterpret_cast<FusedMHARunnerFP16v2*>(data.fused_runner);
276275

277-
const int s = causal ? sequence_length : fused_fp16_runner->NormalizeSequenceLength(sequence_length);
276+
const int s = fused_fp16_runner->NormalizeSequenceLength(sequence_length);
278277

279278
// B = 2 * batch_size when there is padding in input, and B = batch_size when padding is removed.
280279
const int b = (nullptr == data.mask_index ? batch_size : 2 * batch_size);
281280

282-
if (!causal) {
283-
assert(data.qkv_format == AttentionQkvFormat::QKV_BSN3H);
284-
fused_fp16_runner->Run(b, s, data.q, sequence_offset, data.output, stream);
285-
} else {
286-
assert(data.qkv_format == AttentionQkvFormat::Q_K_V_BNSH_QKV_BS3NH);
287-
fused_fp16_runner->Run(b, s, data.gemm_buffer, sequence_offset, data.output, stream);
288-
}
281+
assert(data.qkv_format == AttentionQkvFormat::QKV_BSN3H);
282+
fused_fp16_runner->Run(b, s, data.q, sequence_offset, data.output, stream);
289283

290284
return Status::OK();
291285
}
@@ -802,8 +796,7 @@ Status ConcatPastToPresent(int batch_size, int num_heads, int qk_head_size, int
802796
// When there is past state, the head size for Q/K/V shall be same: H == H_v.
803797

804798
if (nullptr != data.present) { // Attention op
805-
assert(data.qkv_format == AttentionQkvFormat::Q_K_V_BNSH ||
806-
data.qkv_format == AttentionQkvFormat::Q_K_V_BNSH_QKV_BS3NH);
799+
assert(data.qkv_format == AttentionQkvFormat::Q_K_V_BNSH);
807800

808801
ORT_RETURN_IF_ERROR(
809802
LaunchConcatTensorToTensor(

onnxruntime/contrib_ops/cuda/bert/attention_kernel_options.cc

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ void AttentionKernelOptions::Initialize(int value, bool use_build_flag, bool che
2929
use_unfused_ = (value & static_cast<int>(AttentionBackend::MATH)) > 0;
3030
use_trt_flash_attention_ = (value & static_cast<int>(AttentionBackend::TRT_FLASH_ATTENTION)) > 0;
3131
use_trt_cross_attention_ = (value & static_cast<int>(AttentionBackend::TRT_CROSS_ATTENTION)) > 0;
32-
use_trt_causal_attention_ = (value & static_cast<int>(AttentionBackend::TRT_CAUSAL_ATTENTION)) > 0;
3332

3433
use_decoder_attention_ = (value & static_cast<int>(AttentionBackend::DECODER_ATTENTION)) > 0;
3534
} else {
@@ -50,7 +49,6 @@ void AttentionKernelOptions::Initialize(int value, bool use_build_flag, bool che
5049
use_unfused_ = true;
5150
use_trt_flash_attention_ = !ParseEnvironmentVariableWithDefault<bool>(kDisableTrtFlashAttention, false);
5251
use_trt_cross_attention_ = !ParseEnvironmentVariableWithDefault<bool>(kDisableFusedCrossAttention, false);
53-
use_trt_causal_attention_ = ParseEnvironmentVariableWithDefault<bool>(kEnableFusedCausalAttention, false);
5452

5553
use_decoder_attention_ = !ParseEnvironmentVariableWithDefault<bool>(kDisableDecoderAttention, false);
5654
}
@@ -112,7 +110,6 @@ void AttentionKernelOptions::Print() const {
112110
sstream << " CUDNN_FLASH_ATTENTION=" << int(use_cudnn_flash_attention_);
113111
sstream << " TRT_FLASH_ATTENTION=" << int(use_trt_flash_attention_);
114112
sstream << " TRT_CROSS_ATTENTION=" << int(use_trt_cross_attention_);
115-
sstream << " TRT_CAUSAL_ATTENTION=" << int(use_trt_causal_attention_);
116113
sstream << " DECODER_ATTENTION=" << int(use_decoder_attention_);
117114
sstream << " MATH=" << int(use_unfused_);
118115

@@ -126,10 +123,8 @@ void AttentionKernelOptions::Print() const {
126123
}
127124

128125
// Classify the kernel used in TRT fused runner.
129-
void AttentionKernelDebugInfo::SetTrtFusedKernel(bool causal, bool enable_trt_flash_attention, int sequence_length) {
130-
if (causal) {
131-
use_trt_causal_attention = true;
132-
} else if (enable_trt_flash_attention && sequence_length >= contrib::cuda::kMinSequenceLengthFlashAttention) {
126+
void AttentionKernelDebugInfo::SetTrtFusedKernel(bool enable_trt_flash_attention, int sequence_length) {
127+
if (enable_trt_flash_attention && sequence_length >= contrib::cuda::kMinSequenceLengthFlashAttention) {
133128
use_trt_flash_attention = true;
134129
} else {
135130
use_trt_fused_attention = true;
@@ -172,8 +167,6 @@ void AttentionKernelDebugInfo::Print(const char* operator_name,
172167
sstream << "TRT_FLASH_ATTENTION";
173168
} else if (use_trt_cross_attention.has_value() && use_trt_cross_attention.value()) {
174169
sstream << "TRT_CROSS_ATTENTION";
175-
} else if (use_trt_causal_attention.has_value() && use_trt_causal_attention.value()) {
176-
sstream << "TRT_CAUSAL_ATTENTION";
177170
} else if (use_decoder_attention.has_value() && use_decoder_attention.value()) {
178171
sstream << "DECODER_ATTENTION";
179172
} else {

onnxruntime/contrib_ops/cuda/bert/attention_kernel_options.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ struct AttentionKernelDebugInfo {
1515
std::optional<bool> use_cudnn_flash_attention = std::nullopt;
1616
std::optional<bool> use_trt_flash_attention = std::nullopt;
1717
std::optional<bool> use_trt_cross_attention = std::nullopt;
18-
std::optional<bool> use_trt_causal_attention = std::nullopt;
1918
std::optional<bool> use_decoder_attention = std::nullopt;
20-
void SetTrtFusedKernel(bool causal, bool enable_trt_flash_attention, int sequence_length);
19+
void SetTrtFusedKernel(bool enable_trt_flash_attention, int sequence_length);
2120
void Print(const char* operator_name, const std::string& node_name, bool is_float16, bool is_bfloat16) const;
2221
};
2322

@@ -33,7 +32,6 @@ class AttentionKernelOptions {
3332
bool UseUnfusedAttention() const { return use_unfused_; }
3433
bool UseTrtFlashAttention() const { return use_trt_flash_attention_; }
3534
bool UseTrtCrossAttention() const { return use_trt_cross_attention_; }
36-
bool UseTrtCausalAttention() const { return use_trt_causal_attention_; }
3735
bool UseDecoderAttention() const { return use_decoder_attention_; }
3836

3937
// True when the SDPA kernel was explicitly selected via the sdpa_kernel provider option
@@ -67,8 +65,6 @@ class AttentionKernelOptions {
6765

6866
bool use_trt_flash_attention_{true};
6967
bool use_trt_cross_attention_{true};
70-
// Causal attention is disabled by default in #14732.
71-
bool use_trt_causal_attention_{false};
7268

7369
bool use_decoder_attention_{true};
7470

onnxruntime/contrib_ops/cuda/bert/attention_prepare_qkv.cu

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,24 +125,18 @@ Status PrepareQkv_Attention(contrib::AttentionParameters& parameters,
125125
T* qkv = data.workspace;
126126

127127
bool use_fused_kernel = (nullptr != fused_runner && !parameters.is_unidirectional);
128-
bool use_fused_causal = (nullptr != fused_runner && parameters.is_unidirectional);
129128

130129
// For fused TRT attention, transpose qkv to BxSxNx3xH (format 2)
131130
// For flash or memory efficient attention, transpose to 3xBxSxNxH (format 3)
132131
// For unfused kernel, transpose to 3xBxNxSxH (format 1)
133-
// For fused causal kernel, use format 1 since we need have K and V to update present state,
134-
// at the same time, we update gemm_buffer BxSx3xNxH with bias which is used as input for fused causal kernel.
135132
const int format = (use_fused_kernel ? 2 : (use_flash_or_efficient_attention ? 3 : 1));
136133
data.qkv_format = use_fused_kernel
137134
? AttentionQkvFormat::QKV_BSN3H
138135
: (use_flash_or_efficient_attention
139136
? AttentionQkvFormat::Q_K_V_BSNH
140-
: (use_fused_causal
141-
? AttentionQkvFormat::Q_K_V_BNSH_QKV_BS3NH
142-
: AttentionQkvFormat::Q_K_V_BNSH));
137+
: AttentionQkvFormat::Q_K_V_BNSH);
143138

144-
// For fused causal, we will update gemm_buffer with bias directly.
145-
T* qkv_add_bias = use_fused_causal ? data.gemm_buffer : nullptr;
139+
T* qkv_add_bias = nullptr;
146140

147141
int matrix_to_transpose = ((format == AttentionQkvFormat::Q_K_V_BNSH && past_present_share_buffer) ? 1 : 3);
148142
// format 1: BxSx(NH + NH + NH_v) => BxNxSxH + BxNxSxH + BxNxSxH_v

onnxruntime/contrib_ops/cuda/bert/multihead_attention.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -432,14 +432,14 @@ Status MultiHeadAttention<T, QK>::ComputeInternal(OpKernelContext* context) cons
432432
parameters.hidden_size == parameters.v_hidden_size &&
433433
parameters.sequence_length == parameters.kv_sequence_length && // self attention only for fused runner
434434
FusedMHARunnerFP16v2::IsSupported(sm, parameters.head_size, sequence_length,
435-
enable_trt_flash_attention_, is_unidirectional_);
435+
enable_trt_flash_attention_);
436436

437437
DUMP_STRING("Use fused runner = ", (use_fused_runner == true));
438438
if (use_fused_runner) {
439439
// Here we assume that num_heads and head_size does not change for a MultiHeadAttention node.
440440
if (nullptr == fused_fp16_runner_.get()) {
441441
std::call_once(fused_fp16_runner_created_, [&]() {
442-
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(num_heads_, parameters.head_size, sm, is_unidirectional_,
442+
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(num_heads_, parameters.head_size, sm,
443443
enable_trt_flash_attention_, parameters.scale);
444444
});
445445
}
@@ -568,7 +568,7 @@ Status MultiHeadAttention<T, QK>::ComputeInternal(OpKernelContext* context) cons
568568
debug_info.use_trt_cross_attention = fused_cross_attention_kernel != nullptr;
569569
debug_info.use_efficient_attention = use_memory_efficient_attention;
570570
if (fused_fp16_runner_ != nullptr) {
571-
debug_info.SetTrtFusedKernel(is_unidirectional_, enable_trt_flash_attention_, sequence_length);
571+
debug_info.SetTrtFusedKernel(enable_trt_flash_attention_, sequence_length);
572572
}
573573
debug_info.Print("MultiHeadAttention",
574574
this->Node().Name(),

onnxruntime/contrib_ops/cuda/bert/packed_attention.cc

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,15 @@ MHARunner* TrtFusedAttention<T>::GetFusedRunner(const cudaDeviceProp& device_pro
6060
bool is_fMHA_supported = FusedMHARunnerFP16v2::IsSupported(sm,
6161
parameters.head_size,
6262
parameters.sequence_length,
63-
enable_trt_flash_attention_,
64-
false /*causal*/);
63+
enable_trt_flash_attention_);
6564

6665
if (!is_fMHA_supported) {
6766
return fused_runner;
6867
}
6968

7069
// Assuming that num_heads and head_size do not change.
7170
if (nullptr == fused_fp16_runner_.get()) {
72-
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(parameters.num_heads, parameters.head_size, sm, false /*causal*/,
71+
fused_fp16_runner_ = FusedMHARunnerFP16v2::Create(parameters.num_heads, parameters.head_size, sm,
7372
enable_trt_flash_attention_, parameters.scale);
7473
}
7574

@@ -269,7 +268,7 @@ Status PackedAttention<T>::ComputeInternal(OpKernelContext* context) const {
269268
AttentionKernelDebugInfo debug_info;
270269
debug_info.use_efficient_attention = use_memory_efficient_attention;
271270
if (fused_runner != nullptr) {
272-
debug_info.SetTrtFusedKernel(false /*causal*/, this->enable_trt_flash_attention_, parameters.sequence_length);
271+
debug_info.SetTrtFusedKernel(this->enable_trt_flash_attention_, parameters.sequence_length);
273272
}
274273

275274
debug_info.Print("PackedAttention",

onnxruntime/contrib_ops/cuda/bert/packed_multihead_attention.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ Status PackedMultiHeadAttention<T>::ComputeInternal(OpKernelContext* context) co
240240
debug_info.use_flash_attention = use_flash_attention;
241241
debug_info.use_efficient_attention = use_memory_efficient_attention;
242242
if (fused_runner != nullptr) {
243-
debug_info.SetTrtFusedKernel(false /*causal*/, this->enable_trt_flash_attention_, parameters.sequence_length);
243+
debug_info.SetTrtFusedKernel(this->enable_trt_flash_attention_, parameters.sequence_length);
244244
}
245245

246246
debug_info.Print("PackedMultiHeadAttention",

0 commit comments

Comments
 (0)