Skip to content

Fix import crash with transformers >= 5.13#1460

Open
Lazarus-931 wants to merge 1 commit into
ml-explore:mainfrom
Lazarus-931:fix-transformers-5.13-tokenizer-register
Open

Fix import crash with transformers >= 5.13#1460
Lazarus-931 wants to merge 1 commit into
ml-explore:mainfrom
Lazarus-931:fix-transformers-5.13-tokenizer-register

Conversation

@Lazarus-931

Copy link
Copy Markdown

On the newest transformers (5.13.0), just running import mlx_lm crashes:

AttributeError: 'str' object has no attribute '__module__'

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:

AutoTokenizer.register("NewlineTokenizer", fast_tokenizer_class=NewlineTokenizer)

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:

try:
    AutoTokenizer.register("NewlineTokenizer", fast_tokenizer_class=NewlineTokenizer)
except (AttributeError, TypeError):
    pass

All tests pass

`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>
@Lazarus-931

Copy link
Copy Markdown
Author

note #1459 already opened for same issue, will keep this open just incase

@menisadi

menisadi commented Jul 6, 2026

Copy link
Copy Markdown

@Lazarus-931 also #1465

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