Skip to content

fix(testing): resolve tokenizer loading error and UnboundLocalError in logit checker#4438

Open
chiajunglien wants to merge 3 commits into
AI-Hypercomputer:mainfrom
CIeNET-International:emma/fix-mistral-8x7b-e2e
Open

fix(testing): resolve tokenizer loading error and UnboundLocalError in logit checker#4438
chiajunglien wants to merge 3 commits into
AI-Hypercomputer:mainfrom
CIeNET-International:emma/fix-mistral-8x7b-e2e

Conversation

@chiajunglien

@chiajunglien chiajunglien commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

This PR fixes two regression bugs that cause the mistral-7bnightly E2E test to crash in forward_pass_logit_checker.py:

DAG Error Log

  1. UnicodeDecodeError / OSError during tokenizer loading when reading local binary SentencePiece .model files.
  2. UnboundLocalError due to model_prefix being referenced outside its defined conditional block for text-only models.

Changes

  1. Added mistral-7b Online ID Mapping
  • File Modified: src/maxtext/utils/globals.py
  • Details: Added "mistral-7b": "mistralai/Mistral-7B-v0.1" to the HF_IDS dictionary. This enables the logit checker to fall back to the correct online Hugging Face repository if local loading fails.
  1. Implemented Robust Tokenizer Loading Fallback (Fixes Unicode Crash)
  • File Modified: tests/utils/forward_pass_logit_checker.py
  • Details:
    1. Imported HF_IDS from globals.py.
    2. Enhanced the tokenizer loading logic in main(): If loading from the local config.tokenizer_path fails (which occurs because tokenizer.mistral-v1 is a binary SentencePiece .model file instead of JSON), the script now catches the exception and falls back to loading the mapped Hugging Face ID from HF_IDS.
  1. Fixed model_prefix Variable Scope (Fixes UnboundLocalError Crash)
  • File Modified: tests/utils/forward_pass_logit_checker.py
  • Details:
    1. Moved the initialization of model_prefix from inside the if config.use_multimodal: block to the very top of get_data().
    2. This ensures model_prefix is always defined, preventing text-only models (like mistral-7b) from crashing when the script checks the Qwen3 RoPE 3D position ID logic.

Tests

  1. Ran pytest tests/unit/configs_test.py locally: All 76 tests passed successfully.
python3 -m tests.utils.forward_pass_logit_checker \
    src/maxtext/configs/base.yml \
    base_output_directory=gs://runner-maxtext-logs/2026-07-12 \
    load_parameters_path=gs://runner-maxtext-logs/2026-07-12/7b/scanned_ckpt/0/items \
    run_name=matmul_forward_pass_test \
    per_device_batch_size=1 \
    model_name=mistral-7b \
    tokenizer_path=/deps/src/maxtext/assets/tokenizer.mistral-v1 \
    max_prefill_predict_length=11 \
    max_target_length=11 \
    dataset_type=synthetic \
    dtype=float32 \
    megablox=False \
    sparse_matmul=False \
    --atol=3 \
    --rtol=1 \
    --token_size=4

Log: https://paste.googleplex.com/4641417803726848

Checklist

Before submitting this PR, please make sure (put X in square brackets):

  • I have performed a self-review of my code. For an optional AI review, add the gemini-review label.
  • I have necessary comments in my code, particularly in hard-to-understand areas.
  • I have run end-to-end tests tests and provided workload links above if applicable.
  • I have made or will make corresponding changes to the doc if needed, including adding new documentation pages to the relevant Table of Contents (toctree directive) as explained in our documentation.

@chiajunglien chiajunglien force-pushed the emma/fix-mistral-8x7b-e2e branch from c726d4e to 4713810 Compare July 13, 2026 08:25
Comment thread src/maxtext/utils/globals.py Outdated
Comment thread tests/utils/forward_pass_logit_checker.py
Comment thread tests/utils/forward_pass_logit_checker.py Outdated
@codecov

codecov Bot commented Jul 14, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants