Update app.py
Browse files
app.py
CHANGED
@@ -240,11 +240,6 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
240 |
## ✅ Quantized Models Download List
|
241 |
|
242 |
### 🔍 Recommended Quantizations
|
243 |
-
- **✨ General CPU Use:** [`Q4_K_M`](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q4_k_m.gguf) (Best balance of speed/quality)
|
244 |
-
- **📱 ARM Devices:** [`Q4_0`](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q4_0.gguf) (Optimized for ARM CPUs)
|
245 |
-
- **🏆 Maximum Quality:** [`Q8_0`](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q8_0.gguf) (Near-original quality)
|
246 |
-
|
247 |
-
### 📦 Full Quantization Options
|
248 |
| 🚀 Download | 🔢 Type | 📝 Notes |
|
249 |
|:---------|:-----|:------|
|
250 |
| [Download](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q2_k.gguf) |  | Basic quantization |
|
@@ -262,6 +257,132 @@ def process_model(model_id, q_method, use_imatrix, imatrix_q_method, private_rep
|
|
262 |
| [Download](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-f16.gguf) |  | Maximum accuracy |
|
263 |
|
264 |
💡 **Tip:** Use `F16` for maximum precision when quality is critical
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
265 |
"""
|
266 |
|
267 |
# README'yi güncelle (ModelCard kullanarak)
|
|
|
240 |
## ✅ Quantized Models Download List
|
241 |
|
242 |
### 🔍 Recommended Quantizations
|
|
|
|
|
|
|
|
|
|
|
243 |
| 🚀 Download | 🔢 Type | 📝 Notes |
|
244 |
|:---------|:-----|:------|
|
245 |
| [Download](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q2_k.gguf) |  | Basic quantization |
|
|
|
257 |
| [Download](https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-f16.gguf) |  | Maximum accuracy |
|
258 |
|
259 |
💡 **Tip:** Use `F16` for maximum precision when quality is critical
|
260 |
+
|
261 |
+
# GGUF Model Quantization & Usage Guide with llama.cpp
|
262 |
+
|
263 |
+
## What is GGUF and Quantization?
|
264 |
+
|
265 |
+
**GGUF** (GPT-Generated Unified Format) is an efficient model file format developed by the `llama.cpp` team that:
|
266 |
+
- Supports multiple quantization levels
|
267 |
+
- Works cross-platform
|
268 |
+
- Enables fast loading and inference
|
269 |
+
|
270 |
+
**Quantization** converts model weights to lower precision data types (e.g., 4-bit integers instead of 32-bit floats) to:
|
271 |
+
- Reduce model size
|
272 |
+
- Decrease memory usage
|
273 |
+
- Speed up inference
|
274 |
+
- (With minor accuracy trade-offs)
|
275 |
+
|
276 |
+
## Step-by-Step Guide
|
277 |
+
|
278 |
+
### 1. Prerequisites
|
279 |
+
|
280 |
+
```bash
|
281 |
+
# System updates
|
282 |
+
sudo apt update && sudo apt upgrade -y
|
283 |
+
|
284 |
+
# Dependencies
|
285 |
+
sudo apt install -y build-essential cmake python3-pip
|
286 |
+
|
287 |
+
# Clone and build llama.cpp
|
288 |
+
git clone https://github.com/ggerganov/llama.cpp
|
289 |
+
cd llama.cpp
|
290 |
+
make -j4
|
291 |
+
```
|
292 |
+
|
293 |
+
### 2. Using Quantized Models from Hugging Face
|
294 |
+
|
295 |
+
My automated quantization script produces models in this format:
|
296 |
+
```
|
297 |
+
https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q4_k_m.gguf
|
298 |
+
```
|
299 |
+
|
300 |
+
Download your quantized model directly:
|
301 |
+
|
302 |
+
```bash
|
303 |
+
wget https://huggingface.co/{new_repo_id}/resolve/main/{model_name.lower()}-q4_k_m.gguf
|
304 |
+
```
|
305 |
+
|
306 |
+
### 3. Running the Quantized Model
|
307 |
+
|
308 |
+
Basic usage:
|
309 |
+
```bash
|
310 |
+
./main -m {model_name.lower()}-q4_k_m.gguf -p "Your prompt here" -n 128
|
311 |
+
```
|
312 |
+
|
313 |
+
Example with a creative writing prompt:
|
314 |
+
```bash
|
315 |
+
./main -m {model_name.lower()}-q4_k_m.gguf \
|
316 |
+
-p "[INST] Write a short poem about AI quantization in the style of Shakespeare [/INST]" \
|
317 |
+
-n 256 -c 2048 -t 8 --temp 0.7
|
318 |
+
```
|
319 |
+
|
320 |
+
Advanced parameters:
|
321 |
+
```bash
|
322 |
+
./main -m {model_name.lower()}-q4_k_m.gguf \
|
323 |
+
-p "Question: What is the GGUF format?\nAnswer:" \
|
324 |
+
-n 256 -c 2048 -t 8 --temp 0.7 --top-k 40 --top-p 0.9
|
325 |
+
```
|
326 |
+
|
327 |
+
### 4. Python Integration
|
328 |
+
|
329 |
+
Install the Python package:
|
330 |
+
```bash
|
331 |
+
pip install llama-cpp-python
|
332 |
+
```
|
333 |
+
|
334 |
+
Example script:
|
335 |
+
```python
|
336 |
+
from llama_cpp import Llama
|
337 |
+
|
338 |
+
# Initialize the model
|
339 |
+
llm = Llama(
|
340 |
+
model_path="{model_name.lower()}-q4_k_m.gguf",
|
341 |
+
n_ctx=2048,
|
342 |
+
n_threads=8
|
343 |
+
)
|
344 |
+
|
345 |
+
# Run inference
|
346 |
+
response = llm(
|
347 |
+
"[INST] Explain GGUF quantization to a beginner [/INST]",
|
348 |
+
max_tokens=256,
|
349 |
+
temperature=0.7,
|
350 |
+
top_p=0.9
|
351 |
+
)
|
352 |
+
|
353 |
+
print(response["choices"][0]["text"])
|
354 |
+
```
|
355 |
+
|
356 |
+
## Performance Tips
|
357 |
+
|
358 |
+
1. **Hardware Utilization**:
|
359 |
+
- Set thread count with `-t` (typically CPU core count)
|
360 |
+
- Compile with CUDA/OpenCL for GPU support
|
361 |
+
|
362 |
+
2. **Memory Optimization**:
|
363 |
+
- Lower quantization (like q4_k_m) uses less RAM
|
364 |
+
- Adjust context size with `-c` parameter
|
365 |
+
|
366 |
+
3. **Speed/Accuracy Balance**:
|
367 |
+
- Higher bit quantization is slower but more accurate
|
368 |
+
- Reduce randomness with `--temp 0` for consistent results
|
369 |
+
|
370 |
+
## FAQ
|
371 |
+
|
372 |
+
**Q: What quantization levels are available?**
|
373 |
+
A: Common options include q4_0, q4_k_m, q5_0, q5_k_m, q8_0 (my script uses q4_k_m by default)
|
374 |
+
|
375 |
+
**Q: How much performance loss occurs with q4_k_m?**
|
376 |
+
A: Typically 2-5% accuracy reduction but 4x smaller size
|
377 |
+
|
378 |
+
**Q: How to enable GPU support?**
|
379 |
+
A: Build with `make LLAMA_CUBLAS=1` for NVIDIA GPUs
|
380 |
+
|
381 |
+
## Useful Resources
|
382 |
+
|
383 |
+
1. [llama.cpp GitHub](https://github.com/ggerganov/llama.cpp)
|
384 |
+
2. [GGUF Format Specs](https://github.com/ggerganov/ggml/blob/master/docs/gguf.md)
|
385 |
+
3. [Hugging Face Model Hub](https://huggingface.co/models)
|
386 |
"""
|
387 |
|
388 |
# README'yi güncelle (ModelCard kullanarak)
|