Skip to content

fix(mlx): accept file:// filesystem model paths (#7461)#10289

Open
localai-bot wants to merge 1 commit into
masterfrom
fix/7461-mlx-file-uri
Open

fix(mlx): accept file:// filesystem model paths (#7461)#10289
localai-bot wants to merge 1 commit into
masterfrom
fix/7461-mlx-file-uri

Conversation

@localai-bot

Copy link
Copy Markdown
Collaborator

Closes #7461

Problem

A filesystem-imported MLX model arrives with its model: set to a file:// URI (LocalAI's LocalPrefix). The MLX backends passed request.Model verbatim to mlx_lm load(), which rejected it ("Repo id must be in the form ... Use repo_type argument if needed") because file://... is neither a valid HF repo id nor an existing path.

Fix

New pure helper resolve_model_path(model, model_file="") in backend/python/common/python_utils.py: prefers a non-empty ModelFile (the resolved local path, proto field 21), strips a file:// scheme and percent-decodes it, and leaves plain HF repo ids / local paths unchanged. Wired into all three MLX backends (mlx, mlx-vlm, mlx-distributed) for their load()/load_config()/model_key/broadcast paths.

Test plan

  • Six new TestSharedHelpers cases in backend/python/mlx/test.py covering file:// stripping, percent-decoding, ModelFile precedence, and pass-through of repo ids/local paths.
  • Verified by running the isolated pure helper (the backends' grpc/mlx_lm deps aren't importable in CI-less envs); all four edited files pass py_compile.

Note

Could not load a real MLX model end-to-end (needs Apple Silicon); verified at helper/logic + syntax level.

Assisted-by: claude:claude-opus-4-8 [Claude Code]

…d models

MLX backends passed request.Model verbatim to mlx_lm/mlx_vlm load(). For a
model imported from the filesystem, LocalAI hands the backend a file:// URI
(its LocalPrefix), which load() rejects: the scheme is neither a valid HF
repo id nor an existing path (Path(model).exists() fails on the scheme),
producing "Repo id must be in the form 'repo_name' or 'namespace/repo_name'
... Use repo_type argument if needed".

Add a pure, unit-testable resolve_model_path(model, model_file) helper in the
shared python_utils: it prefers the resolved ModelFile, strips a file://
scheme and percent-decodes the path, and leaves plain repo ids and local
paths untouched. Wire it into the mlx, mlx-vlm and mlx-distributed backends
(load, model_key, and the distributed broadcast all use the normalized path).

Fixes #7461.

Assisted-by: claude:claude-opus-4-8 [Claude Code]
Signed-off-by: Ettore Di Giacinto <mudler@localai.io>
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.

Using MLX model imported from filesystem fails due to repo_type

2 participants