Your GGUF Model Won't Load — Here's Every Fix Including File Recovery
GGUF file corruption and llama.cpp compatibility errors are among the most common blockers for developers running local LLMs in 2026. Whether llama.cpp throws invalid magic number, LM Studio refuses to load a model, or a 30 GB model file disappears after a disk cleanup, the fixes exist — and this guide covers all of them. You will also find the one scenario most troubleshooting articles skip entirely: recovering a GGUF file that was accidentally deleted from your hard drive before it gets overwritten.
Part 1. What Causes GGUF File Corruption and Loss
Understanding the root cause before attempting a fix saves significant time. There are four distinct failure modes, and each requires a different resolution path.
1. Incomplete Download
Large GGUF files — often 4–70 GB — are frequently truncated mid-transfer without a visible error in the browser. The file appears to exist and the size may look close to correct, but llama.cpp typically throws invalid magic number or unexpected EOF when it attempts to read the file header or tensor data. SHA256 checksum verification is the only reliable way to catch this class of failure.
🗣️ r/LocalLLaMA user: "I spent three hours debugging before realizing my 13B download had silently stopped at 97% — the file size looked almost right but llama.cpp just threw 'unexpected end of file'. Always check the SHA256."
2. Disk Read/Write Error
A physically degraded drive — HDD bad sectors or SSD NAND wear — can produce a file that passes a basic size check yet contains corrupted bytes at the block level. The model may load partially or fail at inference time with inconsistent errors. Running a disk health check before re-downloading to the same drive is essential; re-downloading to a damaged drive often reproduces the same corruption.
3. llama.cpp Version / GGUF Format Mismatch
The GGUF format has iterated through three major versions, and llama.cpp drops backward compatibility at certain build boundaries. GGUF v1 was deprecated in build b1500 and later. GGUF v3 introduced metadata keys that break inference on older builds. A mismatch between the file's GGUF version and the runtime build produces errors such as unsupported model file version or key not found in metadata.
4. Accidental Deletion
Large model files are frequent targets during disk cleanup sessions — tools like TreeSize, WinDirStat, or CleanMyMac often surface the models/ directory as the top space consumer. When a GGUF file is deleted, the operating system removes only the directory entry; the raw bytes of the 3–70 GB file remain on the disk until new writes overwrite those sectors. Recovery is often possible if no significant data has been written to the drive after the deletion.
Part 2. Diagnose the Problem: llama.cpp Error Message Reference
The error message llama.cpp or LM Studio surfaces at load time typically points directly at the root cause. Use the table below to map each message to a fix.
💡 Tip: Run
llama-cli --versionto confirm your build number before troubleshooting — many compatibility issues become obvious once you know which build you are running.
Table 1: GGUF Error Message Reference
| Error Message | Root Cause | Fix |
|---|---|---|
invalid magic number |
Corrupt or incomplete download | Re-download + verify SHA256 (Part 3) |
unexpected end of file |
Truncated download or disk error | Re-download + check disk health (Part 3) |
unsupported model file version |
Old GGUF v1/v2 vs new llama.cpp build | Convert format or pin build (Part 4) |
key not found / missing metadata key |
GGUF v3 metadata missing in older file | Convert using convert_hf_to_gguf.py (Part 4) |
tensor count mismatch |
Quantization conversion interrupted mid-run | Delete partial file and re-quantize from source (Part 3) |
failed to mmap model |
Network share, permissions issue, or antivirus lock | Move to local drive, check AV exclusions |
model file not found |
Accidental deletion or incorrect path | File recovery (Part 5 and Part 6) |
Each error category leads to a specific resolution in the sections that follow. Start with the exact error string from your terminal or LM Studio logs and proceed to the corresponding part.
Part 3. Fix 1 — Re-Download from Hugging Face with SHA256 Verification
An incomplete or bit-corrupted GGUF file cannot be repaired in place — the only reliable fix is to re-download the file and verify the checksum before attempting to load it. The following steps apply to any GGUF file hosted on Hugging Face.
Step 1. Open the Hugging Face repository page for the model. Locate the .gguf file entry and click the copy icon next to the SHA256 hash displayed beside the filename.
Step 2. Delete the suspect file from your local models directory. Do not attempt to load it again — llama.cpp may write partial cache files that complicate the diagnosis.
Step 3. Re-download using the Hugging Face CLI rather than the browser:
huggingface-cli download {org}/{model} {file}.gguf --local-dir ./models
💡 Tip: Use
huggingface-cliinstead of browser downloads for files over 4 GB — it supports automatic resume-on-interruption and does not rely on browser connection stability for multi-hour transfers.
Step 4. After the download completes, verify the checksum:
# Windows (PowerShell)
Get-FileHash .\models\model.gguf -Algorithm SHA256
# macOS / Linux
shasum -a 256 ./models/model.gguf
Step 5. Compare the output hash character-by-character against the hash shown on the Hugging Face repository page. The strings must match exactly — a single character difference indicates corruption.
Step 6. If hashes differ after two consecutive download attempts, verify available disk space on the target drive and temporarily disable antivirus real-time scanning, which is known to truncate large binary downloads on some configurations.
⚠️ Important: Do not re-download to the same drive that shows disk errors. Run CHKDSK on Windows (
chkdsk C: /f /r) or Disk Utility First Aid on macOS first, or redirect the download to a healthy secondary drive.
Part 4. Fix 2 — Resolve llama.cpp Version and GGUF Format Incompatibility
When the error is unsupported model file version or missing metadata key, the mismatch is between the GGUF format version embedded in the file and the llama.cpp build you are running. The fix requires identifying the GGUF version, then choosing between converting the file or pinning the runtime.
Identify the GGUF Version
Bytes 4–7 of any GGUF file encode the format version as a little-endian uint32. Read it in Python without loading the full model:
import struct
with open('model.gguf', 'rb') as f:
f.read(4) # skip magic bytes 'GGUF'
version = struct.unpack('<I', f.read(4))[0]
print(f'GGUF version: {version}')
Version 1 is deprecated in llama.cpp builds after b1500. Version 2 and version 3 are generally forward-compatible with current builds, though specific metadata keys introduced in v3 may cause errors on builds older than b2000.
Option A — Convert the File to Current GGUF Format
Use the convert_hf_to_gguf.py script from the llama.cpp repository. You will need the original Hugging Face model weights (not the GGUF) as input — this option applies when you have the source safetensors or PyTorch bin files.
python convert_hf_to_gguf.py ./model-weights-dir --outfile ./models/model-v3.gguf --outtype q4_k_m
Option B — Pin the llama.cpp Build
Download a specific tagged release from the llama.cpp GitHub releases page that matches the GGUF version of your file. In LM Studio, navigate to Settings → Runtime and select "Use specific runtime version" to pin to an older llama.cpp backend.
Quantization Compatibility Reference
Different quantization types require minimum llama.cpp build versions and carry different quality and size trade-offs for a 7B parameter model.
Table 2: GGUF Quantization Types
| Quant Type | File Size (7B) | Quality vs F16 | Min Build | Best For |
|---|---|---|---|---|
| F32 | ~28 GB | Identical reference | Any | Development ground truth |
| F16 | ~14 GB | Near-lossless | Any | GPU inference with VRAM to spare |
| Q8_0 | ~7.7 GB | Near-lossless | b500+ | Best quality/size ratio on SSD |
| Q5_K_M | ~5.2 GB | Excellent | b1000+ | Good quality at moderate RAM |
| Q4_K_M | ~4.1 GB | Good — recommended default | b1000+ | Best overall on consumer hardware |
| Q3_K_M | ~3.3 GB | Acceptable | b1000+ | Low-RAM devices with 8 GB RAM |
| IQ2_XXS | ~2.2 GB | Noticeably degraded | b2000+ | Extreme size constraints only |
🗣️ r/LocalLLaMA user: "Q4_K_M is almost always the sweet spot. You give up maybe 1-2% coherence vs Q8 and cut your file size in half. Unless you're doing benchmarks, I wouldn't bother with anything higher."
When a quantization conversion was interrupted — typically indicated by tensor count mismatch — the partial output file cannot be salvaged. Delete it and restart the quantization run from the full F16 or F32 source.
Part 5. Fix 3 — Recover an Accidentally Deleted GGUF File
Accidental deletion is a distinct failure mode from corruption and requires a completely different response. When the operating system marks a file as deleted, it removes only the directory entry — the raw byte sequence making up the 3–70 GB GGUF file remains physically present on the drive until subsequent writes claim those sectors.
The critical factor is time and write activity. Every file download, application log write, or OS operation that lands on the same drive reduces the probability of full recovery. If you realize a GGUF file has been deleted, stop writing to that drive immediately. Do not download a replacement model to the same drive — use a different drive for any new data.
�� Tip: GGUF files are typically 3–70 GB and stored contiguously on disk — this makes them easier to recover intact compared to smaller, fragmented files. Act quickly and avoid all writes to the affected drive to maximize recovery chances.
GGUF files are large binary blobs stored as contiguous byte sequences, which makes them more recoverable than smaller, fragmented files. A recovery scanner reading raw sectors can often reconstruct the full file from a single contiguous region.
Ritridata supports recovery of deleted GGUF files from Windows and Mac HDD/SSD drives, including external hard drives used as model storage directories. Note the scope carefully before proceeding:
- Supported: Windows HDD/SSD, Mac HDD/SSD, external hard drives connected via USB or Thunderbolt
- Not supported: RAID arrays, NAS devices, Linux file systems
- What Ritridata does: Recovers deleted files from raw disk sectors — it restores the original file bytes
- What Ritridata does not do: Repair internal GGUF corruption — if the recovered file still fails to load, re-download from Hugging Face per Part 3
Part 6. Recover Deleted GGUF Files with Ritridata
If your GGUF model file was accidentally deleted from a Windows or Mac drive, Ritridata can scan the raw storage for deleted file data before it is overwritten. The process is non-destructive — the scan reads sectors without writing to the source drive.
Step 1 — Select the drive where your models directory was stored
Launch Ritridata and select the drive or partition that contained your GGUF files. If the models directory was on an external drive, connect it before launching — do not write any new files to it first.
Step 2 — Run a safe scan
Initiate the scan. Ritridata reads raw sectors looking for deleted file data, including large binary files such as .gguf models in the 3–70 GB range. The scan is read-only and does not modify the source drive.
Step 3 — Preview and recover to another drive
When the scan completes, browse results by file name and size to identify your model. Filter by .gguf extension to narrow the list. Recover the file to a different drive — never recover to the same drive that was scanned, as writes during recovery may overwrite other deleted data.
After recovery, verify the SHA256 hash against the Hugging Face repository page using the steps in Part 3. If the hash matches, the file is intact and ready to use. If it does not match, the sectors were partially overwritten — re-download from Hugging Face using huggingface-cli.
Part 7. Prevention Checklist
Preventing GGUF-related failures is significantly less time-consuming than recovering from them. The following practices address each of the four root causes identified in Part 1.
- Verify SHA256 checksums after downloading any GGUF file over 1 GB — make this a non-negotiable step in your model download workflow
- Use
huggingface-cliinstead of the browser for all model downloads larger than 4 GB — it supports interrupted transfers and does not silently truncate - Keep a dedicated models directory on a secondary drive, separate from the OS drive — this reduces the risk of accidental deletion during system cleanups and isolates disk health issues
- Maintain a plain-text file listing model names, quantization types, and Hugging Face source URLs — re-downloading becomes straightforward when the source is documented
- Pin the llama.cpp build version in your project
.envorREADMEalongside the models it was tested with — version drift is the leading cause of sudden compatibility breakage - Exclude the models folder from antivirus real-time scanning — AV tools may quarantine or truncate large binary files they cannot identify
- Before running any disk cleanup tool such as TreeSize, WinDirStat, or CleanMyMac, verify that your models directory is explicitly excluded from the cleanup scope
FAQ
Q1: Why does llama.cpp say 'invalid magic number'?
The file was likely downloaded incompletely or became corrupted during transfer. Re-download the file using huggingface-cli and verify the SHA256 hash against the Hugging Face repository page before attempting to load it.
Q2: Can I use an old GGUF file with a new llama.cpp build?
It depends on the GGUF version encoded in the file. GGUF v1 is not compatible with builds after b1500. GGUF v2 and v3 are generally forward-compatible with current builds, though specific metadata keys introduced in v3 may cause errors on builds below b2000.
Q3: Does LM Studio use the same GGUF format as llama.cpp?
Yes. LM Studio uses llama.cpp as its inference backend, and the same GGUF version compatibility rules apply. Use LM Studio's "Use specific runtime version" setting to pin to a build that matches your file's GGUF version.
Q4: What is the difference between Q4_K_M and Q5_K_M?
Q5_K_M uses more storage — approximately 5.2 GB versus 4.1 GB for a 7B model — in exchange for better output quality. Q4_K_M is the recommended default for consumer hardware where VRAM or RAM is the limiting constraint. Q5_K_M may be preferable for tasks where output coherence is critical and storage is available.
Q5: Can I recover a GGUF file I deleted from my PC or Mac?
Often yes, provided no large amounts of new data have been written to the same drive since the deletion. The sooner you act and the less you write to the affected drive, the better the recovery chances. Ritridata can scan Windows and Mac drives for deleted file data including large GGUF files.
Q6: Will data recovery software work on a GGUF file stored on a NAS?
Ritridata does not support NAS recovery. For GGUF files stored on a NAS or RAID system, contact your NAS manufacturer's support or engage a professional data recovery service that specializes in RAID and network-attached storage systems.
Q7: Does Ritridata repair a corrupted GGUF file?
No. Ritridata recovers deleted files from raw disk sectors — it restores the original file bytes as they existed on the drive. It does not repair internal GGUF format corruption. If the recovered file still fails to load in llama.cpp, re-download from Hugging Face and verify the SHA256 hash per Part 3.
Q8: How do I check which GGUF version a model file uses?
Read bytes 4–7 of the file as a little-endian uint32 in Python:
import struct
with open('model.gguf', 'rb') as f:
f.read(4) # skip 'GGUF' magic bytes
version = struct.unpack('<I', f.read(4))[0]
print(version) # 1 = v1 (deprecated), 2 = v2, 3 = v3 (current)
Version 1 is deprecated in llama.cpp builds after b1500. Version 3 is the current standard.
References
- llama.cpp GitHub — GGUF Format Specification: https://github.com/ggerganov/llama.cpp/blob/master/docs/gguf.md
- Hugging Face — Downloading Models with the CLI: https://huggingface.co/docs/huggingface_hub/guides/download
- r/LocalLLaMA community: https://www.reddit.com/r/LocalLLaMA/
- Microsoft — CHKDSK disk error check: https://support.microsoft.com/en-us/windows/check-your-hard-disk-for-errors-86e8f70e-3f6c-4f33-8b7d-7f9e5f7f6a3b
- Apple — Disk Utility: Repair a storage device: https://support.apple.com/guide/disk-utility/repair-a-storage-device-dskutl1040/mac
