Skip to content

Cap transformers <5.13 to keep mlx-lm importable on macOS (v0.3.19)#316

Merged
codelion merged 1 commit into
mainfrom
fix/transformers-cap-mlx
Jul 5, 2026
Merged

Cap transformers <5.13 to keep mlx-lm importable on macOS (v0.3.19)#316
codelion merged 1 commit into
mainfrom
fix/transformers-cap-mlx

Conversation

@codelion

@codelion codelion commented Jul 5, 2026

Copy link
Copy Markdown
Member

Problem

On Apple silicon, import optillm crashes with:

AttributeError: 'str' object has no attribute '__module__'
  at transformers/models/auto/auto_factory.py:680 in register()

Root cause: transformers 5.13.0 tightened AutoTokenizer.register() to require a class (it does key.__module__). mlx-lm 0.31.3 (latest) registers a custom tokenizer by string name:

# mlx_lm/tokenizer_utils.py:505
AutoTokenizer.register("NewlineTokenizer", fast_tokenizer_class=NewlineTokenizer)

transformers ≤5.12.1 tolerated the string; 5.13.0 raises. Since optillm declares transformers>=5.0.0 with no ceiling, a fresh install pulls 5.13.0.

macOS-only: optillm installs mlx-lm only under platform_machine=="arm64" and sys_platform=="darwin". Linux CI never installs mlx-lm, so it silently ran 5.13.0 fine — which is why CI stayed green while local Mac installs broke.

Fix

Pin transformers>=5.0.0,<5.13.0 (resolves to 5.12.1). Verified: mlx-lm then imports cleanly.

The transformers 5.13.0 HF path itself is fine — I confirmed dhara-250m loads and generates on 5.13.0. The incompatibility is purely mlx-lm's; lift the cap once mlx-lm ships a 5.13-compatible release.

Testing

  • Reproduced the crash with transformers==5.13.0 + mlx-lm in a clean venv.
  • Verified transformers>=5.0.0,<5.13.0 resolves to 5.12.1 and import mlx_lm succeeds.
  • Confirmed the dhara HF path (tokenizer + generate) works on both 5.12.1 and 5.13.0.

transformers 5.13.0 tightened AutoModel/AutoTokenizer.register() to require a
class (it does key.__module__). mlx-lm 0.31.3 registers a custom tokenizer by
string name (tokenizer_utils.py: AutoTokenizer.register("NewlineTokenizer", ...)),
so `import mlx_lm` — and therefore `import optillm` — crashes with
"AttributeError: 'str' object has no attribute '__module__'".

This only affects Apple silicon, where optillm installs mlx-lm
(platform_machine=="arm64" and sys_platform=="darwin"); Linux CI never installs
mlx-lm so it was unaffected. The transformers 5.13.0 HF path itself is fine
(dhara loads and generates); the incompatibility is purely mlx-lm's.

Pin transformers>=5.0.0,<5.13.0 (resolves to 5.12.1) until mlx-lm ships a
transformers-5.13-compatible release, then lift the cap.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@codelion codelion merged commit 6a0200c into main Jul 5, 2026
6 checks passed
@codelion codelion deleted the fix/transformers-cap-mlx branch July 5, 2026 02:18
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.

1 participant