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
Prune comments/docs
  • Loading branch information
michalk8 committed Nov 24, 2026
commit 56bd0b440b08b78fb37d58b2da3d45550e0fa972
9 changes: 4 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,10 @@ that package in `MODEL_REMAPPING` in `mlx_lm/models/__init__.py`.

A package has `__init__.py` (exporting `Model` and `ModelArgs`), `config.py`
(`ModelArgs`) and `model.py` (`Model`, with `model_args = ModelArgs` in the class
body). Optionally, `layers.py` has the blocks,
`checkpoint.py` the `sanitize` that converts checkpoint weights, `kernels.py` the
Metal kernels only this model uses, and `processor.py` and `vision.py` the
processor and the vision encoder of a model that takes images. Reuse the shared
code in
body). Optionally, `layers.py` has the blocks, `checkpoint.py` the `sanitize`
that converts checkpoint weights, `kernels.py` the Metal kernels only this model
uses, and `processor.py` and `vision.py` the processor and the vision encoder of
a model that takes images. Reuse the shared code in
[`mlx_lm/layers`](https://github.com/ml-explore/mlx-lm/tree/main/mlx_lm/layers)
and [`mlx_lm/kernels`](https://github.com/ml-explore/mlx-lm/tree/main/mlx_lm/kernels).

Expand Down
20 changes: 11 additions & 9 deletions mlx_lm/plugins/discovery.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ def load_model_class(name: str) -> type[nn.Module]:

ep = _entry_point("mlx_lm.models", name)
model = ep.load()

if not (isinstance(model, type) and issubclass(model, nn.Module)):
raise ValueError(
f"{ep.value} from {ep.dist.name} is not an nn.Module subclass."
)
if not callable(getattr(getattr(model, "model_args", None), "from_dict", None)):
model_args = getattr(model, "model_args", None)
if not hasattr(model_args, "from_dict"):
raise ValueError(
f"{ep.value} from {ep.dist.name} has no model_args with from_dict."
)
Expand All @@ -35,29 +37,34 @@ def load_model_class(name: str) -> type[nn.Module]:
def load_tool_parser(name: str) -> Any:
"""The tool parser for ``name``; ValueError if none or invalid."""
name = lookup_name(name)
# Built-ins come first and never read package metadata.
module = import_if_exists(f"mlx_lm.tool_parsers.{name}")
if module is not None:
return module

ep = _entry_point("mlx_lm.tool_parsers", name)
parser = ep.load()

start = getattr(parser, "tool_call_start", None)
end = getattr(parser, "tool_call_end", None)
is_parser = (
is_valid_parser = (
isinstance(start, str)
and start != ""
and isinstance(end, str)
and callable(getattr(parser, "parse_tool_call", None))
)
if not is_parser:
if not is_valid_parser:
raise ValueError(
f"{ep.value} from {ep.dist.name} is not a tool parser "
"(tool_call_start, tool_call_end, parse_tool_call)."
)
return parser


def lookup_name(name: str) -> str:
"""``name`` in lower case, with ``_`` for ``-``."""
return name.lower().replace("-", "_")


def import_if_exists(module: str) -> ModuleType | None:
"""The module, or None if there is none. Its parent package must exist."""
spec = importlib.util.find_spec(module)
Expand All @@ -67,11 +74,6 @@ def import_if_exists(module: str) -> ModuleType | None:
return importlib.import_module(module)


def lookup_name(name: str) -> str:
"""``name`` in lower case, with ``_`` for ``-``."""
return name.lower().replace("-", "_")


def _entry_point(group: str, name: str) -> EntryPoint:
"""The one entry point of ``group`` that gives ``name``; ValueError if none or more."""
found = [ep for ep in entry_points(group=group) if lookup_name(ep.name) == name]
Expand Down
4 changes: 1 addition & 3 deletions mlx_lm/processors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@ def __call__(self, text: str, **media: Sequence[Any]) -> tuple[str, dict[str, An


def load_processor(config: dict[str, Any]) -> Processor | None:
"""The processor of the model of a configuration, or None if it takes only text."""
"""The processor of a built-in model, or None if it has none or takes only text."""
if not any(config.get(key) for key in ENCODER_CONFIGS):
return None
package = import_if_exists(f"mlx_lm.models.{model_package(config)}")
if package is None:
# Not a built-in model.
return None
module = import_if_exists(f"{package.__name__}.processor")
if module is None:
# A built-in model without a processor.
return None
return module.Processor.from_config(config)
1 change: 0 additions & 1 deletion mlx_lm/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,7 +629,6 @@ def _tokenizer_defaults(

module = plugins.import_if_exists(package)
if module is None:
# Not a built-in model.
return None
return getattr(module, "TOKENIZER_DEFAULTS", None)

Expand Down
4 changes: 2 additions & 2 deletions tests/test_plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@ def setUp(self):
"test": "test_lm.models.test:Model",
"llama": "test_lm.models.test:Model",
"Solo-LM": "test_lm.solo:Model",
"no_args": "test_lm.solo:NoArgs",
"a_module": "test_lm.solo",
"not_a_model": "test_lm.solo:NotAModel",
"a_module": "test_lm.solo",
"no_args": "test_lm.solo:NoArgs",
}
self.install(
"test-lm",
Expand Down