Fix import crash with transformers >= 5.13#1460
Open
Lazarus-931 wants to merge 1 commit into
Open
Conversation
`AutoTokenizer.register()` is called with the string "NewlineTokenizer" as its first (config-class) argument. transformers 5.13 added an unguarded `key.__module__` access in `_LazyAutoMapping.register`, which raises `AttributeError: 'str' object has no attribute '__module__'` on a non-class key and aborts `import mlx_lm`. The name lookup mlx-lm relies on (`REGISTERED_TOKENIZER_CLASSES`, used to resolve models whose tokenizer_config sets tokenizer_class="NewlineTokenizer") is populated before the failing step, so wrap the call to tolerate the new strictness. Verified `import mlx_lm` on transformers 5.13.0 and 5.12.1, with NewlineTokenizer still resolvable by name. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Author
|
note #1459 already opened for same issue, will keep this open just incase |
|
@Lazarus-931 also #1465 |
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.
On the newest transformers (5.13.0), just running import mlx_lm crashes:
Since it fails on import, nothing in mlx-lm works — and any project that depends on mlx-lm breaks too.
mlx-lm registers its custom NewlineTokenizer like this:
That first argument is supposed to be a class, but we pass a plain text name ("NewlineTokenizer"). Older transformers didn't care. transformers 5.13 now assumes it's a class and tries to read .module off it, leading to the error.
Fix: Wrap the call so that extra step failing can't take down the whole import:
All tests pass