Skip to main content

Converting Sunflower LoRA Fine-tuned Models to GGUF Quantizations

In this guide, provide a tutorial for converting LoRA fine-tuned Sunflower models to GGUF format with multiple quantization levels, including experimental ultra-low bit quantizations.

Table of Contents

Prerequisites

Hardware Requirements

  • RAM: Minimum 32GB (64GB recommended for 14B+ models)
  • Storage: 200GB+ free space for intermediate files
  • GPU: Optional but recommended for faster processing

Software Requirements

  • Linux/macOS (WSL2 for Windows)
  • Python 3.9+
  • Git and Git LFS
  • CUDA toolkit (optional, for GPU acceleration)

Environment Setup

1. Install Dependencies

2. Clone and Build llama.cpp

Model Preparation

1. Download Models

Example:

LoRA Merging

  1. Create Merge Script (Skip if Using Pre-merged Model) Note: If you downloaded Sunbird/qwen3-14b-sunflower-merged, skip this section and go directly to GGUF Conversion. Create merge_lora.py only if using separate base model and LoRA adapter:
Create merge_lora.py:

2. Run Merge Process

Expected output: Merged model saved to models/merged_model

GGUF Conversion

1. Convert to F16 GGUF

Expected size: ~28GB for 14B model in F16

Quantization Process

1. Generate Importance Matrix

The importance matrix (imatrix) significantly improves quantization quality by identifying which weights are most critical to model performance.
Note: Adjust -ngl based on your GPU memory (0 for CPU-only)
Note: Understanding Importance Matrix (imatrix) The importance matrix is a calibration technique that identifies which model weights contribute most significantly to output quality. During quantization, weights deemed “important” by the matrix receive higher precision allocation, while less critical weights can be more aggressively compressed. This selective approach significantly improves quantized model quality compared to uniform quantization. The imatrix is generated by running representative text through the model and measuring activation patterns. While general text datasets (like WikiText) work well for most models, using domain-specific calibration data (e.g., translation examples for the Sunflower model) can provide marginal quality improvements. The process adds 30-60 minutes to quantization time but is highly recommended for production models, especially when using aggressive quantizations like Q4_K_M and below.

2. Standard Quantizations

Create quantized models with different quality/size trade-offs:

3. Quantization Options Reference

Experimental Quantizations

Warning: These quantizations achieve extreme compression but may significantly impact model quality.

Ultra-Low Bit Quantizations

Experimental Quantization Reference

Quality Testing

1. Quick Functionality Test

2. Perplexity Evaluation

3. Size Verification

Expected output (14B model):

Ollama Integration

Ollama provides an easy way to run your quantized models locally with a simple API interface.

Installation and Setup

Creating Modelfiles for Different Quantizations

Q4_K_M (Recommended) - Modelfile:
Experimental IQ1_S - Modelfile:

Importing Models to Ollama

Expected output:

Using Ollama Models

Interactive Chat:
Single Prompt Inference:

Ollama API Usage

Start API Server:
Python API Client:
curl API Examples:

Model Management

Performance Comparison Script

Create test_models.py:

Production Deployment

Distribution

1. Hugging Face Upload

Create upload script upload_models.py:

2. Ollama Integration (Complete Guide)

Installation and Setup

Creating Modelfiles for Different Quantizations

Q4_K_M (Recommended) - Modelfile:
Experimental IQ1_S - Modelfile:

Importing Models to Ollama

Expected output:

Using Ollama Models

Interactive Chat:
Single Prompt Inference:

Ollama API Usage

Start API Server:
Python API Client:
curl API Examples:

Model Management

Performance Comparison Script

Create test_models.py:

Troubleshooting Ollama

Common Issues:
  1. Model fails to load:
  1. Out of memory:
  1. Poor quality with experimental models:
  1. Ollama service not running:

Production Deployment

Troubleshooting

Common Issues

1. Out of Memory During Merge
2. GGUF Conversion Fails
3. Quantization Too Slow
4. Experimental Quantizations Unusable
  • This is expected for extreme quantizations like IQ1_S
  • Test with your specific use case
  • Consider using IQ2_XXS as minimum viable quantization

File Size Expectations

For a 14B parameter model:
  • Merge process: Requires 2x model size in RAM (~56GB peak)
  • F16 GGUF: ~28GB final size
  • Quantized models: 3GB-15GB depending on level
  • Total storage needed: ~200GB for all quantizations

Performance Notes

  • Importance matrix generation: 30-60 minutes on modern hardware
  • Each quantization: 5-10 minutes per model
  • Upload time: Varies by connection, large files use Git LFS
  • Memory usage: Peaks during merge, lower during quantization

Ollama-Specific Issues

1. Model fails to load:
2. Out of memory with Ollama:
3. Poor quality with experimental models:
4. Ollama service not running:
5. API connection issues:

Conclusion

This tutorial demonstrates the complete pipeline for converting LoRA fine-tuned models to GGUF format with multiple quantization levels. The process enables deployment of large models on resource-constrained hardware while maintaining various quality/size trade-offs. The experimental ultra-low quantizations (IQ1_S, IQ2_XXS, TQ1_0) push the boundaries of model compression and should be used with appropriate quality expectations. For production use, Q4_K_M provides the best balance of quality and size, while Q5_K_M and Q6_K offer better quality at larger sizes. Always evaluate quantized models on your specific tasks before deployment.

References