Skip to content

Download tokenizers from GCS in unit tests instead of HF - #4752

Open
igorts-git wants to merge 1 commit into
mainfrom
igorts/tokenizer-assets
Open

Download tokenizers from GCS in unit tests instead of HF#4752
igorts-git wants to merge 1 commit into
mainfrom
igorts/tokenizer-assets

Conversation

@igorts-git

@igorts-git igorts-git commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Description

This PR refactors unit and integration tests to dynamically pull required tokenizers from gs://maxtext-dataset/hf/ into local assets on demand during test setup.

This helps avoid downloads from HuggingFace. Unfortunately, we cannot simply put these tokenizers in our assets directory because their license is not Apache 2.0.

The new helper function test_helpers.ensure_tokenizer_downloaded has a skip_test_on_failure parameter that allows us to skip the test if copying of the tokenizer from the GS bucket fails.

Additionally, this PR fixes repository root detection in src/maxtext/utils/globals.py when running inside Git worktrees.

Tests

CI tests

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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a helper function ensure_tokenizer_downloaded to standardize tokenizer downloads from GCS across integration and unit tests, replacing inline subprocess calls. It also updates repository root detection to support Git worktrees. The review feedback identifies critical issues where the newly introduced qwen3-tokenizer is used in several test classes within sft_data_processing_test.py but is never downloaded in their setUpClass methods, which will cause test failures. Additionally, the ensure_tokenizer_downloaded helper function ignores the custom target_path argument during the download process, hardcoding the destination directory instead.

Comment thread tests/post_training/unit/sft_data_processing_test.py
Comment thread tests/post_training/unit/sft_data_processing_test.py
Comment thread tests/post_training/unit/sft_data_processing_test.py
Comment thread tests/utils/test_helpers.py Outdated
@igorts-git
igorts-git force-pushed the igorts/tokenizer-assets branch from ec2d8ab to 742dac0 Compare August 7, 2026 16:33
…e root detection

- Add ensure_tokenizer_downloaded helper in tests/utils/test_helpers.py to fetch tokenizers from gs://maxtext-dataset/hf/ at runtime if missing or empty, with automatic cleanup on download failure and filelock support.
- Update tests (sft_data_processing_test, distillation_data_processing_test, sft_trainer_correctness_test, grpo_trainer_correctness_test, grpo_correctness, tokenizer_test) to use ensure_tokenizer_downloaded.
- Update src/maxtext/utils/globals.py .git check using os.path.exists to support Git worktrees.
@igorts-git
igorts-git force-pushed the igorts/tokenizer-assets branch from 742dac0 to 192b0f2 Compare August 7, 2026 16:46
@codecov

codecov Bot commented Aug 7, 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants