Skip to content

Commit e3144b3

Browse files
h-jooGoogle-ML-Automation
authored andcommitted
Automated Code Change
PiperOrigin-RevId: 944783931
1 parent 7957526 commit e3144b3

39 files changed

Lines changed: 363 additions & 358 deletions

src/maxtext/checkpoint_conversion/utils/hf_model_configs.py

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919

2020
import transformers
2121

22-
if transformers.__version__ >= "5.0.0":
22+
if transformers.__version__ >= "5.0.0": # pyrefly: ignore[missing-attribute]
2323
from transformers.configuration_utils import PreTrainedConfig as PTConfig # pytype: disable=import-error
2424
else:
2525
from transformers.configuration_utils import PretrainedConfig as PTConfig
@@ -120,7 +120,7 @@
120120

121121
gemma4_31b_dict = gemma4_26b_dict.copy()
122122
gemma4_31b_dict["text_config"] = gemma4_26b_dict["text_config"].copy()
123-
gemma4_31b_dict["text_config"].update(
123+
gemma4_31b_dict["text_config"].update( # pyrefly: ignore[no-matching-overload]
124124
{
125125
"enable_moe_block": False,
126126
"hidden_size": 5376,
@@ -265,10 +265,10 @@
265265

266266
try:
267267
# Will execute successfully if Transformers is updated with Gemma 4 support
268-
gemma4_26b_config = transformers.Gemma4Config(**gemma4_26b_dict)
269-
gemma4_31b_config = transformers.Gemma4Config(**gemma4_31b_dict)
270-
gemma4_e2b_config = transformers.Gemma4Config(**gemma4_e2b_dict)
271-
gemma4_e4b_config = transformers.Gemma4Config(**gemma4_e4b_dict)
268+
gemma4_26b_config = transformers.Gemma4Config(**gemma4_26b_dict) # pyrefly: ignore[missing-attribute]
269+
gemma4_31b_config = transformers.Gemma4Config(**gemma4_31b_dict) # pyrefly: ignore[missing-attribute]
270+
gemma4_e2b_config = transformers.Gemma4Config(**gemma4_e2b_dict) # pyrefly: ignore[missing-attribute]
271+
gemma4_e4b_config = transformers.Gemma4Config(**gemma4_e4b_dict) # pyrefly: ignore[missing-attribute]
272272
except AttributeError:
273273
# Graceful fallback to raw dict-based PTConfig if Gemma 4 natively is missing
274274
gemma4_26b_config = PTConfig(**gemma4_26b_dict) # pytype: disable=wrong-arg-types
@@ -1011,7 +1011,7 @@
10111011

10121012

10131013
# TODO(shuningjin): replace with DeepseekV32Config when available in transformers library
1014-
class DeepseekV32Config(PTConfig):
1014+
class DeepseekV32Config(PTConfig): # pyrefly: ignore[invalid-inheritance]
10151015
model_type = "deepseek_v32"
10161016

10171017
def __init__(self, **kwargs):
@@ -1089,7 +1089,7 @@ def __init__(self, **kwargs):
10891089
"use_cache": True,
10901090
"vocab_size": 201088,
10911091
}
1092-
gpt_oss_20b_config = transformers.GptOssConfig(**gpt_oss_20b_dict)
1092+
gpt_oss_20b_config = transformers.GptOssConfig(**gpt_oss_20b_dict) # pyrefly: ignore[bad-argument-type]
10931093

10941094
# from https://huggingface.co/openai/gpt-oss-120b/blob/main/config.json
10951095
# remove mxfp4 quantization_config, since we are using bf16
@@ -1171,7 +1171,7 @@ def __init__(self, **kwargs):
11711171
"use_cache": True,
11721172
"vocab_size": 201088,
11731173
}
1174-
gpt_oss_120b_config = transformers.GptOssConfig(**gpt_oss_120b_dict)
1174+
gpt_oss_120b_config = transformers.GptOssConfig(**gpt_oss_120b_dict) # pyrefly: ignore[bad-argument-type]
11751175

11761176

11771177
qwen3_omni_30b_a3b_config = transformers.Qwen3OmniMoeConfig(
@@ -1481,8 +1481,8 @@ def __init__(self, **kwargs):
14811481

14821482
try:
14831483
# Will execute successfully if Transformers is updated with Qwen3.5 support
1484-
qwen3_5_35b_a3b_config = transformers.Qwen3_5MoeConfig(**qwen3_5_35b_a3b_dict)
1485-
qwen3_5_397b_a17b_config = transformers.Qwen3_5MoeConfig(**qwen3_5_397b_a17b_dict)
1484+
qwen3_5_35b_a3b_config = transformers.Qwen3_5MoeConfig(**qwen3_5_35b_a3b_dict) # pyrefly: ignore[missing-attribute]
1485+
qwen3_5_397b_a17b_config = transformers.Qwen3_5MoeConfig(**qwen3_5_397b_a17b_dict) # pyrefly: ignore[missing-attribute]
14861486
except AttributeError:
14871487
qwen3_5_35b_a3b_config = PTConfig(**qwen3_5_35b_a3b_dict) # pytype: disable=wrong-arg-types
14881488
qwen3_5_397b_a17b_config = PTConfig(**qwen3_5_397b_a17b_dict) # pytype: disable=wrong-arg-types

src/maxtext/checkpoint_conversion/utils/param_mapping.py

Lines changed: 69 additions & 69 deletions
Large diffs are not rendered by default.

src/maxtext/inference/decode.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def main(argv: Sequence[str]) -> None:
139139

140140
if config.use_multimodal:
141141
tokens = mm_processor.prepare_text_for_image_fusion(tokens=tokens, config=config, processor_output=processor_outputs)
142-
true_length += image_offsets
142+
true_length += image_offsets # pyrefly: ignore[unbound-name]
143143

144144
if config.use_mrope:
145145
from maxtext.multimodal import processor_qwen3_omni # pylint: disable=import-outside-toplevel
@@ -181,13 +181,13 @@ def main(argv: Sequence[str]) -> None:
181181
prefill_result, first_token = engine.prefill(
182182
params=params,
183183
padded_tokens=tokens,
184-
positions=position_ids,
185-
mrope_deltas=mrope_position_deltas,
186-
images=processor_outputs.pixel_values if config.use_multimodal else None,
187-
image_masks=processor_outputs.pixel_mask if config.use_multimodal and "llama4" in config.model_name else None,
184+
positions=position_ids, # pyrefly: ignore[bad-argument-type]
185+
mrope_deltas=mrope_position_deltas, # pyrefly: ignore[bad-argument-type]
186+
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]
188188
videos=getattr(processor_outputs, "video_values", None) if config.use_multimodal else None,
189-
audio_values=processor_outputs.audio_values if config.use_audio else None,
190-
audio_masks=processor_outputs.audio_mask if config.use_audio else None,
189+
audio_values=processor_outputs.audio_values if config.use_audio else None, # pyrefly: ignore[bad-argument-type]
190+
audio_masks=processor_outputs.audio_mask if config.use_audio else None, # pyrefly: ignore[bad-argument-type]
191191
true_length=true_length,
192192
rng=rng_prefill,
193193
slot=i,

src/maxtext/inference/inference_microbenchmark.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,8 +400,8 @@ def run_benchmarks(config):
400400
config,
401401
multisampling_prefill_executable[prefill_length],
402402
params,
403-
prefill_tokens[prefill_length],
404-
prefill_true_lengths[prefill_length],
403+
prefill_tokens[prefill_length], # pyrefly: ignore[unbound-name]
404+
prefill_true_lengths[prefill_length], # pyrefly: ignore[unbound-name]
405405
benchmark_loop_iters,
406406
)
407407

src/maxtext/inference/kvcache.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ def __init__(
277277
*,
278278
# Not used in KVCache but passed in by nnx_wrappers.to_linen.
279279
# TODO: Remove when bridge no longer needed
280-
rngs: nnx.Rngs = None,
280+
rngs: nnx.Rngs = None, # pyrefly: ignore[bad-function-definition]
281281
):
282282
"""Initializes the KVCache module.
283283
@@ -612,8 +612,8 @@ def kv_cache_chunked_prefill(
612612
# For quantized kv cached. Could be get without transpose twice.
613613
cached_key = self.get_cached_values(cached_prefill_key_vars, key.dtype, self.prefill_cache_axis_order)
614614
cached_value = self.get_cached_values(cached_prefill_value_vars, value.dtype, self.prefill_cache_axis_order)
615-
cached_key_value = jnp.transpose(cached_key, self.prefill_cache_axis_order)
616-
cached_value_value = jnp.transpose(cached_value, self.prefill_cache_axis_order)
615+
cached_key_value = jnp.transpose(cached_key, self.prefill_cache_axis_order) # pyrefly: ignore[bad-argument-type]
616+
cached_value_value = jnp.transpose(cached_value, self.prefill_cache_axis_order) # pyrefly: ignore[bad-argument-type]
617617

618618
seq_axis = self.prefill_cache_logical_axis_names.index(CACHE_SEQUENCE)
619619
cache_seq_axis = self.prefill_cache_axis_order.index(seq_axis)
@@ -767,17 +767,17 @@ def update_ar_key_value(
767767
if use_ragged_attention:
768768
cache_locations = [slice(None)] * 4
769769
new_token_locations = [slice(None)] * 4
770-
new_token_locations[ar_cache_sequence_axis] = 0
770+
new_token_locations[ar_cache_sequence_axis] = 0 # pyrefly: ignore[unsupported-operation]
771771

772772
def key_body(i, val):
773773
cache_locations[ar_cache_batch_axis] = i
774-
cache_locations[ar_cache_sequence_axis] = lengths[i]
774+
cache_locations[ar_cache_sequence_axis] = lengths[i] # pyrefly: ignore[unsupported-operation]
775775
new_token_locations[ar_cache_batch_axis] = i
776776
return val.at[tuple(cache_locations)].set(one_token_key_shaped_for_cache[tuple(new_token_locations)])
777777

778778
def value_body(i, val):
779779
cache_locations[ar_cache_batch_axis] = i
780-
cache_locations[ar_cache_sequence_axis] = lengths[i]
780+
cache_locations[ar_cache_sequence_axis] = lengths[i] # pyrefly: ignore[unsupported-operation]
781781
new_token_locations[ar_cache_batch_axis] = i
782782
return val.at[tuple(cache_locations)].set(one_token_value_shaped_for_cache[tuple(new_token_locations)])
783783

@@ -815,15 +815,15 @@ def value_body(i, val):
815815
cached_key_scale.set_value(
816816
jax.lax.dynamic_update_index_in_dim(
817817
cached_key_scale.get_value(),
818-
one_token_key_scale_shaped_for_cache,
818+
one_token_key_scale_shaped_for_cache, # pyrefly: ignore[unbound-name]
819819
ar_cache_update_idx,
820820
ar_cache_scale_update_axis,
821821
)
822822
)
823823
cached_value_scale.set_value(
824824
jax.lax.dynamic_update_index_in_dim(
825825
cached_value_scale.get_value(),
826-
one_token_value_scale_shaped_for_cache,
826+
one_token_value_scale_shaped_for_cache, # pyrefly: ignore[unbound-name]
827827
ar_cache_update_idx,
828828
ar_cache_scale_update_axis,
829829
)
@@ -844,7 +844,7 @@ 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=[])
847+
cache_value = KVTensor(qvalue=cache_value, scale=[scale_value], scale_t=None, dequant_dtype=target_dtype, bias=[]) # pyrefly: ignore[unexpected-keyword]
848848
cache_value_in_logical_shape = jax.tree.map(lambda x: reverse_transpose(x, cache_axis_order), cache_value)
849849
return cache_value_in_logical_shape
850850

@@ -1061,7 +1061,7 @@ def __init__(
10611061
*,
10621062
# Not used in MlaKVCache but passed in by nnx_wrappers.to_linen.
10631063
# TODO: Remove when bridge no longer needed
1064-
rngs: nnx.Rngs = None,
1064+
rngs: nnx.Rngs = None, # pyrefly: ignore[bad-function-definition]
10651065
):
10661066
"""Initializes the MlaKVCache module.
10671067

src/maxtext/inference/maxengine/maxengine.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ def get_keys(self):
101101
_BaseEngine = engine_api.Engine if (not is_decoupled() and hasattr(engine_api, "Engine")) else object
102102

103103

104-
class MaxEngine(_BaseEngine):
104+
class MaxEngine(_BaseEngine): # pyrefly: ignore[invalid-inheritance]
105105
"""The computational core of the generative model server.
106106
107107
Engine defines an API that models must adhere to as they plug into the
@@ -192,7 +192,7 @@ def _nnx_init_cache_dict(self, mode: str = MODEL_MODE_PREFILL) -> dict:
192192
"""Zero-filled pure-dict cache matching the abstract NNX model."""
193193
src = self._abstract_model_for_mode(mode)
194194
_, cache_state, _ = nnx.split(src, nnx.Cache, ...)
195-
cache_dict = cache_state.to_pure_dict()
195+
cache_dict = cache_state.to_pure_dict() # pyrefly: ignore[missing-attribute]
196196
return jax.tree.map(lambda x: jnp.zeros(x.shape, x.dtype), cache_dict)
197197

198198
def _nnx_run_model(
@@ -219,7 +219,7 @@ 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)
222+
model = nnx.merge(self.graphdef, params, cache_state, self._nnx_rest_state, copy=True) # pyrefly: ignore[no-matching-overload]
223223
logits = model(
224224
decoder_input_tokens,
225225
decoder_positions,
@@ -280,7 +280,7 @@ def _layout(x, s, l):
280280
if x.format == l:
281281
return x
282282
# 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
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]
284284
f = jax.jit(self._identity, out_shardings=Format(dll, s)).lower(x).compile(compiler_options=xla_flags)
285285
y = f(x)
286286
# Achieves donation of the input argument, but allows for different memory
@@ -409,7 +409,7 @@ def _load_params_nnx(self, params, rng):
409409
with nn_partitioning.axis_rules(self.config.logical_axis_rules):
410410
full_sharding = sharding.nnx_construct_named_sharding(full_abs, self._mesh)
411411
concrete_model = maxtext_utils_nnx.create_nnx_sharded_model(
412-
self.model, self._create_model_fn, mesh=self._mesh, named_sharding=full_sharding
412+
self.model, self._create_model_fn, mesh=self._mesh, named_sharding=full_sharding # pyrefly: ignore[bad-argument-type]
413413
)
414414
graphdef, _, _, rest_state = nnx.split(concrete_model, nnx.Param, nnx.Cache, ...)
415415
self.graphdef = graphdef
@@ -435,16 +435,16 @@ def _load_params_nnx(self, params, rng):
435435
# PREFILL/AR attention ops have different cache variable shapes, and a
436436
# mismatch trips the `assert prefill_kv_cache` check inside attention_op.
437437
with nn_partitioning.axis_rules(self.config.logical_axis_rules):
438-
concrete_model = self._create_model_fn()
438+
concrete_model = self._create_model_fn() # pyrefly: ignore[not-callable]
439439
graphdef, _, _, rest_state = nnx.split(concrete_model, nnx.Param, nnx.Cache, ...)
440440
# Overlay loaded non-Param/non-Cache leaves (e.g. AQT qrhs.frozen) onto
441441
# the PREFILL-mode rest_state. The PREFILL concrete_model already has
442442
# placeholder qrhs vars at the right paths; we just swap in the loaded
443443
# values. Anything only in `loaded_rest_state` (e.g. AR-only RNG slots)
444444
# is ignored. We keep PREFILL rest_state as the base so RNG variables
445445
# match the PREFILL graphdef's expectations.
446-
loaded_rest_dict = loaded_rest_state.to_pure_dict()
447-
rest_dict = rest_state.to_pure_dict()
446+
loaded_rest_dict = loaded_rest_state.to_pure_dict() # pyrefly: ignore[missing-attribute]
447+
rest_dict = rest_state.to_pure_dict() # pyrefly: ignore[missing-attribute]
448448

449449
def _overlay(dst, src):
450450
if isinstance(dst, dict) and isinstance(src, dict):
@@ -768,7 +768,7 @@ def _prefill_jit(
768768
one_d_output = ones_to_keep * DECODING_ACTIVE_SEQUENCE_INDICATOR
769769
sequence_indicator = jnp.expand_dims(one_d_output, 0)
770770

771-
rng, new_rng = jax.random.split(rng)
771+
rng, new_rng = jax.random.split(rng) # pyrefly: ignore[bad-argument-type]
772772
if self.config.pure_nnx:
773773
# Prefill always operates on batch=1 (one padded prompt at a time).
774774
nnx_cache = (
@@ -1026,7 +1026,7 @@ def _prefill_multisampling_jit(
10261026
one_d_output = ones_to_keep * DECODING_ACTIVE_SEQUENCE_INDICATOR
10271027
sequence_indicator = jnp.expand_dims(one_d_output, 0)
10281028

1029-
rng, new_rng = jax.random.split(rng)
1029+
rng, new_rng = jax.random.split(rng) # pyrefly: ignore[bad-argument-type]
10301030
if self.config.pure_nnx:
10311031
# Prefill is batch=1 (one prompt); multi-sampling only draws several first
10321032
# tokens from the shared logits below. Mirror the _prefill_jit NNX branch.

src/maxtext/input_pipeline/grain_data_processing.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,9 +203,9 @@ def create_dataset_from_pattern(pattern):
203203
dataset = dataset.repeat(num_epoch)
204204
dataset = dataset[file_slice]
205205
if data_file_type == "tfrecord":
206-
dataset = dataset.map(input_pipeline_utils.make_tfrecord_iter_dataset)
206+
dataset = dataset.map(input_pipeline_utils.make_tfrecord_iter_dataset) # pyrefly: ignore[missing-attribute]
207207
else:
208-
dataset = dataset.map(grain.experimental.ParquetIterDataset)
208+
dataset = dataset.map(grain.experimental.ParquetIterDataset) # pyrefly: ignore[missing-attribute]
209209
cycle_length = min(files_per_host, grain_num_threads)
210210
dataset = grain.experimental.InterleaveIterDataset(dataset, cycle_length=cycle_length)
211211
if row_shard is not None:

src/maxtext/input_pipeline/grain_tokenizer.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ 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):
74+
for feature_name, max_length in zip(self.feature_names, self.sequence_length, strict=True): # pyrefly: ignore[bad-argument-type]
7575
text = element[feature_name]
7676
token_ids = self._encode(text)[:max_length]
7777
element[feature_name] = np.asarray(token_ids, dtype=np.int32)
@@ -88,9 +88,9 @@ def __post_init__(self):
8888
super().__post_init__()
8989
# TokenizeAndChunk only supports single feature for chunking
9090
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"
91+
assert len(self.sequence_length) == 1, "TokenizeAndChunk only supports single sequence length" # pyrefly: ignore[bad-argument-type]
9292
self.feature_name = self.feature_names[0] # For backward compatibility
93-
self.sequence_length = self.sequence_length[0] # Convert back to int for chunking
93+
self.sequence_length = self.sequence_length[0] # Convert back to int for chunking # pyrefly: ignore[bad-index]
9494

9595
def flat_map(self, element: dict[str, Any]) -> list[dict[str, Any]]:
9696
"""Tokenize and chunk text into multiple examples of sequence length."""
@@ -103,8 +103,8 @@ def flat_map(self, element: dict[str, Any]) -> list[dict[str, Any]]:
103103
return []
104104

105105
output_elements = []
106-
for start_idx in range(0, len(token_ids), chunk_size):
107-
chunk = np.asarray(token_ids[start_idx : start_idx + chunk_size], dtype=np.int32)
106+
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]
108108
new_element = {self.feature_name: chunk}
109109
output_elements.append(new_element)
110110

0 commit comments

Comments
 (0)