To download a GGUF model from Hugging Face that has multiple files (e.g., different quantization levels), you can use either the huggingface_hub Python library or git lfs. Here's how to do it:
Method 1: Using huggingface_hub (Python)
This is the easiest way to download specific GGUF files without cloning the entire repository.
1. Install the huggingface_hub library:
pip install huggingface-hub
2. Download a specific GGUF file:
from huggingface_hub import hf_hub_download
model_id = "TheBloke/Llama-2-7B-GGUF" # Example model
filename = "llama-2-7b.Q4_K_M.gguf" # Choose your quantization
# Download the model
model_path = hf_hub_download(
repo_id=model_id,
filename=filename,
local_dir="models", # Save to a local folder
local_dir_use_symlinks=False,
)
print(f"Model saved to: {model_path}")
3. Download all GGUF files (if needed):
from huggingface_hub import snapshot_download
model_id = "TheBloke/Llama-2-7B-GGUF"
snapshot_download(
repo_id=model_id,
allow_patterns="*.gguf", # Only download GGUF files
local_dir="models",
local_dir_use_symlinks=False,
)
Method 2: Using git lfs (Command Line)
If you want to clone the entire repository (useful if you need other files like configs):
1. Install Git LFS:
sudo apt-get install git-lfs # Linux (Debian/Ubuntu)
brew install git-lfs # macOS
2. Clone the repository (with LFS):
git lfs install
git clone https://huggingface.co/TheBloke/Llama-2-7B-GGUF
cd Llama-2-7B-GGUF
3. Download only the GGUF files (if you don't want everything):
git lfs pull --include="*.gguf"
Choosing the Right GGUF File
Most GGUF repositories (like those from TheBloke) include multiple quantization levels:
- Higher quantization (e.g.,
Q5_K_M, Q6_K): Better quality, larger file size.
- Lower quantization (e.g.,
Q2_K, Q4_0): Faster inference, lower quality.
Example filenames:
llama-2-7b.Q4_K_M.gguf # Medium 4-bit quantization (good balance)
llama-2-7b.Q8_0.gguf # High precision (8-bit)
llama-2-7b.Q2_K.gguf # Very small, but lower quality
Using the Downloaded GGUF Model
Once downloaded, you can use it with:
llama.cpp (for CPU/GPU inference)
- VLLM (if GGUF support is available)
- Ollama (for local LLM serving)
Example with llama.cpp:
./main -m models/llama-2-7b.Q4_K_M.gguf -p "Tell me about AI"
Summary
- For a single file: Use
hf_hub_download.
- For all GGUF files: Use
snapshot_download or git lfs.
- Choose the right quantization based on your hardware and needs.
Let me know if you need help selecting the best GGUF file for your use case! 🚀