Executable programs and extensions
Last updated
Run GGUF directly in Transformers: how it differs from llama.cpp and MLX
Load a GGUF directly and generate answers in a Python evaluation workflow
On Apple Silicon, Transformers can compute with GGUF1 weights in their quantized form through compatible kernels and answer questions through a Python API2 or local server. This is useful when you want dataset evaluation, intermediate model outputs, and custom processing in the same Python project.
If you already use a GGUF model and want to run a list of questions, save the answers, or manage preprocessing and evaluation alongside Python code, you can load the GGUF file directly in Transformers. This path uses compatible kernels on Apple Silicon MPS to compute with quantized weights.
First prepare compatible packages and files, then load the model with a small input and check the result. Next decide whether you need an API server or whether llama.cpp or MLX3 would be simpler for your work.
Decide which code workflow to connect to the GGUF
llama.cpp is a common way to run GGUF. Its many app and server options make it easy to select a model file and start chatting. Transformers offers a familiar API when you want to work with intermediate model outputs, custom logit processing, or evaluation code in the same Python project.
With the Transformers path, you can work with GGUF through its API without expanding all weights into large floating-point values.
For a simple chat server, the mature llama.cpp path may be simpler. Transformers may fit better when you need to inspect model internals or continue dataset evaluation and preprocessing in the same code. Choose based on the next task rather than which engine is universally better.
- Hugging Face’s official article on GGUF in Transformers
- Context length, RoPE and sliding-window attention
- Prefill vs decode: should you look at TTFT or tok/s?
- GGUF vs MLX: which model format should you download?
- Run Jev-Style Local Decision Models on Mac, RTX 3090, and Servers
- Building Fully Offline Local AI: Air-Gap Installation and Update Procedures

Check memory use to see whether the quantized kernel is active
The documented path loads ggml and ggml-attn kernels on Apple Silicon MPS to compute with quantized weights. If the PyTorch4, Transformers, and kernels versions are incompatible, a regular dequantization path may be used. Read the model-loading logs and check memory use before and after execution.
The size of a Q4 GGUF file alone does not tell you how much memory execution will need. The KV cache5 and runtime6 also use memory. Record a baseline with the compatible kernel active, then check how use changes as you increase context length7. If it grows more than expected, inspect kernel activation and data type before blaming the file format.

Specify both the repository and the GGUF file
A Hugging Face repository may contain several quantized files. Specify both the repository ID and gguf_file in from_pretrained to select the intended Q4 file. Before this feature is included in a stable release, you may need Transformers main and a compatible version of kernels, as shown in the official article.
Start with a small model and short prompt8, recording CPU9 and GPU10 memory and the initial load time. Then move to the model you want and check the same items. If you do not need custom code and would otherwise spend time matching package and kernel versions, llama.cpp or MLX may be easier to operate.
pip install -U "git+https://github.com/huggingface/transformers.git" kernelsfrom transformers import AutoModelForCausalLM, AutoTokenizer
repo = "bartowski/Qwen2.5-7B-Instruct-GGUF"
file = "Qwen2.5-7B-Instruct-Q4_K_M.gguf"
tokenizer = AutoTokenizer.from_pretrained(repo, gguf_file=file)
model = AutoModelForCausalLM.from_pretrained(repo, gguf_file=file, device_map="mps")
First verify a response from the local API
transformers serve opens an OpenAI-compatible API so existing apps can call the model. The official introduction says its initial implementation focuses on one conversation at a time, with padding and batching still needing refinement. Start at the default local address and verify a response; add authentication and a proxy before allowing external access.
Once the server starts, check available model IDs at /v1/models and send a short request using one of them. A generated result in the JSON response’s choices confirms model loading and API connectivity. If multiple users will connect, first verify one request, then measure time to first token11 and total throughput12 separately at concurrency levels 2, 4, and 8.
Python hooks are convenient, but they also expand the user and model-repository code that can execute. Pin the revision and package versions, and separate development from production.
transformers serve "bartowski/Qwen2.5-7B-Instruct-GGUF:Qwen2.5-7B-Instruct-Q4_K_M.gguf"curl http://127.0.0.1:8000/v1/models
curl http://127.0.0.1:8000/v1/chat/completions \
-H 'Content-Type: application/json' \
-d '{"model":"bartowski/Qwen2.5-7B-Instruct-GGUF:Qwen2.5-7B-Instruct-Q4_K_M.gguf","messages":[{"role":"user","content":"로컬 모델이 준비됐는지 한 문장으로 알려줘."}],"max_tokens":32}'Check in sequence if memory use spikes or a request fails
If the file cannot be found, check that the repository ID and gguf_file name are exact and that the file exists in that repository. If the download is blocked, check Hub connectivity and access permissions. If memory use grows more than expected after loading the GGUF, check the logs for ggml kernel activation and confirm that the PyTorch, Transformers, and kernels versions are compatible.
If the server starts but a request fails, use the model ID shown by /v1/models exactly and use the first log error to distinguish model loading, request format, and memory issues. If only long inputs fail, lower the context length and resend the same request. If memory is insufficient, check the baseline request with a smaller quantized file. Keep the model file and input fixed when comparing each change.
Choose Transformers, llama.cpp, or MLX for the task
If you need a chat or embedding server with broad GGUF support and simple installation, start with llama.cpp. Consider MLX when you want Apple Silicon model conversion and array operations in the MLX development workflow. Choose Transformers to retain Hugging Face evaluation, pipelines, and custom forward logic while using GGUF’s memory advantages.
Compare speed with the same model file, prompt, and output length. The Transformers figure in the official article includes prefill13 for a 128-token generation, while llama-bench’s tg128 is decode-focused, so the values cannot be ranked directly. Measure time to first token, decode14 speed, and peak memory on your own workload.
Terminology notes
GGUF — A file format for model data, widely used by llama.cpp-based tools.
Back to the textAPI — A defined interface that lets other code call a program’s functions.
Back to the textMLX — Apple’s machine-learning framework, which runs models using memory shared by the CPU and GPU on Apple Silicon.
Back to the textPyTorch — A software framework for building and running AI models. Check the compatible PyTorch version and hardware support along with the model.
Back to the textKV cache — Memory that stores attention keys and values from earlier tokens for reuse during later token generation. Its size depends on context length and batch size.
Back to the textRuntime — The software environment that provides facilities needed while a program runs. In local AI, it can also refer to a model execution engine.
Back to the textContext window — The token span of input and generated content a model can handle in one request. The supported limit and memory use depend on the model and runtime settings.
Back to the textPrompt — The input text sent to a model. For generative models it describes the desired result and strongly shapes the output.
Back to the textCPU — The central processor that runs the operating system and general-purpose instructions; in AI workloads it also handles tasks such as preprocessing and data movement.
Back to the textGPU — A processor designed to handle many calculations in parallel. It performs model computations during AI inference.
Back to the textTime to First Token — The time from sending a request until its first output token arrives.
Back to the textThroughput — The amount of work processed or generated over time. Comparisons need the unit, such as tokens per second or requests per second.
Back to the textPrefill — The stage where an LLM reads the input prompt and computes representations for its tokens. Longer prompts contain more tokens to process.
Back to the textToken decoding — The stage that generates successive output tokens using the input and the response produced so far.
Back to the text
Frequently asked questions
- What should you check first in this article?
- On Apple Silicon, Transformers can compute with GGUF weights in their quantized form through compatible kernels and answer questions through a Python API or local server. This is useful when you want dataset evaluation, intermediate model outputs, and custom processing in the same Python project.
- How much memory does it need?
- The documented path loads ggml and ggml-attn kernels on Apple Silicon MPS to compute with quantized weights. If the PyTorch, Transformers, and kernels versions are incompatible, a regular dequantization path may be used. Read the model-loading logs and check memory use before and after execution.
Read next
Executable programs and extensions
llama.cpp: finding which settings are slowing you down
Executable programs and extensions
Run local AI with MLX on Apple Silicon: frameworks and model tools explained
Executable programs and extensions
Which local LLM app or serving engine should you start with?
memory and model
How much VRAM or unified memory does a local LLM need?
