Skip to content

Commit 5a49893

Browse files
[fusilli] Emit custom scale SDPA through flex attention
Remove the regular SDPA scale fallback now that torch.hop_flex_attention supports an explicit scale operand. Update the custom-scale emitter test to expect flex_attention and remove the stale custom-scale xfail. Co-authored-by: GPT-5 Codex <noreply@openai.com> Signed-off-by: Keshav Vinayak Jha <keshavvinayakjha@gmail.com>
1 parent 743a400 commit 5a49893

4 files changed

Lines changed: 7 additions & 22 deletions

File tree

include/fusilli/support/asm_emitter.h

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,12 +2478,7 @@ inline bool SdpaNode::useLegacySdpaAsm() const {
24782478
if (sdpaAttr.getMASK() || sdpaAttr.getDropout() != 0.0f)
24792479
return true;
24802480

2481-
// The legacy SDPA op does not produce logsumexp, so keep generate_stats on
2482-
// flex_attention even when extra attributes are present.
2483-
if (sdpaAttr.getGenerateStats())
2484-
return false;
2485-
2486-
return sdpaAttr.getScale().has_value();
2481+
return false;
24872482
}
24882483

24892484
inline std::string SdpaNode::emitModuleScopeAsm() const {

samples/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,8 +198,3 @@ add_fusilli_samples(
198198
libsdpautils
199199
Catch2::Catch2WithMain
200200
)
201-
202-
# XFAIL: TODO(#404): Remove once regular SDPA supports non-default scales.
203-
set_tests_properties(
204-
fusilli_sdpa_samples_sdpa_fprop_custom_scale
205-
PROPERTIES WILL_FAIL TRUE)

samples/sdpa_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ inline constexpr std::string_view kSdpaWithMask = R"mlir(
9494
)mlir";
9595
// clang-format on
9696

97-
/// Builds the MLIR template for torch.aten.scaled_dot_product_attention.
97+
/// Builds the MLIR template for SDPA custom-op samples.
9898
///
9999
/// Selects the appropriate R-string template (with/without attn_mask) and
100100
/// resolves scalar placeholders. Standard CustomOp dtype/name placeholders

tests/lit/test_sdpa_asm_emitter_custom_scale.cpp

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44
// See https://llvm.org/LICENSE.txt for license information.
55
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
66

7-
// XFAIL: *
8-
// TODO(iree-org/fusilli#404): Remove XFAIL once IREE supports non-default SDPA
9-
// scale values.
107
// RUN: %{TEST_EXE} | iree-opt --verify-roundtrip
118
// RUN: %{TEST_EXE} | FileCheck %s --check-prefix=TORCH-CHECK
129
// RUN: %{TEST_EXE} stats | FileCheck %s --check-prefix=%{BACKEND}-STATS-CHECK
@@ -33,12 +30,10 @@
3330
// TORCH-CHECK: %permute_V_val_3_sdpa = torch.constant.int 3
3431
// TORCH-CHECK: %permute_V_sdpa = torch.prim.ListConstruct %permute_V_val_0_sdpa, %permute_V_val_1_sdpa, %permute_V_val_2_sdpa, %permute_V_val_3_sdpa : (!torch.int, !torch.int, !torch.int, !torch.int) -> !torch.list<int>
3532
// TORCH-CHECK: %v_sdpa_perm = torch.aten.permute %v, %permute_V_sdpa : !torch.vtensor<[1,8,64,64],f16>, !torch.list<int> -> !torch.vtensor<[1,8,64,64],f16>
36-
// TORCH-CHECK: %none_mask_sdpa = torch.constant.none
37-
// TORCH-CHECK: %dropout_sdpa = torch.constant.float 0.000000e+00
38-
// TORCH-CHECK: %is_causal_sdpa = torch.constant.bool false
3933
// TORCH-CHECK: %scale_sdpa = torch.constant.float 5.000000e-02
40-
// TORCH-CHECK: %enable_gqa_sdpa = torch.constant.bool false
41-
// TORCH-CHECK: %sdpa_O_sdpa_perm = torch.aten.scaled_dot_product_attention %q_sdpa_perm, %k_sdpa_perm, %v_sdpa_perm, %none_mask_sdpa, %dropout_sdpa, %is_causal_sdpa, %scale_sdpa, %enable_gqa_sdpa : !torch.vtensor<[1,8,64,64],f16>, !torch.vtensor<[1,8,64,64],f16>, !torch.vtensor<[1,8,64,64],f16>, !torch.none, !torch.float, !torch.bool, !torch.float, !torch.bool -> !torch.vtensor<[1,8,64,64],f16>
34+
// TORCH-CHECK: %return_lse_sdpa = torch.constant.bool false
35+
// TORCH-CHECK: %return_max_scores_sdpa = torch.constant.bool false
36+
// TORCH-CHECK: %sdpa_O_sdpa_perm, %sdpa_logsumexp_sdpa, %sdpa_max_scores_sdpa = torch.hop_flex_attention %q_sdpa_perm, %k_sdpa_perm, %v_sdpa_perm, %scale_sdpa, %return_lse_sdpa, %return_max_scores_sdpa : !torch.vtensor<[1,8,64,64],f16>, !torch.vtensor<[1,8,64,64],f16>, !torch.vtensor<[1,8,64,64],f16>, !torch.float, !torch.bool, !torch.bool -> !torch.vtensor<[1,8,64,64],f16>, !torch.none, !torch.none
4237
// TORCH-CHECK: %permute_O_val_0_sdpa = torch.constant.int 0
4338
// TORCH-CHECK: %permute_O_val_1_sdpa = torch.constant.int 1
4439
// TORCH-CHECK: %permute_O_val_2_sdpa = torch.constant.int 2
@@ -51,9 +46,9 @@
5146
// TORCH-CHECK: }
5247
//
5348
// AMDGPU-STATS-CHECK: "transient-memory-size": 0
54-
// AMDGPU-STATS-CHECK: "dispatch-count": 1
49+
// AMDGPU-STATS-CHECK: "dispatch-count": {{[1-9][0-9]*}}
5550
// CPU-STATS-CHECK: "transient-memory-size": 0
56-
// CPU-STATS-CHECK: "dispatch-count": 1
51+
// CPU-STATS-CHECK: "dispatch-count": {{[1-9][0-9]*}}
5752
//
5853
// clang-format on
5954

0 commit comments

Comments
 (0)