@@ -220,7 +220,7 @@ def _compute_attention(
220220 # Get logit sink parameter if configured.
221221 logit_sink = self .parameters .get ("sink" , None )
222222
223- jit_attn = flash_attention_implementation (
223+ flash_specs = flash_attention_implementation (
224224 backend = backend ,
225225 query = q_proj ,
226226 key = k_proj ,
@@ -236,7 +236,7 @@ def _compute_attention(
236236 page_tables = page_indices ,
237237 backend_overrides = cfg .backend_overrides ,
238238 )
239- if jit_attn is None :
239+ if flash_specs is None :
240240 # Fall back to standard attention if no backend kernels are supported.
241241 return super ()._compute_attention (
242242 mode = mode ,
@@ -265,7 +265,6 @@ def _compute_attention(
265265 v_proj = with_sharding_constraint (v_proj , cfg .mha_dim_to_partition_spec [kv_partition ])
266266
267267 # We need to manually partition pallas | jax-triton calls.
268- # Note: shard_map doesn't support kwargs.
269268 input_batch_specs = {
270269 # Q [batch_size, seq_len, num_heads, per_head_dim].
271270 "query" : cfg .mha_dim_to_partition_spec ["btnh" ],
@@ -285,9 +284,10 @@ def _compute_attention(
285284 ),
286285 # PagedKVCache's page indices.
287286 "page_tables" : cfg .mha_dim_to_partition_spec .get ("bs" , PartitionSpec (None )),
287+ ** flash_specs .additional_in_specs ,
288288 }
289289 partitioned_mha = shard_map (
290- jit_attn ,
290+ flash_specs . fn ,
291291 mesh = thread_resources .env .physical_mesh ,
292292 in_specs = (input_batch_specs ,),
293293 # O [batch_size, seq_len, num_heads, per_head_dim].
@@ -307,6 +307,7 @@ def _compute_attention(
307307 "bias" : attention_logit_biases ,
308308 "logit_sink" : logit_sink ,
309309 "page_tables" : page_indices ,
310+ ** flash_specs .additional_kwargs ,
310311 }
311312 outputs = with_sharding_constraint (
312313 partitioned_mha (
@@ -345,7 +346,7 @@ def default_mha_dim_to_partition_spec(
345346 Returns:
346347 A dictionary keyed by MHA tensor dims with partition spec values.
347348 """
348- batch_axis_names = tuple (el for el in mesh_axis_names if el != "model" )
349+ batch_axis_names = tuple (el for el in mesh_axis_names if el in [ "data" , "fsdp" ] )
349350 tp_axis_name = "model" if "model" in mesh_axis_names else None
350351 return {
351352 "btnh" : PartitionSpec (batch_axis_names , None , tp_axis_name , None ),
@@ -369,7 +370,7 @@ def default_output_dim_to_partition_spec(
369370 Returns:
370371 A dictionary keyed by FlashAttention output tensor dims with partition spec values.
371372 """
372- batch_axis_names = tuple (el for el in mesh_axis_names if el not in ["seq " , "model " ])
373+ batch_axis_names = tuple (el for el in mesh_axis_names if el in ["data " , "fsdp " ])
373374 tp_axis_name = "model" if "model" in mesh_axis_names else None
374375 sp_axis_name = "seq" if "seq" in mesh_axis_names else None
375376 return {
0 commit comments