Skip to content

Commit 5c0aecd

Browse files
committed
Use unfused SDPA for short sequences (q_len <= 128 or kv_len <= 128)
Pull Request resolved: #18651 ATT ghstack-source-id: 374666320 @exported-using-ghexport Differential Revision: [D96044308](https://our.internmc.facebook.com/intern/diff/D96044308/)
1 parent 249bcb0 commit 5c0aecd

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

extension/llm/custom_ops/op_sdpa.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,11 @@ Tensor& custom_sdpa_out_impl(
412412
InvalidArgument,
413413
output);
414414

415-
bool use_unfused_sdpa = seq_len == 1;
415+
// Quantized GEMM kernels may not handle non-contiguous per-head strides
416+
// correctly when seq_dim=ONE and seq_len > 1, so keep the conservative
417+
// condition for quantized inputs.
418+
bool is_quantized = q.scalar_type() == ScalarType::Char;
419+
bool use_unfused_sdpa = (!is_quantized) && (seq_len <= 128 || num_keys_for_causal_attention <= 128);
416420
if (use_unfused_sdpa) {
417421
ET_SWITCH_FLOAT_TYPES(output.scalar_type(), ctx, "sdpa", CTYPE, [&] {
418422
sdpa::impl::cpu_sdpa<CTYPE>(

0 commit comments

Comments
 (0)