Skip to content

Commit 3ff6eb6

Browse files
Merge pull request #4446 from AI-Hypercomputer:chengnuojin-fix-lint
PiperOrigin-RevId: 948475711
2 parents 7dfe73c + 9b46d04 commit 3ff6eb6

30 files changed

Lines changed: 204 additions & 257 deletions

src/maxtext/checkpoint_conversion/utils/param_mapping.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1269,7 +1269,9 @@ def concat_ba_and_transpose(input_tensor, target_shape=None):
12691269
hooks[f"{mlp_prefix}-shared_expert-wo-kernel"] = transpose
12701270
hooks[f"{mlp_prefix}-shared_expert_gate-kernel"] = transpose
12711271

1272-
hooks[(f"{mlp_prefix}-routed_experts-wi_0", f"{mlp_prefix}-routed_experts-wi_1")] = process_wi_0_wi_1 # pyrefly: ignore[unsupported-operation]
1272+
hooks[(f"{mlp_prefix}-routed_experts-wi_0", f"{mlp_prefix}-routed_experts-wi_1")] = (
1273+
process_wi_0_wi_1 # pyrefly: ignore[unsupported-operation]
1274+
)
12731275
hooks[f"{mlp_prefix}-routed_experts-wo"] = transpose_expert
12741276

12751277
# Vision hooks for Qwen3.5
@@ -1340,7 +1342,9 @@ def reshape_vision_attn_out(input_tensor, target_shape):
13401342
return input_tensor.T.reshape(target_shape)
13411343

13421344
# Apply vision hooks
1343-
hooks["params-vision_encoder-Qwen3_5MoeVisionEncoder_0-patch_embed-proj-kernel"] = reshape_conv3d_patch_embed # pyrefly: ignore[bad-assignment]
1345+
hooks["params-vision_encoder-Qwen3_5MoeVisionEncoder_0-patch_embed-proj-kernel"] = (
1346+
reshape_conv3d_patch_embed # pyrefly: ignore[bad-assignment]
1347+
)
13441348

13451349
for i in range(n_vision_layers):
13461350
prefix = f"params-vision_encoder-Qwen3_5MoeVisionEncoder_0-blocks_{i}"
@@ -1355,8 +1359,12 @@ def reshape_vision_attn_out(input_tensor, target_shape):
13551359
hooks[f"{prefix}-mlp_out-kernel"] = reshape_kernel_vision # pyrefly: ignore[bad-assignment]
13561360

13571361
# Vision projector
1358-
hooks["params-vision_encoder-Qwen3_5MoeVisionProjector_0-merger-mlp_0-kernel"] = reshape_kernel_vision # pyrefly: ignore[bad-assignment]
1359-
hooks["params-vision_encoder-Qwen3_5MoeVisionProjector_0-merger-mlp_2-kernel"] = reshape_kernel_vision # pyrefly: ignore[bad-assignment]
1362+
hooks["params-vision_encoder-Qwen3_5MoeVisionProjector_0-merger-mlp_0-kernel"] = (
1363+
reshape_kernel_vision # pyrefly: ignore[bad-assignment]
1364+
)
1365+
hooks["params-vision_encoder-Qwen3_5MoeVisionProjector_0-merger-mlp_2-kernel"] = (
1366+
reshape_kernel_vision # pyrefly: ignore[bad-assignment]
1367+
)
13601368

13611369
return hooks
13621370

@@ -1384,7 +1392,9 @@ def QWEN3_NEXT_MAXTEXT_TO_HF_PARAM_MAPPING(config, maxtext_config, scan_layers=F
13841392
prefix = f"params-decoder-layers-layer_{block_idx}"
13851393

13861394
# Layer norms
1387-
mapping[f"{prefix}-input_layernorm-scale"] = [f"model.layers.{i}.input_layernorm.weight" for i in hf_indices] # pyrefly: ignore[bad-assignment]
1395+
mapping[f"{prefix}-input_layernorm-scale"] = [
1396+
f"model.layers.{i}.input_layernorm.weight" for i in hf_indices
1397+
] # pyrefly: ignore[bad-assignment]
13881398
mapping[f"{prefix}-post_attention_layernorm-scale"] = [ # pyrefly: ignore[bad-assignment]
13891399
f"model.layers.{i}.post_attention_layernorm.weight" for i in hf_indices
13901400
]
@@ -1943,7 +1953,9 @@ def interleave(input_tensor, target_shape=None):
19431953
hooks[f"{prefix}-GptOssMlp-gate-kernel"] = transpose
19441954
# `composite_mt_key`: A hook for combining multiple MaxText params.
19451955
hooks[(f"{prefix}-GptOssMlp-wi_0", f"{prefix}-GptOssMlp-wi_1")] = interleave # pyrefly: ignore[unsupported-operation]
1946-
hooks[(f"{prefix}-GptOssMlp-wi_0_bias", f"{prefix}-GptOssMlp-wi_1_bias")] = interleave # pyrefly: ignore[unsupported-operation]
1956+
hooks[(f"{prefix}-GptOssMlp-wi_0_bias", f"{prefix}-GptOssMlp-wi_1_bias")] = (
1957+
interleave # pyrefly: ignore[unsupported-operation]
1958+
)
19471959

19481960
return hooks
19491961

src/maxtext/common/checkpointing.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,9 +1151,13 @@ def save_checkpoint(checkpoint_manager, step, state, config=None, data_iterator=
11511151
if isinstance(data_iterator, RemoteIteratorWrapper):
11521152
# Pass the wrapper directly; GrainCheckpointHandler will call save_state with the step
11531153
save_args_composite["iter"] = GrainCheckpointSave(item=data_iterator) # pyrefly: ignore[bad-assignment]
1154-
elif not isinstance(data_iterator, list) and isinstance(data_iterator.local_iterator, ElasticIterator): # pyrefly: ignore[missing-attribute]
1154+
elif not isinstance(data_iterator, list) and isinstance(
1155+
data_iterator.local_iterator, ElasticIterator
1156+
): # pyrefly: ignore[missing-attribute]
11551157
# ElasticIterator checkpoints a single global scalar shared by all shards.
1156-
save_args_composite["iter"] = GrainCheckpointSave(item=data_iterator.local_iterator) # pyrefly: ignore[bad-assignment]
1158+
save_args_composite["iter"] = GrainCheckpointSave(
1159+
item=data_iterator.local_iterator
1160+
) # pyrefly: ignore[bad-assignment]
11571161
else:
11581162
if not isinstance(data_iterator, list):
11591163
data_iterator = [data_iterator]
@@ -1163,7 +1167,9 @@ def save_checkpoint(checkpoint_manager, step, state, config=None, data_iterator=
11631167
process_count_total = process_count_total // config.expansion_factor_real_data
11641168
for i, data_iter in enumerate(data_iterator):
11651169
process_index = jax.process_index() + i * jax.process_count()
1166-
grain_iters_to_save.append((data_iter.local_iterator, process_index, process_count_total)) # pyrefly: ignore[missing-attribute]
1170+
grain_iters_to_save.append(
1171+
(data_iter.local_iterator, process_index, process_count_total)
1172+
) # pyrefly: ignore[missing-attribute]
11671173
save_args_composite["iter"] = GrainCheckpointSave(item=grain_iters_to_save) # pyrefly: ignore[bad-assignment]
11681174

11691175
custom_metadata = {}

src/maxtext/inference/decode.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,9 @@ def main(argv: Sequence[str]) -> None:
184184
positions=position_ids, # pyrefly: ignore[bad-argument-type]
185185
mrope_deltas=mrope_position_deltas, # pyrefly: ignore[bad-argument-type]
186186
images=processor_outputs.pixel_values if config.use_multimodal else None, # pyrefly: ignore[bad-argument-type]
187-
image_masks=processor_outputs.pixel_mask if config.use_multimodal and "llama4" in config.model_name else None, # pyrefly: ignore[bad-argument-type]
187+
image_masks=processor_outputs.pixel_mask
188+
if config.use_multimodal and "llama4" in config.model_name
189+
else None, # pyrefly: ignore[bad-argument-type]
188190
videos=getattr(processor_outputs, "video_values", None) if config.use_multimodal else None,
189191
audio_values=processor_outputs.audio_values if config.use_audio else None, # pyrefly: ignore[bad-argument-type]
190192
audio_masks=processor_outputs.audio_mask if config.use_audio else None, # pyrefly: ignore[bad-argument-type]

src/maxtext/inference/kvcache.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,9 @@ def get_cached_values(self, cache_vars, target_dtype, cache_axis_order) -> jax.A
844844
elif dtype == jnp.float8_e4m3fn:
845845
scale_value /= E4M3_MAX
846846

847-
cache_value = KVTensor(qvalue=cache_value, scale=[scale_value], scale_t=None, dequant_dtype=target_dtype, bias=[]) # pyrefly: ignore[unexpected-keyword]
847+
cache_value = KVTensor(
848+
qvalue=cache_value, scale=[scale_value], scale_t=None, dequant_dtype=target_dtype, bias=[]
849+
) # pyrefly: ignore[unexpected-keyword]
848850
cache_value_in_logical_shape = jax.tree.map(lambda x: reverse_transpose(x, cache_axis_order), cache_value)
849851
return cache_value_in_logical_shape
850852

src/maxtext/inference/maxengine/maxengine.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,9 @@ def _nnx_run_model(
219219
nnx.replace_by_pure_dict(cache_state, cache_dict)
220220
# copy=True avoids reusing Variable objects across traces (TraceContextError),
221221
# mirroring the workaround in train.py's diff_wrapper.
222-
model = nnx.merge(self.graphdef, params, cache_state, self._nnx_rest_state, copy=True) # pyrefly: ignore[no-matching-overload]
222+
model = nnx.merge(
223+
self.graphdef, params, cache_state, self._nnx_rest_state, copy=True
224+
) # pyrefly: ignore[no-matching-overload]
223225
logits = model(
224226
decoder_input_tokens,
225227
decoder_positions,
@@ -280,7 +282,9 @@ def _layout(x, s, l):
280282
if x.format == l:
281283
return x
282284
# Somehow this can be None sometimes.
283-
dll = (l.layout if jax.__version_info__ >= (0, 6, 3) else l.device_local_layout) if isinstance(l, Format) else l # pyrefly: ignore[missing-attribute]
285+
dll = (
286+
(l.layout if jax.__version_info__ >= (0, 6, 3) else l.device_local_layout) if isinstance(l, Format) else l
287+
) # pyrefly: ignore[missing-attribute]
284288
f = jax.jit(self._identity, out_shardings=Format(dll, s)).lower(x).compile(compiler_options=xla_flags)
285289
y = f(x)
286290
# Achieves donation of the input argument, but allows for different memory
@@ -409,7 +413,10 @@ def _load_params_nnx(self, params, rng):
409413
with nn_partitioning.axis_rules(self.config.logical_axis_rules):
410414
full_sharding = sharding.nnx_construct_named_sharding(full_abs, self._mesh)
411415
concrete_model = maxtext_utils_nnx.create_nnx_sharded_model(
412-
self.model, self._create_model_fn, mesh=self._mesh, named_sharding=full_sharding # pyrefly: ignore[bad-argument-type]
416+
self.model,
417+
self._create_model_fn,
418+
mesh=self._mesh,
419+
named_sharding=full_sharding, # pyrefly: ignore[bad-argument-type]
413420
)
414421
graphdef, _, _, rest_state = nnx.split(concrete_model, nnx.Param, nnx.Cache, ...)
415422
self.graphdef = graphdef

src/maxtext/input_pipeline/grain_tokenizer.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,9 @@ class TokenizeAndTrim(TokenizerTransformBase, grain.MapTransform):
7171

7272
def map(self, element: dict[str, Any]) -> dict[str, Any]:
7373
"""Maps to each element."""
74-
for feature_name, max_length in zip(self.feature_names, self.sequence_length, strict=True): # pyrefly: ignore[bad-argument-type]
74+
for feature_name, max_length in zip(
75+
self.feature_names, self.sequence_length, strict=True
76+
): # pyrefly: ignore[bad-argument-type]
7577
text = element[feature_name]
7678
token_ids = self._encode(text)[:max_length]
7779
element[feature_name] = np.asarray(token_ids, dtype=np.int32)
@@ -88,7 +90,9 @@ def __post_init__(self):
8890
super().__post_init__()
8991
# TokenizeAndChunk only supports single feature for chunking
9092
assert len(self.feature_names) == 1, "TokenizeAndChunk only supports single feature name"
91-
assert len(self.sequence_length) == 1, "TokenizeAndChunk only supports single sequence length" # pyrefly: ignore[bad-argument-type]
93+
assert (
94+
len(self.sequence_length) == 1
95+
), "TokenizeAndChunk only supports single sequence length" # pyrefly: ignore[bad-argument-type]
9296
self.feature_name = self.feature_names[0] # For backward compatibility
9397
self.sequence_length = self.sequence_length[0] # Convert back to int for chunking # pyrefly: ignore[bad-index]
9498

@@ -104,7 +108,9 @@ def flat_map(self, element: dict[str, Any]) -> list[dict[str, Any]]:
104108

105109
output_elements = []
106110
for start_idx in range(0, len(token_ids), chunk_size): # pyrefly: ignore[bad-argument-type]
107-
chunk = np.asarray(token_ids[start_idx : start_idx + chunk_size], dtype=np.int32) # pyrefly: ignore[unsupported-operation]
111+
chunk = np.asarray(
112+
token_ids[start_idx : start_idx + chunk_size], dtype=np.int32
113+
) # pyrefly: ignore[unsupported-operation]
108114
new_element = {self.feature_name: chunk}
109115
output_elements.append(new_element)
110116

src/maxtext/input_pipeline/input_pipeline_utils.py

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ def is_conversational(features, data_columns):
172172
for column in data_columns:
173173
messages = features[column]
174174
if isinstance(messages, datasets.Sequence):
175-
if isinstance(messages.feature, dict) and "role" in messages.feature and "content" in messages.feature: # pyrefly: ignore[missing-attribute]
175+
if (
176+
isinstance(messages.feature, dict) and "role" in messages.feature and "content" in messages.feature
177+
): # pyrefly: ignore[missing-attribute]
176178
return True
177179

178180
return False
@@ -840,11 +842,19 @@ def map(
840842
if isinstance(element[data_column], mm_utils.PreprocessorOutput):
841843
raise TypeError("Only 'images' column can be of type PreprocessorOutput.")
842844

843-
element[f"{data_column}_segmentation"] = element[data_column] != self.pad_id # pyrefly: ignore[unsupported-operation]
844-
element[f"{data_column}_segmentation"] = element[f"{data_column}_segmentation"].astype(np.int32) # pyrefly: ignore[missing-attribute]
845-
element[f"{data_column}_position"] = np.arange(element[data_column].shape[0], dtype=np.int32) # pyrefly: ignore[missing-attribute]
845+
element[f"{data_column}_segmentation"] = (
846+
element[data_column] != self.pad_id
847+
) # pyrefly: ignore[unsupported-operation]
848+
element[f"{data_column}_segmentation"] = element[f"{data_column}_segmentation"].astype(
849+
np.int32
850+
) # pyrefly: ignore[missing-attribute]
851+
element[f"{data_column}_position"] = np.arange(
852+
element[data_column].shape[0], dtype=np.int32
853+
) # pyrefly: ignore[missing-attribute]
846854
if self.add_true_length:
847-
element[f"{data_column}_true_length"] = np.array([element[data_column].shape[0]], dtype=np.int32) # pyrefly: ignore[missing-attribute]
855+
element[f"{data_column}_true_length"] = np.array(
856+
[element[data_column].shape[0]], dtype=np.int32
857+
) # pyrefly: ignore[missing-attribute]
848858

849859
for key, _ in element.items():
850860
if key == "images":

src/maxtext/integration/vllm/maxtext_vllm_adapter/adapter.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,7 @@ def load_weights(self, rng_key: jax.Array) -> None:
345345
self.maxtext_config, mesh=self.mesh, model_mode=self.model_mode, rng_key=rng_key
346346
)
347347
if self.maxtext_config.lora.enable_lora:
348-
model = lora_utils.apply_lora_to_model(
349-
model, self.mesh, self.maxtext_config
350-
)
348+
model = lora_utils.apply_lora_to_model(model, self.mesh, self.maxtext_config)
351349
if self.maxtext_config.lora.lora_restore_path:
352350
lora_utils.restore_lora_from_path(model, self.maxtext_config)
353351
self.model = nnx.data(model)

src/maxtext/kernels/attention/splash_attention_kernel.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -624,7 +624,9 @@ def _apply_mask_and_soft_cap(
624624

625625
repeats, rem = divmod(k_slice.size, NUM_LANES)
626626
assert rem == 0
627-
q_sequence = jnp.tile(q_sequence_ref[...], (1, repeats)) # [bq, k_slice.size] # pyrefly: ignore[unsupported-operation]
627+
q_sequence = jnp.tile(
628+
q_sequence_ref[...], (1, repeats)
629+
) # [bq, k_slice.size] # pyrefly: ignore[unsupported-operation]
628630
else:
629631
assert q_sequence_ref.shape == (NUM_SUBLANES, bq) # pyrefly: ignore[missing-attribute]
630632

@@ -1694,7 +1696,9 @@ def run():
16941696
if is_mqa:
16951697
should_write = jnp.logical_and(should_write, q_head_index == num_q_heads - 1)
16961698
elif num_kv_heads < num_q_heads:
1697-
should_write = jnp.logical_and(should_write, q_head_index_per_kv_head == q_heads_per_kv_heads - 1) # pyrefly: ignore[unsupported-operation]
1699+
should_write = jnp.logical_and(
1700+
should_write, q_head_index_per_kv_head == q_heads_per_kv_heads - 1
1701+
) # pyrefly: ignore[unsupported-operation]
16981702

16991703
@pl.when(should_write)
17001704
def end():
@@ -2425,8 +2429,12 @@ def manual_sharding_spec(self, sharding: jax.sharding.NamedSharding):
24252429
data_next=spec if self.fwd_mask_info.data_next is not None else None, # pyrefly: ignore[bad-argument-type]
24262430
mask_next=spec if self.fwd_mask_info.mask_next is not None else None, # pyrefly: ignore[bad-argument-type]
24272431
block_mask=spec if self.fwd_mask_info.block_mask is not None else None, # pyrefly: ignore[bad-argument-type]
2428-
partial_mask_blocks=partial_mask_blocks_spec if self.fwd_mask_info.partial_mask_blocks is not None else None, # pyrefly: ignore[bad-argument-type]
2429-
q_sequence=q_sequence_spec if self.fwd_mask_info.q_sequence is not None else None, # pyrefly: ignore[bad-argument-type]
2432+
partial_mask_blocks=partial_mask_blocks_spec
2433+
if self.fwd_mask_info.partial_mask_blocks is not None
2434+
else None, # pyrefly: ignore[bad-argument-type]
2435+
q_sequence=q_sequence_spec
2436+
if self.fwd_mask_info.q_sequence is not None
2437+
else None, # pyrefly: ignore[bad-argument-type]
24302438
)
24312439
return SplashAttentionKernel(
24322440
mask_info_specs,

src/maxtext/kernels/gather_reduce_sc.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -570,7 +570,9 @@ def get_row_val(row_idx):
570570
row0 = arith.mulf(row0, weights_vecs[0]) # pyrefly: ignore[unsupported-operation]
571571
if topk_wgt_zero_nan:
572572
row0 = arith.select(
573-
arith.cmpf(arith.CmpFPredicate.OEQ, weights_vecs[0], zero_vec_f32), # pyrefly: ignore[unbound-name, unsupported-operation]
573+
arith.cmpf(
574+
arith.CmpFPredicate.OEQ, weights_vecs[0], zero_vec_f32
575+
), # pyrefly: ignore[unbound-name, unsupported-operation]
574576
zero_vec_f32,
575577
row0,
576578
)
@@ -580,7 +582,9 @@ def get_row_val(row_idx):
580582
row8 = arith.mulf(row8, weights_vecs[8]) # pyrefly: ignore[unsupported-operation]
581583
if topk_wgt_zero_nan:
582584
row8 = arith.select(
583-
arith.cmpf(arith.CmpFPredicate.OEQ, weights_vecs[8], zero_vec_f32), # pyrefly: ignore[unsupported-operation]
585+
arith.cmpf(
586+
arith.CmpFPredicate.OEQ, weights_vecs[8], zero_vec_f32
587+
), # pyrefly: ignore[unsupported-operation]
584588
zero_vec_f32,
585589
row8,
586590
)

0 commit comments

Comments
 (0)