@@ -1184,22 +1184,23 @@ def test_tpu_flash_attention_ring_context_parallel(self):
11841184 )
11851185 generic_state = nnx .state (attention_as_mha_generic )
11861186
1187- attention_as_mha_flash_cp = Attention (
1188- config = cfg_cp ,
1189- num_query_heads = cfg_cp .num_query_heads ,
1190- num_kv_heads = cfg_cp .num_kv_heads ,
1191- head_dim = cfg_cp .head_dim ,
1192- max_target_length = cfg_cp .max_target_length ,
1193- max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1194- inputs_q_shape = lnx .shape ,
1195- inputs_kv_shape = lnx .shape ,
1196- mesh = mesh_cp ,
1197- attention_kernel = "flash" ,
1198- dtype = cfg_cp .dtype ,
1199- dropout_rate = cfg_cp .dropout_rate ,
1200- model_mode = MODEL_MODE_PREFILL ,
1201- rngs = self .nnx_rng ,
1202- )
1187+ with nn_partitioning .axis_rules (cfg_cp .logical_axis_rules ):
1188+ attention_as_mha_flash_cp = Attention (
1189+ config = cfg_cp ,
1190+ num_query_heads = cfg_cp .num_query_heads ,
1191+ num_kv_heads = cfg_cp .num_kv_heads ,
1192+ head_dim = cfg_cp .head_dim ,
1193+ max_target_length = cfg_cp .max_target_length ,
1194+ max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1195+ inputs_q_shape = lnx .shape ,
1196+ inputs_kv_shape = lnx .shape ,
1197+ mesh = mesh_cp ,
1198+ attention_kernel = "flash" ,
1199+ dtype = cfg_cp .dtype ,
1200+ dropout_rate = cfg_cp .dropout_rate ,
1201+ model_mode = MODEL_MODE_PREFILL ,
1202+ rngs = self .nnx_rng ,
1203+ )
12031204 nnx .update (attention_as_mha_flash_cp , generic_state )
12041205
12051206 mha_generic_flash_cp_output = attention_test_util .forward_with_context_expert_parallelism (
@@ -1255,22 +1256,23 @@ def test_tpu_flash_attention_ring_context_parallel_grad(self):
12551256 )
12561257 generic_state = nnx .state (attention_as_mha_generic )
12571258
1258- attention_as_mha_flash_cp = Attention (
1259- config = cfg_cp ,
1260- num_query_heads = cfg_cp .num_query_heads ,
1261- num_kv_heads = cfg_cp .num_kv_heads ,
1262- head_dim = cfg_cp .head_dim ,
1263- max_target_length = cfg_cp .max_target_length ,
1264- max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1265- inputs_q_shape = lnx .shape ,
1266- inputs_kv_shape = lnx .shape ,
1267- mesh = mesh_cp ,
1268- attention_kernel = "flash" ,
1269- dtype = cfg_cp .dtype ,
1270- dropout_rate = cfg_cp .dropout_rate ,
1271- model_mode = MODEL_MODE_PREFILL ,
1272- rngs = self .nnx_rng ,
1273- )
1259+ with nn_partitioning .axis_rules (cfg_cp .logical_axis_rules ):
1260+ attention_as_mha_flash_cp = Attention (
1261+ config = cfg_cp ,
1262+ num_query_heads = cfg_cp .num_query_heads ,
1263+ num_kv_heads = cfg_cp .num_kv_heads ,
1264+ head_dim = cfg_cp .head_dim ,
1265+ max_target_length = cfg_cp .max_target_length ,
1266+ max_prefill_predict_length = cfg_cp .max_prefill_predict_length ,
1267+ inputs_q_shape = lnx .shape ,
1268+ inputs_kv_shape = lnx .shape ,
1269+ mesh = mesh_cp ,
1270+ attention_kernel = "flash" ,
1271+ dtype = cfg_cp .dtype ,
1272+ dropout_rate = cfg_cp .dropout_rate ,
1273+ model_mode = MODEL_MODE_PREFILL ,
1274+ rngs = self .nnx_rng ,
1275+ )
12741276 nnx .update (attention_as_mha_flash_cp , generic_state )
12751277
12761278 def generic_loss (lnx ):
0 commit comments