LM studio MLX based models

#79
by HuskGua - opened

The template never work with LM Studio MLX models, I tested also old templates, but never worked.
It calls the tools by writing following and exited afterwards

image

Does anyone know how it can be fixed??

GGUF based models works fine

This happens because LM Studio handles GGUF and MLX through two completely different engines under the hood.

For GGUF models, LM Studio uses llama.cpp, which parses custom Jinja templates and XML tool calls without any trouble. But for its MLX backend, LM Studio does not have an XML parser hooked up. It expects tool calls in standard JSON format. When Qwen outputs its native XML (<function=...><parameter=...>), LM Studio fails to recognise it as a tool call, dumps the raw text into the chat window, and simply stops.

A couple of ways round this:

Stick with the GGUF in LM Studio: On Apple Silicon, Metal performance on GGUFs is pretty much identical to MLX, and tool calling works out of the box with this template.

Force JSON in the template: If you want to keep using the MLX model inside LM Studio, you can edit ** line 2** of chat_template.jinja before pasting it into LM Studio's prompt settings. Change:

{%- set _tool_format = tool_call_format if tool_call_format is defined else 'xml' %}

to:

{%- set _tool_format = 'json' %}

This will tell the model to output Hermes JSON ({"name": "...", "arguments": {...}}) instead of XML, which LM Studio's MLX runner should be able to catch.

or:

Use standalone MLX tools: If you run the model outside LM Studio using mlx-lm or omlx, custom Jinja and tool parsing work as intended.

LM Studio's MLX backend does not have an XML parser hooked up, so it only understands JSON tool calls. If you set _tool_format = 'json' at the top of chat_template.jinja before pasting it into LM Studio, it will output Hermes JSON and tool calls should work.

froggeric changed discussion status to closed

Sign up or log in to comment