Choose GGUF to run a supported model in LM Studio, Ollama, or llama.cpp. Choose safetensors weights with their model configuration and tokenizer for Transformers training or vLLM serving. On Apple Silicon, LM Studio also runs compatible MLX packages that contain safetensors weights. GGUF specification, Transformers model API, vLLM weight loading, LM Studio’s MLX announcement.
Evidence note: The LM Studio 0.4.28 changelog and app documentation, GGUF v3 specification, llama.cpp master documentation, Transformers v5 and main documentation, and Safetensors and ComfyUI project documentation were checked on November 25, 2026. Commands and benchmarks were not run for this guide. LM Studio changelog.
What each format was designed to do
Safetensors stores named tensors behind a JSON header. When provided, configuration, tokenizer, and chat template files are separate from the safetensors weights. The format requires every byte of its tensor buffer to be indexed, with no gaps, to prevent polyglot files that can be interpreted as more than one format. Safetensors documentation, Safetensors format and design notes.
GGUF packages weights with metadata a compatible inference engine uses, including architecture settings and tokenizer data. It can also carry a Jinja chat template in the tokenizer.chat_template field. GGUF supports both full-precision and quantized weights. GGUF specification, Hugging Face GGUF guide.
PyTorch pickle and ONNX serve other purposes. Pickle can serialize Python objects and can execute code when unpickled, so only unpickle files you trust. An ONNX export describes the model’s computation as a graph for compatible runtimes. Hugging Face model format guide, ONNX concepts.
Side by side
| GGUF | Safetensors | |
|---|---|---|
| Best fit | Distribute a model for local inference | Store weights for training, fine-tuning, or serving |
| What travels with the weights | Model settings, tokenizer, and chat template when included | A tensor index and optional string metadata. The model repository supplies the configuration and tokenizer |
| File layout | GGUF magic bytes, v3 header, key-value metadata, aligned tensor data | 8-byte header length, JSON header, tensor bytes |
| Quantization | Formats such as Q4_K_M and Q8_0 | The loading framework interprets quantized weights, such as MLX 4-bit |
| Memory-mapped loading | Supported by design | Supported for tensor reads |
| Typical runtimes | llama.cpp, LM Studio, Ollama | Transformers, vLLM, MLX, ComfyUI |
| LM Studio support | llama.cpp loads supported GGUF models | The MLX runtime loads supported MLX packages on Apple Silicon |
GGUF specification, Safetensors format, MLX LM conversion guide, LM Studio runtimes.
Loading speed and generation speed
For GPT-2 weights, Hugging Face reported the Safetensors loader was 76.6× as fast as torch.load on a 2.00 GHz Intel Xeon and 2.1× as fast on a Tesla T4 with SAFETENSORS_FAST_GPU=1. The Safetensors maintainers also report that BLOOM load time across eight GPUs fell from 10 minutes to 45 seconds. Both examples measure loading weights. Hugging Face speed comparison, Safetensors lazy-loading notes.
For inference, llama.cpp reports a different trade-off for Llama 3.1 8B. In its benchmark, Q4_K_M used a smaller file and generated tokens faster, while F16 processed the prompt faster. Both rows are GGUF files. llama.cpp quantization benchmark.
| GGUF weights | File size | Prompt processing at 512 tokens | Generation at 128 tokens |
|---|---|---|---|
| F16 | 14.96 GiB | 923.49 ± 0.53 tokens/s | 29.17 ± 0.04 tokens/s |
| Q4_K_M | 4.58 GiB | 821.81 ± 21.44 tokens/s | 71.93 ± 1.52 tokens/s |
For quality, perplexity (ppl) measures how well the model predicts the next token on a text sample. Kullback–Leibler divergence (kld) measures how far the quantized model’s token probabilities move from a reference model’s probabilities. Compare quantizations on the same text. Hugging Face perplexity guide, llama.cpp quality measurements.
An importance matrix uses calibration text to help preserve accuracy during quantization. The calibration commands below show how to collect it and pass it to llama-quantize with --imatrix. llama.cpp importance matrix guide, llama.cpp quantization options.
Can LM Studio run safetensors?
LM Studio opens supported GGUF files with llama.cpp. On an Apple Silicon Mac running macOS 14.0 or later, it can also open supported MLX packages, including their safetensors weights. For a stock Transformers checkpoint, look for a GGUF or MLX conversion. LM Studio app docs, system requirements, LM Studio MLX engine.
- Open Discover with
Cmd+2on Mac orCtrl+2on Windows or Linux. Search the model name or paste its Hugging Face URL. The search shortcut isCmd+Shift+Mon Mac orCtrl+Shift+Mon Windows. LM Studio download guide, Hugging Face LM Studio guide. - At a terminal, use
lms get qwen --ggufor, on Apple Silicon,lms get qwen --mlx. To request a particular GGUF quantization, append a selector such as@Q6_Kto its Hugging Face repository URL. LM Studio CLI download reference, Hugging Face LM Studio guide. - If the original checkpoint is the only download, follow the GGUF conversion steps below. On Apple Silicon,
mlx_lm.convert --model mistralai/Mistral-7B-Instruct-v0.3 -qis MLX LM’s example for a compatible Transformers model. MLX LM conversion guide.
No LM Runtime found for model format
Match the format at the end of the error to the checkpoint and your OS. LM Studio’s Windows issue report includes safetensors and torchSafetensors. A maintainer identified the downloaded model in the report as MLX. LM Studio issue 569.
| Error format | What to try |
|---|---|
'safetensors' | If the repository is an MLX conversion, use it with the MLX runtime on Apple Silicon. On Windows or Linux, download a GGUF build. For a stock checkpoint, find a compatible conversion. |
'torchSafetensors' | Check the repository for a supported GGUF or MLX download. For an ordinary PyTorch/Transformers checkpoint, download or create a conversion suited to your platform. |
'gguf' | Open LM Runtimes with Cmd+Shift+R on Mac or Ctrl+Shift+R on Windows or Linux. Install or update the llama.cpp runtime and try loading the model again. |
LM Studio runtime management, LM Studio issue 317, LM Studio issue 569.
At the terminal, list the installed runtimes with lms runtime ls. Use lms runtime get if the required runtime is missing or lms runtime update for an installed runtime. Run lms runtime select to choose the active version. LM Studio runtime CLI.
If the GGUF error persists, check for AVX2 on x64. LM Studio requires AVX2 support on x64 Windows and ships with AVX2 support by default on x64 Linux. LM Studio system requirements.
Continuous batching for GGUF
LM Studio’s parallel-request guide specifies llama.cpp runtime v2.0.0 for continuous batching. It lets the server combine overlapping requests into a batch. In the model loader, turn on Manually choose model load parameters, select a model, then turn on Show advanced settings. Set Max Concurrent Predictions, which defaults to 4. LM Studio parallel requests.
GGUF vs MLX vs safetensors
MLX is an inference and machine learning framework that can use safetensors weights. Check the repository’s name and file list before downloading. LM Studio added its MLX runtime in 0.3.4 and can load GGUF and MLX models simultaneously. LM Studio MLX announcement, MLX LM documentation.
| Choice | What to look for | LM Studio runtime |
|---|---|---|
| GGUF | A compatible .gguf download in your chosen quantization | llama.cpp on supported platforms |
| MLX | A repository marked MLX. For example, LM Studio’s MLX LFM2 release has model.safetensors, config.json, and tokenizer files | MLX on Apple Silicon |
| Stock safetensors checkpoint | Weights, configuration and tokenizer published for the source framework. A sharded model such as Qwen2.5 also has a weights index | Choose a GGUF or MLX build for your platform |
Hugging Face GGUF guide, LM Studio’s MLX file list, Qwen’s Transformers file list.
The compatibilityTypes field in model.yaml describes model variants in the catalog. It can list both gguf and safetensors. The model listing API reports the actual model file format as gguf, mlx, or null. LM Studio model.yaml, LM Studio model listing API.
GGUF vs safetensors in ComfyUI
ComfyUI’s built-in Load Checkpoint node loads safetensors checkpoints. The ComfyUI-GGUF custom nodes can load GGUF diffusion weights for models such as Flux. Compare the files in city96’s FLUX.1-dev model card and download listing.
| FLUX.1-dev quantization | F16 | Q8_0 | Q6_K | Q5_K_S | Q4_K_S | Q3_K_S | Q2_K |
|---|---|---|---|---|---|---|---|
| File size | 23.8 GB | 12.7 GB | 9.86 GB | 8.29 GB | 6.81 GB | 5.23 GB | 4.03 GB |
ComfyUI’s Flux examples offer flux1-dev-fp8.safetensors for Load Checkpoint. For this checkpoint, put it in ComfyUI/models/checkpoints and set CFG to 1.0. The examples also show how to reduce memory use by setting weight_dtype to FP8 in Load Diffusion Model. The examples recommend full 16-bit weights when resources permit because FP8 can reduce quality. ComfyUI Flux workflows.
If FP8 fits in VRAM, compare sampling speed on the same workflow before switching. ComfyUI has a dedicated FP8 linear path, while the GGUF custom node expands quantized weights during layer execution. That extra work can offset a smaller GGUF download when both models fit and the backend can use the FP8 path. ComfyUI FP8 code, ComfyUI-GGUF weight handling.
To use a Flux GGUF in ComfyUI, follow the ComfyUI-GGUF install and usage instructions.
- From
ComfyUI/custom_nodes, rungit clone https://github.com/city96/ComfyUI-GGUF. Install the dependency into ComfyUI’s Python environment withpip install --upgrade gguf. - Place the
.gguffile inComfyUI/models/unet. - Use Unet Loader (GGUF) in the bootleg category in place of Load Diffusion Model.
For a safetensors checkpoint that bundles the diffusion model, text encoder, and VAE, put it in ComfyUI/models/checkpoints and select it in Load Checkpoint. ComfyUI Load Checkpoint documentation.
Where to get a compatible model
Look for a supported build before converting. Use the LM Studio app and its model downloader to search for a GGUF or MLX release. If you already have Ollama or llama.cpp installed, these commands open the same example Hub GGUF at Q8_0. Hugging Face Ollama guide, Hugging Face llama.cpp guide.
ollama run hf.co/bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0
llama cli -hf bartowski/Llama-3.2-3B-Instruct-GGUF:Q8_0
Converting safetensors to GGUF
For an architecture supported by llama.cpp, first convert the original weights to a high-precision GGUF, then quantize. Keep enough disk space for the source weights, intermediate GGUF, and final quantized file. llama.cpp quantization guide.
-
Clone and build llama.cpp, then install its Python requirements. llama.cpp build instructions, Python requirements.
git clone https://github.com/ggml-org/llama.cpp cd llama.cpp cmake -B build cmake --build build --config Release python3 -m pip install -r requirements.txt -
Download the source model directory with the weight files, model configuration and tokenizer. Point
convert_hf_to_gguf.pyat that directory. Here./Model-Dirstands for its local path. llama.cpp converter arguments.python convert_hf_to_gguf.py ./Model-Dir --outfile model-bf16.gguf --outtype bf16 -
Pass
Q4_K_Mtollama-quantize. The converter’s--outtypeacceptsbf16, but rejectsq4_k_m. llama.cpp quantization guide, converter output types../build/bin/llama-quantize model-bf16.gguf model-Q4_K_M.gguf Q4_K_M -
Run
lms import model-Q4_K_M.gguf --copyand follow the prompts. The--copyflag keeps the original file in place. Then select the imported model in LM Studio. LM Studio import guide, CLI import options, Loading a model in LM Studio.
To use a calibration matrix in step 3, put representative text in calibration-data.txt and run the following commands from the llama.cpp repository. llama.cpp importance matrix guide.
./build/bin/llama-imatrix -m model-bf16.gguf -f calibration-data.txt -o imatrix.gguf
./build/bin/llama-quantize --imatrix imatrix.gguf model-bf16.gguf model-Q4_K_M.gguf Q4_K_M
For a Hub repository, the quantization guide also shows a --remote conversion and a separate --mmproj export for vision weights. llama.cpp quantization guide.
Converting GGUF to safetensors
Transformers can export a supported GGUF as a dense model. Dequantization expands the rounded weights and cannot recover the original precision. For fine-tuning where that precision matters, start from the original checkpoint. Transformers GGUF guide, llama.cpp quantization guide.
The example uses the Qwen checkpoint from the Transformers docs. Substitute your compatible repository and filename. GgufConfig(dequantize=True) explicitly loads dense weights. The legacy loader already dequantizes supported architectures such as Llama, Mistral, and Qwen2. Budget memory for the expanded weights. Transformers GGUF guide.
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, GgufConfig
model_id = "unsloth/Qwen3.5-4B-GGUF"
filename = "Qwen3.5-4B-Q4_K_M.gguf"
tokenizer = AutoTokenizer.from_pretrained(model_id, gguf_file=filename)
model = AutoModelForCausalLM.from_pretrained(
model_id,
gguf_file=filename,
quantization_config=GgufConfig(dequantize=True),
dtype=torch.bfloat16,
)
model.save_pretrained("output-directory")
tokenizer.save_pretrained("output-directory")
The output directory contains model weights, model configuration, and tokenizer files. In Transformers v5, omit safe_serialization from save_pretrained(). It writes safetensors weights by default and no longer accepts that parameter. For LM Studio, use the original supported GGUF or a compatible MLX package. Transformers model API, tokenizer API, Transformers v5 migration guide, LM Studio runtimes.
Running packed GGUF weights in Transformers
For inference on Apple Silicon, the September 2026 Transformers update documents packed execution for Qwen3.5 dense and MoE architectures, including compatible Qwen3.8 checkpoints. The packed path uses the ggml-org/ggml-quantization Metal kernel through PyTorch MPS. Hugging Face packed GGUF announcement.
With a compatible Transformers and PyTorch installation, run pip install kernels. Use the same from_pretrained(..., gguf_file=filename) call and omit the explicit dequantization configuration and dtype. The loader falls back to dense weights if a compatible kernel is unavailable. Transformers GGUF guide, Hugging Face packed GGUF requirements.
Applying a LoRA adapter to a GGUF model
If your fine-tune is a PEFT LoRA adapter, convert just the adapter with GGUF-my-LoRA. Sign in to Hugging Face in GGUF-my-LoRA, select the adapter, then download the result from the new repository in your account. Load the matching base model with -m and the adapter with --lora. llama.cpp GGUF-my-LoRA announcement, llama.cpp CLI options.
llama cli \
-m Meta-Llama-3.1-8B-Instruct-Q4_K_M.gguf \
--lora Llama-3-Instruct-abliteration-8B.gguf
Pick a quantization that fits
Check runtime support before downloading weights. Then use which GGUF quant level: Q4_K_M vs Q8_0 to pick a variant. To check whether it fits, use how much VRAM a 7B model needs or the VRAM and GGUF sizer. LM Studio’s system requirements covers platform requirements.
For serving the model from another machine, see running LM Studio headless on Unraid.