@@ -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