@@ -62,6 +62,7 @@ Tensor& custom_sdpa_out_no_context(
6262 const bool is_causal,
6363 // @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
6464 const optional<double > scale,
65+ const bool is_seq_dim_2,
6566 Tensor& output);
6667
6768at::Tensor custom_sdpa_aten (
@@ -75,7 +76,8 @@ at::Tensor custom_sdpa_aten(
7576 const double dropout_p,
7677 const bool is_causal,
7778 // @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
78- const std::optional<double > scale);
79+ const std::optional<double > scale,
80+ const bool is_seq_dim_2);
7981
8082Tensor& custom_quantized_sdpa_out_no_context (
8183 const Tensor& q,
@@ -224,6 +226,7 @@ Tensor& custom_sdpa_out_no_context(
224226 const bool is_causal,
225227 // @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
226228 const optional<double > scale,
229+ const bool is_seq_dim_2,
227230 Tensor& output) {
228231 executorch::aten::RuntimeContext context{};
229232 return torch::executor::native::custom_sdpa_out (
@@ -236,6 +239,7 @@ Tensor& custom_sdpa_out_no_context(
236239 dropout_p,
237240 is_causal,
238241 scale,
242+ is_seq_dim_2,
239243 output);
240244}
241245
@@ -250,10 +254,20 @@ at::Tensor custom_sdpa_aten(
250254 const double dropout_p,
251255 const bool is_causal,
252256 // @lint-ignore CLANGTIDY facebook-hte-ParameterMightThrowOnCopy
253- const std::optional<double > scale) {
257+ const std::optional<double > scale,
258+ const bool is_seq_dim_2) {
254259 auto output = at::empty (q.sizes ());
255- WRAP_TO_ATEN (custom_sdpa_out_no_context, 8 )
256- (q, k, v, start_pos, attn_mask, dropout_p, is_causal, scale, output);
260+ WRAP_TO_ATEN (custom_sdpa_out_no_context, 9 )
261+ (q,
262+ k,
263+ v,
264+ start_pos,
265+ attn_mask,
266+ dropout_p,
267+ is_causal,
268+ scale,
269+ is_seq_dim_2,
270+ output);
257271 return output;
258272}
259273
@@ -401,11 +415,11 @@ TORCH_LIBRARY_FRAGMENT(llama, m) {
401415 m.def (
402416 " custom_sdpa(Tensor query, Tensor key, Tensor value, SymInt start_pos, "
403417 " Tensor? attn_mask=None, float drpout_p=0.0, bool is_causal=False, "
404- " float? scale=None) -> Tensor" );
418+ " float? scale=None, bool is_seq_dim_2=False ) -> Tensor" );
405419 m.def (
406420 " custom_sdpa.out(Tensor query, Tensor key, Tensor value, SymInt start_pos, "
407421 " Tensor? attn_mask=None, float drpout_p=0.0, bool is_causal=False, "
408- " float? scale=None, *, Tensor(a!) out) -> Tensor(a!)" );
422+ " float? scale=None, bool is_seq_dim_2=False, *, Tensor(a!) out) -> Tensor(a!)" );
409423 m.def (
410424 " update_cache(Tensor value, Tensor(a!) cache, "
411425 " SymInt start_pos, bool is_seq_dim_2=False) -> Tensor" );
@@ -443,7 +457,7 @@ TORCH_LIBRARY_IMPL(llama, CompositeExplicitAutograd, m) {
443457 m.impl (" custom_sdpa" , torch::executor::native::custom_sdpa_aten);
444458 m.impl (
445459 " custom_sdpa.out" ,
446- WRAP_TO_ATEN (torch::executor::native::custom_sdpa_out_no_context, 8 ));
460+ WRAP_TO_ATEN (torch::executor::native::custom_sdpa_out_no_context, 9 ));
447461 m.impl (" update_cache" , torch::executor::native::update_cache_aten);
448462 m.impl (
449463 " update_cache.out" ,
0 commit comments