Skip to content

Add load_model, so plugins that name one model share it - #26

Merged
nigelgilbert merged 1 commit into
mainfrom
feature/load-model
Nov 24, 2026
Merged

nigelgilbert merged 1 commit into
mainfrom
feature/load-model

Conversation

@nigelgilbert

Copy link
Copy Markdown
Owner

A plugin still names its own model, but now loads it with load_model from kiku. Plugins that name the same model get the same loaded copy; before, each one loaded its own, and MLX does not share them (two loads of the 1.7B cleanup model measured 1.3 GB, then 2.6 GB).

from kiku import Plugin, load_model

class Pirate(Plugin):
    def __init__(self) -> None:
        self.model = load_model(MODEL)

    @override
    def on_cleaned(self, t: str) -> str:
        return self.model.prompt(PROMPT, t) or t
  • load_model(name, engine="mlx") returns a Model with one method, prompt(system, text, examples). "mlx" is the only engine so far; a second one is a new Model subclass and a new case.
  • The five examples use it, and lose their copied prompt method and their direct mlx_lm imports.
  • load_model is optional. A plugin can still call mlx-lm, or anything else, from __init__.
  • docs/hooks.md has a "Bring your own model" section.

One behavior change: terminal.py had a fixed 128-token reply limit and now gets the shared one, four times the request's length plus 64.

Checked by loading three examples through load_plugins with the real model: one shared model object, and a translation came back.

@nigelgilbert
nigelgilbert merged commit d4c5324 into main Nov 24, 2026
1 check passed
@nigelgilbert
nigelgilbert deleted the feature/load-model branch November 24, 2026 07:59
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