@@ -1190,22 +1190,23 @@ def test_tpu_flash_attention_ring_context_parallel(self, context_parallel_load_b
11901190 )
11911191 generic_state = nnx .state (attention_as_mha_generic )
11921192
1193- attention_as_mha_flash_cp = Attention (
1194- config = cfg_cp ,
1195- num_query_heads = cfg_cp .num_query_heads ,
1196- num_kv_heads = cfg_cp .num_kv_heads ,
1197- head_dim = cfg_cp .head_dim ,
1198- max_target_length = cfg_cp .max_target_length ,
1199- max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1200- inputs_q_shape = lnx .shape ,
1201- inputs_kv_shape = lnx .shape ,
1202- mesh = mesh_cp ,
1203- attention_kernel = "flash" ,
1204- dtype = cfg_cp .dtype ,
1205- dropout_rate = cfg_cp .dropout_rate ,
1206- model_mode = MODEL_MODE_PREFILL ,
1207- rngs = self .nnx_rng ,
1208- )
1193+ with nn_partitioning .axis_rules (cfg_cp .logical_axis_rules ):
1194+ attention_as_mha_flash_cp = Attention (
1195+ config = cfg_cp ,
1196+ num_query_heads = cfg_cp .num_query_heads ,
1197+ num_kv_heads = cfg_cp .num_kv_heads ,
1198+ head_dim = cfg_cp .head_dim ,
1199+ max_target_length = cfg_cp .max_target_length ,
1200+ max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1201+ inputs_q_shape = lnx .shape ,
1202+ inputs_kv_shape = lnx .shape ,
1203+ mesh = mesh_cp ,
1204+ attention_kernel = "flash" ,
1205+ dtype = cfg_cp .dtype ,
1206+ dropout_rate = cfg_cp .dropout_rate ,
1207+ model_mode = MODEL_MODE_PREFILL ,
1208+ rngs = self .nnx_rng ,
1209+ )
12091210 nnx .update (attention_as_mha_flash_cp , generic_state )
12101211
12111212 mha_generic_flash_cp_output = attention_test_util .forward_with_context_expert_parallelism (
@@ -1266,22 +1267,23 @@ def test_tpu_flash_attention_ring_context_parallel_grad(self, context_parallel_l
12661267 )
12671268 generic_state = nnx .state (attention_as_mha_generic )
12681269
1269- attention_as_mha_flash_cp = Attention (
1270- config = cfg_cp ,
1271- num_query_heads = cfg_cp .num_query_heads ,
1272- num_kv_heads = cfg_cp .num_kv_heads ,
1273- head_dim = cfg_cp .head_dim ,
1274- max_target_length = cfg_cp .max_target_length ,
1275- max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1276- inputs_q_shape = lnx .shape ,
1277- inputs_kv_shape = lnx .shape ,
1278- mesh = mesh_cp ,
1279- attention_kernel = "flash" ,
1280- dtype = cfg_cp .dtype ,
1281- dropout_rate = cfg_cp .dropout_rate ,
1282- model_mode = MODEL_MODE_PREFILL ,
1283- rngs = self .nnx_rng ,
1284- )
1270+ with nn_partitioning .axis_rules (cfg_cp .logical_axis_rules ):
1271+ attention_as_mha_flash_cp = Attention (
1272+ config = cfg_cp ,
1273+ num_query_heads = cfg_cp .num_query_heads ,
1274+ num_kv_heads = cfg_cp .num_kv_heads ,
1275+ head_dim = cfg_cp .head_dim ,
1276+ max_target_length = cfg_cp .max_target_length ,
1277+ max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1278+ inputs_q_shape = lnx .shape ,
1279+ inputs_kv_shape = lnx .shape ,
1280+ mesh = mesh_cp ,
1281+ attention_kernel = "flash" ,
1282+ dtype = cfg_cp .dtype ,
1283+ dropout_rate = cfg_cp .dropout_rate ,
1284+ model_mode = MODEL_MODE_PREFILL ,
1285+ rngs = self .nnx_rng ,
1286+ )
12851287 nnx .update (attention_as_mha_flash_cp , generic_state )
12861288
12871289 def generic_loss (lnx ):
0 commit comments