Skip to content

Fix NewlineTokenizer registration for transformers >= 5.13#1465

Open
chandukona wants to merge 1 commit into
ml-explore:mainfrom
chandukona:fix-tokenizer-quotes
Open

Fix NewlineTokenizer registration for transformers >= 5.13#1465
chandukona wants to merge 1 commit into
ml-explore:mainfrom
chandukona:fix-tokenizer-quotes

Conversation

@chandukona

@chandukona chandukona commented Jul 4, 2026

Copy link
Copy Markdown

Fixes #1458

transformers 5.13.0 added an unguarded key.__module__.startswith("transformers.") check in _LazyAutoMapping.register, so registering a tokenizer with a string key now raises AttributeError: 'str' object has no attribute '__module__' at import time. mlx-lm registered NewlineTokenizer under the string "NewlineTokenizer", which older transformers versions tolerated because the key was never dereferenced.

This PR passes the class itself as the registration key instead. Classes have __module__, so registration succeeds on 5.13, and nothing else changes: name-based lookup (tokenizer_class_from_name) resolves "NewlineTokenizer" through REGISTERED_TOKENIZER_CLASSES, which is keyed by the tokenizer's __name__ regardless of the mapping key — so model repos with "tokenizer_class": "NewlineTokenizer" in their tokenizer_config.json load exactly as before.

Tested with transformers 5.13.0 and 5.7.0 (the minimum pinned version): import mlx_lm succeeds on both, and tokenizer_class_from_name("NewlineTokenizer") returns the class.

If you'd prefer registering with a PreTrainedConfig subclass per the documented signature, happy to update — this version just keeps the diff to one line.

@chandukona chandukona changed the title Fix syntax error with NewLineTokenizer string wrapper Fix NewlineTokenizer registration for transformers >= 5.13 Jul 4, 2026
youssofal added a commit to youssofal/MTPLX that referenced this pull request Jul 7, 2026
…ery fresh install at model load (#136, #135)

transformers 5.13.0 changed AutoTokenizer.register to require a config
class as the key; mlx-lm 0.31.x registers by name ("NewlineTokenizer"),
so `import mlx_lm` raises AttributeError('str' has no '__module__')
before any model can load. Every venv resolved after 5.13.0 shipped is
dead on arrival — three independent reporters in 24h (#136 + 2 dupes,
#135 is timing-consistent), and we hit the identical crash ourselves on
2026-07-03 and pinned the local venv manually (this makes the fix
survive the app's fingerprint force-reinstall, which the manual pin did
not). Marker-gated like the sibling mlx pins.

Same content as PR #137 by @davidtai (verified: bisect 5.12.1 good /
5.13.0 bad matches our own finding). Wheel metadata verified:
Requires-Dist: transformers<5.13 present in the built wheel.

Drop the cap once mlx-lm registers the 5.13-compatible way
(ml-explore/mlx-lm#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.

transformers==5.13.0 breaks mlx-lm / mlx-vlm imports due to string auto-registration

1 participant