Repository navigation
Keep tokenizers loading when the Hub rate limits the Mistral tag lookup - #18662
Merged
Merged
Conversation
Below transformers 5.6.0 every tokenizer with a vocab over 100k loaded by repo id calls an anonymous model_info to check for a Mistral base, with no error handling, so a 429 (common on shared Colab and Kaggle IPs) fails from_pretrained even with every file cached. Back-port the 5.6.0 guard: a failure inside that lookup means not Mistral; any other error still raises. No-op on 5.6.0+.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Member
Author
|
@codex review |
1 similar comment
Member
Author
|
@codex review |
|
Codex Review: Didn't find any major issues. Bravo. Reviewed commit: ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
If Codex has suggestions, it will comment; otherwise it will react with 👍. Codex can also answer questions or update the PR. Try commenting "@codex address that feedback". |
This was referenced Nov 20, 2026
danielhanchen
added a commit
that referenced
this pull request
Nov 20, 2026
…aseline (#18677) ## Summary `Source lint (Python + shell + YAML + JSON + safety nets)` is red on `main` (seen on #18675, reproduced on current `main`). Its blocking step is `No new risky loader call sites`: ``` 1 risky loader call site(s) not in the baseline: unsloth/import_fixes.py:1135 [dynamic-import] import_module ``` ## Cause #18662 (keep tokenizers loading when the Hub rate limits the Mistral tag lookup) adds `fix_transformers_mistral_regex_hub_error`. It calls `importlib.import_module(module_name)` over a fixed literal tuple: - `transformers.tokenization_utils_base` - `transformers.tokenization_utils_tokenizers` The call has the same shape as the four already-reviewed `import_module(module_name)` sites in `import_fixes.py`, so it lands in their baseline group (digest `59e72c01edb14c86`) as a fifth instance. The gate reports one site over the recorded count; the line it names (1135) is simply the last one it counts. The new call is safe: the module names are written out in the source. The baseline just was not updated. ## Change `scripts/risky_loaders_baseline.json`, regenerated with `python scripts/lint_risky_loaders.py --update`: - the group's count goes from 4 to 5; - its reason now also names the two literal tokenizer owners of `_patch_mistral_regex`. No other entry changes. ## Testing - `python scripts/lint_risky_loaders.py`: exits 1 on `main` with the message above; with this change, `ok: 122 risky loader call site(s), all recorded`. - `python scripts/lint_risky_loaders.py --self-test`: ok. - `tests/security/test_lint_risky_loaders.py`: 46 passed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem: On transformers 4.57.x through 5.5.4, loading any tokenizer with a vocab over 100k by repo id (Qwen3, Llama 3, Gemma, and so on) makes an anonymous
model_infocall to read the repo's tags and spot a Mistral base. That call has no error handling, so a single 429 failsfrom_pretrainedeven when every tokenizer file is already cached. Anonymous users on shared IPs (Colab, Kaggle, CI runners) are the ones who hit this: the anonymous API limit is 500 calls per 5 minutes per IP. On transformers 5.x the 429 also surfaces as a misleadingOSError: Unable to load vocabulary from file.transformers 5.6.0 fixed it upstream by treating a failed lookup as "not Mistral".
Fix:
fix_transformers_mistral_regex_hub_errorinimport_fixes.pyback-ports that guard. It wraps_patch_mistral_regexonPreTrainedTokenizerBase(4.57.x) orTokenizersBackend(5.0 to 5.5). An exception raised inside theis_base_mistraltag lookup returns the tokenizer unchanged, exactly as 5.6.0 does; any other error still raises. It is applied only when the installedis_base_mistralhas notry:, so it does nothing on 5.6.0 and later, and applying it twice wraps once.Testing
Warm-cache
AutoTokenizer.from_pretrained("trl-internal-testing/tiny-Qwen3ForCausalLM")with the tag lookup answering 429:HfHubHTTPError: 429 Client Error: Too Many RequestsOSError: Unable to load vocabulary from fileOSError: Unable to load vocabulary from filetests/test_mistral_regex_hub_guard.py(new, 4 tests): a 429 in the lookup keeps the tokenizer, unguarded transformers fails the load, an error outside the lookup still raises, and the fix is idempotent. Run againstmain'simport_fixes.py(UNSLOTH_IMPORT_FIXES), the 429 test fails.tests/test_transformers_security_fixes.pystill passes (34 passed together).