|
78 | 78 | import jax |
79 | 79 | import jax.numpy as jnp |
80 | 80 | from maxtext.configs import pyconfig |
81 | | -from maxtext.utils.globals import MAXTEXT_TEST_ASSETS_ROOT |
| 81 | +from maxtext.utils.globals import MAXTEXT_TEST_ASSETS_ROOT, HF_IDS |
82 | 82 | from maxtext.checkpoint_conversion.utils.hf_utils import convert_jax_weight_to_torch |
83 | 83 | from maxtext.common.common_types import DECODING_ACTIVE_SEQUENCE_INDICATOR, MODEL_MODE_TRAIN |
84 | 84 | from maxtext.layers import quantizations |
@@ -232,13 +232,13 @@ def check_kl_divergence(model_logits, golden_logits, atol=0.02, clip_logits_epsi |
232 | 232 |
|
233 | 233 | def get_data(golden_data_point, config): |
234 | 234 | """Get the golden data for the test indexed at golden_data_index""" |
| 235 | + model_prefix = config.model_name.split("-")[0] |
235 | 236 |
|
236 | 237 | max_logging.log(f"config.global_batch_size_to_train_on={config.global_batch_size_to_train_on}") |
237 | 238 | if config.use_multimodal: |
238 | 239 | assert "pixel_values" in golden_data_point, "no image found in golden data while use_multimodal=True" |
239 | 240 | pixel_values = np.asarray(golden_data_point["pixel_values"], dtype=np.float32) |
240 | 241 | max_logging.log(f"pixel_values.shape = {pixel_values.shape}") |
241 | | - model_prefix = config.model_name.split("-")[0] |
242 | 242 | # Gemma3 and Gemma4 models expect (num_images, height, width, channels) |
243 | 243 | if model_prefix in ["gemma3", "gemma4"]: |
244 | 244 | if pixel_values.ndim == 2: |
@@ -328,22 +328,28 @@ def main(config, test_args): # pylint: disable=W0621 |
328 | 328 | # 1. Pre-loaded golden logits comparison (multimodal input) |
329 | 329 | # 2. On-the-fly HuggingFace model comparison (text only input) |
330 | 330 | hf_token = config.hf_access_token |
331 | | - try: |
332 | | - if test_args.hf_model_path: |
333 | | - max_logging.log(f"Loading tokenizer from {test_args.hf_model_path}.") |
334 | | - tokenizer = AutoTokenizer.from_pretrained( |
335 | | - test_args.hf_model_path, token=hf_token, trust_remote_code=test_args.trust_remote_code |
336 | | - ) |
337 | | - else: |
338 | | - max_logging.log(f"Loading tokenizer from {config.tokenizer_path}.") |
339 | | - tokenizer = AutoTokenizer.from_pretrained( |
340 | | - config.tokenizer_path, token=hf_token, trust_remote_code=test_args.trust_remote_code |
341 | | - ) |
342 | | - except Exception as e: # pylint: disable=broad-except |
343 | | - max_logging.log(f"Tokenizer loading error: {e}.\nLoading tokenizer from {config.tokenizer_path}.") |
344 | | - tokenizer = AutoTokenizer.from_pretrained( |
345 | | - config.tokenizer_path, token=hf_token, trust_remote_code=test_args.trust_remote_code |
346 | | - ) |
| 331 | + tokenizer_load_paths = [] |
| 332 | + if test_args.hf_model_path: |
| 333 | + tokenizer_load_paths.append(test_args.hf_model_path) |
| 334 | + tokenizer_load_paths.append(config.tokenizer_path) |
| 335 | + |
| 336 | + hf_model_id = HF_IDS.get(config.model_name) |
| 337 | + if hf_model_id: |
| 338 | + tokenizer_load_paths.append(hf_model_id) |
| 339 | + |
| 340 | + tokenizer = None |
| 341 | + last_exception = None |
| 342 | + for path in tokenizer_load_paths: |
| 343 | + try: |
| 344 | + max_logging.log(f"Loading tokenizer from {path}.") |
| 345 | + tokenizer = AutoTokenizer.from_pretrained(path, token=hf_token, trust_remote_code=test_args.trust_remote_code) |
| 346 | + break |
| 347 | + except Exception as e: # pylint: disable=broad-except,broad-exception-caught |
| 348 | + last_exception = e |
| 349 | + max_logging.log(f"Failed to load tokenizer from {path}: {e}") |
| 350 | + |
| 351 | + if tokenizer is None: |
| 352 | + raise last_exception |
347 | 353 |
|
348 | 354 | if config.model_name.startswith(("llama3.1", "mixtral")): |
349 | 355 | tokenizer.pad_token = tokenizer.eos_token |
|
0 commit comments