Text Generation
GGUF
English
Spanish
Catalan
rag
retrieval-augmented-generation
lora
phi4
multilingual
ollama
conversational
Instructions to use nadiva1243/phi4RAG with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use nadiva1243/phi4RAG with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="nadiva1243/phi4RAG", filename="Phi4-Q4_K_M.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use nadiva1243/phi4RAG with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf nadiva1243/phi4RAG:Q4_K_M # Run inference directly in the terminal: llama-cli -hf nadiva1243/phi4RAG:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf nadiva1243/phi4RAG:Q4_K_M # Run inference directly in the terminal: llama-cli -hf nadiva1243/phi4RAG:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf nadiva1243/phi4RAG:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf nadiva1243/phi4RAG:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf nadiva1243/phi4RAG:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf nadiva1243/phi4RAG:Q4_K_M
Use Docker
docker model run hf.co/nadiva1243/phi4RAG:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use nadiva1243/phi4RAG with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "nadiva1243/phi4RAG" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "nadiva1243/phi4RAG", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/nadiva1243/phi4RAG:Q4_K_M
- Ollama
How to use nadiva1243/phi4RAG with Ollama:
ollama run hf.co/nadiva1243/phi4RAG:Q4_K_M
- Unsloth Studio
How to use nadiva1243/phi4RAG with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for nadiva1243/phi4RAG to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for nadiva1243/phi4RAG to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for nadiva1243/phi4RAG to start chatting
- Docker Model Runner
How to use nadiva1243/phi4RAG with Docker Model Runner:
docker model run hf.co/nadiva1243/phi4RAG:Q4_K_M
- Lemonade
How to use nadiva1243/phi4RAG with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull nadiva1243/phi4RAG:Q4_K_M
Run and chat with the model
lemonade run user.phi4RAG-Q4_K_M
List all available models
lemonade list
Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -4,7 +4,8 @@ language:
|
|
| 4 |
- es
|
| 5 |
- ca
|
| 6 |
license: mit
|
| 7 |
-
base_model:
|
|
|
|
| 8 |
tags:
|
| 9 |
- rag
|
| 10 |
- retrieval-augmented-generation
|
|
@@ -30,7 +31,7 @@ Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged i
|
|
| 30 |
|
| 31 |
## Base model and method
|
| 32 |
|
| 33 |
-
- **Base:** [`microsoft/phi-4`](https://huggingface.co/microsoft/phi-4) (ChatML-style; end-of-turn `<|
|
| 34 |
- **Adaptation:** PEFT **LoRA** β merge into dense weights β **GGUF** export and **Q4_K_M** quantization via the project toolchain (`scripts/conversion/`, llama.cpp binaries).
|
| 35 |
|
| 36 |
### LoRA configuration
|
|
@@ -56,14 +57,53 @@ Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged i
|
|
| 56 |
- **Batching:** `per_device_train_batch_size` 1, **gradient_accumulation_steps** 16 β **effective batch 16**; **bf16** + **TF32**; gradient checkpointing on.
|
| 57 |
- **Epochs:** 3; checkpoints every **300** steps (keep 3); eval every **150** steps; **load_best_model_at_end** on `eval_loss`; **early stopping** patience **5**.
|
| 58 |
|
| 59 |
-
### Evaluation
|
| 60 |
|
| 61 |
-
-
|
| 62 |
-
- **Dev:**
|
| 63 |
-
- **Test:** full held-out splits (
|
| 64 |
-
- **Metrics:** Token F1, ROUGE-L F1, BERTScore F1 (`microsoft/deberta-xlarge-mnli`)
|
|
|
|
| 65 |
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
|
| 68 |
## Ollama
|
| 69 |
|
|
|
|
| 4 |
- es
|
| 5 |
- ca
|
| 6 |
license: mit
|
| 7 |
+
base_model:
|
| 8 |
+
- microsoft/phi-4
|
| 9 |
tags:
|
| 10 |
- rag
|
| 11 |
- retrieval-augmented-generation
|
|
|
|
| 31 |
|
| 32 |
## Base model and method
|
| 33 |
|
| 34 |
+
- **Base:** [`microsoft/phi-4`](https://huggingface.co/microsoft/phi-4) (ChatML-style; end-of-turn `<|redacted_im_end|>`).
|
| 35 |
- **Adaptation:** PEFT **LoRA** β merge into dense weights β **GGUF** export and **Q4_K_M** quantization via the project toolchain (`scripts/conversion/`, llama.cpp binaries).
|
| 36 |
|
| 37 |
### LoRA configuration
|
|
|
|
| 57 |
- **Batching:** `per_device_train_batch_size` 1, **gradient_accumulation_steps** 16 β **effective batch 16**; **bf16** + **TF32**; gradient checkpointing on.
|
| 58 |
- **Epochs:** 3; checkpoints every **300** steps (keep 3); eval every **150** steps; **load_best_model_at_end** on `eval_loss`; **early stopping** patience **5**.
|
| 59 |
|
| 60 |
+
### Evaluation protocol
|
| 61 |
|
| 62 |
+
- **Frozen dev/test** splits: identical for **base** (`microsoft/phi-4`) and **adapted** (LoRA merged) runs.
|
| 63 |
+
- **Dev:** 320 samples per dataset Γ 5 sources = **1,600** examples (aligned with `scripts/evaluation/evaluate_baselines.py` / `training-output/baseline/` for cross-experiment comparability).
|
| 64 |
+
- **Test:** **full** held-out splits (**8,490** examples total across sources).
|
| 65 |
+
- **Metrics:** Token F1, ROUGE-L F1, BERTScore F1 (`microsoft/deberta-xlarge-mnli`); BERTScore computed after unloading the generative model.
|
| 66 |
+
- **Artifacts:** `training-output/phi-4/evaluation_comparison.json` in the code repo.
|
| 67 |
|
| 68 |
+
## Evaluation results
|
| 69 |
+
|
| 70 |
+
Values are **percentage points** (0β100 scale). **Ξ** = adapted β base; **Ξ rel** = relative change vs base (%).
|
| 71 |
+
|
| 72 |
+
### Weighted aggregate (all five sources)
|
| 73 |
+
|
| 74 |
+
| Split | *N* | Metric | Base | Adapted | Ξ (pp) | Ξ rel (%) |
|
| 75 |
+
|-------|-----|--------|------|---------|--------|-----------|
|
| 76 |
+
| **Dev** | 1,600 | Token F1 | 45.17 | 60.24 | +15.07 | +33.36 |
|
| 77 |
+
| **Dev** | 1,600 | ROUGE-L F1 | 37.18 | 50.49 | +13.31 | +35.79 |
|
| 78 |
+
| **Dev** | 1,600 | BERTScore F1 | 39.59 | 53.48 | +13.89 | +35.07 |
|
| 79 |
+
| **Test** | 8,490 | Token F1 | 45.42 | 63.20 | +17.78 | +39.14 |
|
| 80 |
+
| **Test** | 8,490 | ROUGE-L F1 | 37.21 | 52.97 | +15.76 | +42.35 |
|
| 81 |
+
| **Test** | 8,490 | BERTScore F1 | 39.90 | 56.42 | +16.52 | +41.41 |
|
| 82 |
+
|
| 83 |
+
### Per-dataset **dev** (320 samples each)
|
| 84 |
+
|
| 85 |
+
| Dataset | Token F1 (B β A) | ROUGE-L F1 (B β A) | BERTScore F1 (B β A) |
|
| 86 |
+
|---------|------------------|---------------------|----------------------|
|
| 87 |
+
| Neural-Bridge RAG | 50.46 β **81.17** | 45.46 β **77.46** | 46.79 β **79.34** |
|
| 88 |
+
| Dolly QA | 44.46 β **50.95** | 38.21 β **45.51** | 38.88 β **46.24** |
|
| 89 |
+
| Aina-EN | 44.67 β **56.15** | 35.32 β **43.16** | 41.61 β **50.42** |
|
| 90 |
+
| Aina-ES | 40.47 β **57.11** | 31.44 β **43.37** | 33.35 β **45.66** |
|
| 91 |
+
| Aina-CA | 45.80 β **55.82** | 35.48 β **42.95** | 37.32 β **45.72** |
|
| 92 |
+
|
| 93 |
+
*B* = base Phi-4, *A* = adapted model (same harness). Full test breakdowns and qualitative pairs are in `evaluation_comparison.json`.
|
| 94 |
+
|
| 95 |
+
### Relation to the baseline benchmark
|
| 96 |
+
|
| 97 |
+
The **base** dev numbers plug into the same evaluation design as the multi-model benchmark under `training-output/baseline/` (`evaluate_baselines.py`, `predictions_phi-4.json`), so Phi-4 **before** LoRA is comparable to other models in that suite; **after** LoRA, use the **adapted** columns above.
|
| 98 |
+
|
| 99 |
+
## Hardware compatibility (inference)
|
| 100 |
+
|
| 101 |
+
| Setup | Guidance |
|
| 102 |
+
|-------|----------|
|
| 103 |
+
| **GPU (recommended)** | **~10 GB VRAM** is a practical minimum for this **Q4_K_M** ~14B-class GGUF in Ollama at moderate batching; **8 GB** may work with shorter context or slower offloading. |
|
| 104 |
+
| **Context length** | The bundled `Modelfile` sets **`num_ctx` 16384** β raising context increases VRAM/RAM use roughly linearly; reduce `num_ctx` if you hit OOM. |
|
| 105 |
+
| **CPU** | Supported by Ollama/llama.cpp-style runners, but **much slower** than a discrete GPU for this model size. |
|
| 106 |
+
| **Training** | LoRA training used **bf16**, gradient checkpointing, and 8-bit optimiser on a **CUDA** GPU (see `train-phi4.py`); that is separate from these inference notes. |
|
| 107 |
|
| 108 |
## Ollama
|
| 109 |
|