Skip to content

Commit 64dc147

Browse files
committed
fix: linting and revert missing function
1 parent def7009 commit 64dc147

3 files changed

Lines changed: 333 additions & 301 deletions

File tree

src/MaxText/layers/initializers.py

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ def variable_to_logically_partitioned(variable: nnx.VariableState):
6666
"""
6767
val = variable.value
6868

69-
7069
if isinstance(variable.value, aqt_tensor.QTensor):
7170
return variable.value
7271

@@ -84,24 +83,24 @@ def variable_to_logically_partitioned(variable: nnx.VariableState):
8483
sharding_names = metadata["sharding_names"]
8584
else:
8685
sharding_names = metadata["sharding"]
87-
86+
8887
# --- Auto-Patching for Pipeline Expansion ---
8988
# If the value rank is greater than the sharding rank, it implies pipeline expansion
9089
# occurred (broadcasting), but the metadata is stale. We patch the spec here.
91-
if hasattr(val, 'ndim') and isinstance(sharding_names, tuple):
92-
val_rank = val.ndim
93-
spec_rank = len(sharding_names)
94-
diff = val_rank - spec_rank
95-
96-
if diff > 0:
97-
# Prepend axes based on rank difference
98-
# Diff 2: [Repeats, Stage, ...] -> ('circular_repeats', 'activation_stage', ...)
99-
# Diff 1: [Stage, ...] -> ('activation_stage', ...)
100-
if diff == 2:
101-
sharding_names = ('circular_repeats', 'layers') + sharding_names
102-
elif diff == 1:
103-
sharding_names = ('layers',) + sharding_names
104-
90+
if hasattr(val, "ndim") and isinstance(sharding_names, tuple):
91+
val_rank = val.ndim
92+
spec_rank = len(sharding_names)
93+
diff = val_rank - spec_rank
94+
95+
if diff > 0:
96+
# Prepend axes based on rank difference
97+
# Diff 2: [Repeats, Stage, ...] -> ('circular_repeats', 'activation_stage', ...)
98+
# Diff 1: [Stage, ...] -> ('activation_stage', ...)
99+
if diff == 2:
100+
sharding_names = ("circular_repeats", "layers") + sharding_names
101+
elif diff == 1:
102+
sharding_names = ("layers",) + sharding_names
103+
105104
# ---------------------------------------------
106105

107106
return nn.LogicallyPartitioned( # type: ignore[wrong-keyword-args]
@@ -111,4 +110,4 @@ def variable_to_logically_partitioned(variable: nnx.VariableState):
111110
rules=metadata.get("rules"),
112111
)
113112
else:
114-
return variable.value
113+
return variable.value

0 commit comments

Comments
 (0)