Skip to content

Commit 61f962b

Browse files
committed
deprecate get_logical_axis_rule_from_config
1 parent 085068d commit 61f962b

6 files changed

Lines changed: 41 additions & 50 deletions

File tree

src/maxtext/configs/base.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ xprof_e2e_enable_fw_power_level_event: false
10691069
xprof_e2e_enable_fw_thermal_event: false
10701070
profile_power_events: false # Set to true to enable TPU-specific power/thermal profiling events. Defaults to false to avoid breaking GPU xplane tracing.
10711071

1072-
log_config: true # Prints the config (after defaults have been set by pyconfig logic)
1072+
log_config: false # Prints the config (after defaults have been set by pyconfig logic)
10731073
debug_sharding: false # Prints model weights sharding info
10741074

10751075
# Checkpoint Structured logging

src/maxtext/layers/attention_op.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
from maxtext.layers.initializers import variable_to_logically_partitioned
7676
from maxtext.layers.quantizations import AqtQuantization as Quant
7777
from maxtext.utils import max_utils
78-
from maxtext.utils.sharding import logical_to_mesh_axes, maybe_shard_with_pspec, get_logical_axis_rules_from_config
78+
from maxtext.utils.sharding import logical_to_mesh_axes, maybe_shard_with_pspec, get_logical_axis_rules
7979
import numpy as np
8080
# pylint: disable=line-too-long, g-doc-args, g-doc-return-or-yield, bad-continuation, g-inconsistent-quotes
8181
# pytype: disable=attribute-error
@@ -628,7 +628,7 @@ def maybe_create_nnx(einsum, *args):
628628
self.AqtEinsum_3 = jnp.einsum
629629

630630
def _logical_to_mesh_axes(self, logical_name):
631-
logical_rules = get_logical_axis_rules_from_config(self.config)
631+
logical_rules = get_logical_axis_rules()
632632
return logical_to_mesh_axes(logical_name, mesh=self.mesh, rules=logical_rules)
633633

634634
def check_attention_inputs(self, query: Array, key: Array | KVTensor, value: Array | KVTensor) -> None:

src/maxtext/layers/moe.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
from maxtext.utils import max_utils
4444
from maxtext.utils import maxtext_utils
4545
from maxtext.utils.sharding import create_sharding, maybe_shard_with_logical, maybe_shard_with_pspec
46-
from maxtext.utils.sharding import logical_to_mesh_axes, remove_expert_from_partition_spec, get_logical_axis_rules_from_config
46+
from maxtext.utils.sharding import logical_to_mesh_axes, remove_expert_from_partition_spec, get_logical_axis_rules
4747
import numpy as np
4848
import qwix
4949
from qwix.contrib.sparsity import sparsity_module
@@ -644,7 +644,7 @@ def _maybe_shard_with_logical(self, inputs, logical_name):
644644
)
645645

646646
def _logical_to_mesh_axes(self, logical_name):
647-
logical_rules = get_logical_axis_rules_from_config(self.config)
647+
logical_rules = get_logical_axis_rules()
648648
return logical_to_mesh_axes(logical_name, mesh=self.mesh, rules=logical_rules)
649649

650650
def _maybe_shard_with_pspec(self, inputs, pspec: jax.sharding.PartitionSpec | None):

src/maxtext/models/deepseek.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
from maxtext.utils import max_utils
4343
from maxtext.utils.sharding import create_sharding
4444
from maxtext.utils.sharding import maybe_shard_with_logical
45-
from maxtext.utils.sharding import get_logical_axis_rules_from_config
45+
from maxtext.utils.sharding import get_logical_axis_rules
4646

4747
import transformers
4848

@@ -190,7 +190,7 @@ def with_logical_constraint(self, x):
190190
shard_mode=self.config.shard_mode,
191191
debug_sharding=self.config.debug_sharding,
192192
extra_stack_level=1,
193-
rules=get_logical_axis_rules_from_config(self.config),
193+
rules=get_logical_axis_rules(),
194194
)
195195

196196
def dropout_op(self, x, deterministic):

src/maxtext/utils/sharding.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,6 @@ def get_logical_axis_rules():
5656
return flax_get_logical_axis_rules()
5757

5858

59-
def get_logical_axis_rules_from_config(config):
60-
"""Get the logical axis rules from the config.
61-
When we use pipeline parallelism or in eval step, we may use
62-
a different logical axis rule than the one in config.
63-
Plan to deprecate (b/536927795) and use get_logical_axis_rules instead.
64-
"""
65-
if config.using_pipeline_parallelism or config.eval_interval != -1:
66-
return None
67-
return config.logical_axis_rules
68-
69-
7059
def _get_sharding_desc(inputs, extra_stack_level):
7160
"""Get the inputs sharding description using inspect module"""
7261
frame = inspect.currentframe()

tests/unit/attention_test.py

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)