Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cd9019c
Initial plugin design
michalk8 Nov 19, 2026
cb81479
Clean-up README.md, better structure
michalk8 Nov 19, 2026
2c230a9
More tests, fix no preprocessor
michalk8 Nov 19, 2026
ce88ee3
Load first built-in, then extra, check for metadata errors
michalk8 Nov 20, 2026
b2b9e7c
Move to a plugin/ directory
michalk8 Nov 20, 2026
548f0a8
Better error messages
michalk8 Nov 20, 2026
3113601
Prune readme.md, add experimental note
michalk8 Nov 20, 2026
db32212
Expose think start/end in tokenizer wrapper
michalk8 Nov 20, 2026
8996170
Better processor handling
michalk8 Nov 20, 2026
635c623
Clean-up code, tests
michalk8 Nov 20, 2026
5d01b37
Rename `Kind` -> `PluginKind`
michalk8 Nov 20, 2026
9523296
Folder without __init__
michalk8 Nov 20, 2026
9c0034e
Better error message when duplicates are found
michalk8 Nov 20, 2026
873c4eb
Take think start/end tokens only from 1 source
michalk8 Nov 20, 2026
dd77093
Fix arch remapping
michalk8 Nov 23, 2026
e1053ca
Make MODEL_REMAPPING, etc. again a plain dict + re-export
michalk8 Nov 23, 2026
a46743b
Simplify load processor
michalk8 Nov 23, 2026
b75b550
Improve typing/docstrings
michalk8 Nov 23, 2026
44cff9b
Redesign
michalk8 Nov 23, 2026
4713ec3
model_args
michalk8 Nov 24, 2026
d3409aa
Simplify the code
michalk8 Nov 24, 2026
56bd0b4
Prune comments/docs
michalk8 Nov 24, 2026
41bdde0
Update readme
michalk8 Nov 24, 2026
9073bff
Simplify check
michalk8 Nov 24, 2026
7ca480f
Prune readme some more
michalk8 Nov 24, 2026
bb8f038
Plugin list/check
michalk8 Nov 24, 2026
2d1e197
Clean-up plugins
michalk8 Nov 24, 2026
3a5ca0b
Update README.md
michalk8 Nov 24, 2026
d01451d
More tests
michalk8 Nov 24, 2026
2ff3efd
Clean-up plugin code
michalk8 Nov 24, 2026
594b8c6
Use `mlx_lm plugin list`
michalk8 Nov 24, 2026
89e41b1
Simplify the API
michalk8 Nov 24, 2026
17342d8
Drop the enum
michalk8 Nov 24, 2026
d904fb2
List plugins, move to_json
michalk8 Nov 24, 2026
db8dfa9
Rename to registry
michalk8 Nov 24, 2026
2ed0238
Use any for a builtin
michalk8 Nov 24, 2026
d4a6ec1
Make some methods private
michalk8 Nov 24, 2026
c526dbe
or "" for sorting (no Name in metadata)
michalk8 Nov 24, 2026
28b7c21
Helper fn to load tool parser
michalk8 Nov 24, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Folder without __init__
  • Loading branch information
michalk8 committed Nov 24, 2026
commit 95232965fb02eea91668ef14396a51fb6fb8c5c7
17 changes: 10 additions & 7 deletions mlx_lm/plugins/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@ def module_name(kind: PluginKind, name: str) -> str:
raise ValueError(f"{name!r} is not a valid identifier.")

builtin = f"mlx_lm.{kind}.{name}"
# Built-ins never read other packages' metadata.
if importlib.util.find_spec(builtin) is not None:
# Built-ins never read other packages' metadata. Namespace folders have no origin.
spec = importlib.util.find_spec(builtin)
if spec is not None and spec.origin is not None:
return builtin

group = f"mlx_lm.{kind}"
Expand Down Expand Up @@ -52,16 +53,18 @@ def _plugin_module(group: str, found: list[EntryPoint]) -> str:
f"{len(found)} projects give {ep.name} in {group}, for example "
f"{ep.dist.name} and {rest[0].dist.name}."
)
if ep.attr is not None:
match = ep.pattern.match(ep.value)
if match is None or match["attr"] is not None:
raise ValueError(
f"The entry point {ep.name} in {group} of {ep.dist.name} must be a "
f"module, not {ep.value}."
f"module, not {ep.value!r}."
)
if not _exists(ep.module):
module = match["module"]
if not _exists(module):
raise ValueError(
f"{ep.dist.name} gives {ep.name} in {group}, but {ep.module} does not exist."
f"{ep.dist.name} gives {ep.name} in {group}, but {module} does not exist."
)
return ep.module
return module


def _exists(module: str) -> bool:
Expand Down
5 changes: 4 additions & 1 deletion mlx_lm/processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ def load_processor(config: dict[str, Any]) -> Processor | None:
"""The processor of the model of a configuration, or None if it takes only text."""
if not any(config.get(key) for key in ENCODER_CONFIGS):
return None
package = model_package(config)
try:
package = model_package(config)
except ValueError:
return None
# Imported here: the package holds the whole model.
module = importlib.import_module(package)
# A plug-in model can be a single module, without a processor.
Expand Down
25 changes: 20 additions & 5 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import tempfile
import unittest
from pathlib import Path
from unittest import mock

from mlx_lm import plugins, utils
from mlx_lm import models, plugins, utils
from mlx_lm.plugins import discovery
from mlx_lm.processors import load_processor

Expand Down Expand Up @@ -100,6 +101,14 @@ def test_broken_package_does_not_break_builtins(self):
package = utils.model_package({"model_type": "llama"})
self.assertEqual(package, "mlx_lm.models.llama")

def test_folder_without_init_is_not_a_builtin(self):
# Left behind by a branch switch.
leftover = Path(self.root.name) / "leftover"
(leftover / "test" / "__pycache__").mkdir(parents=True)
path = [*models.__path__, str(leftover)]
with mock.patch.object(models, "__path__", path):
self.assertEqual(utils.model_package(TEST), "test_lm.models.test")

def test_unknown_model(self):
with self.assertRaises(ValueError):
utils.model_package({"model_type": "unknown"})
Expand All @@ -118,10 +127,12 @@ def test_entry_point_with_extras(self):
self.assertEqual(package, "test_lm.solo")

def test_entry_point_must_be_a_module(self):
entry_points = {"mlx_lm.models": {"other": "other_lm.test:Model"}}
self.install("other-lm", entry_points, {})
with self.assertRaises(ValueError):
utils.model_package({"model_type": "other"})
values = ("other_lm.test:Model", "other_lm.test:", "other-lm.test")
entry_points = {f"bad{i}": value for i, value in enumerate(values)}
self.install("other-lm", {"mlx_lm.models": entry_points}, {})
for model_type in entry_points:
with self.assertRaisesRegex(ValueError, "of other-lm must be a module"):
utils.model_package({"model_type": model_type})

def test_entry_point_to_missing_module(self):
for model_type in ("ghost", "orphan"):
Expand Down Expand Up @@ -150,6 +161,10 @@ def test_module_without_processor(self):
config = {"model_type": "solo", "vision_config": {"patch_size": 16}}
self.assertIsNone(load_processor(config))

def test_unknown_model_has_no_processor(self):
config = {"model_type": "unknown", "vision_config": {"patch_size": 16}}
self.assertIsNone(load_processor(config))

def test_tokenizer_defaults_follow_the_given_config(self):
with tempfile.TemporaryDirectory() as path:
(Path(path) / "config.json").write_text('{"model_type": "llama"}')
Expand Down