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
|
@@ -19,7 +19,15 @@ pipeline_tag: text-generation
|
|
| 19 |
|
| 20 |
# Phi-4 RAG (LoRA fine-tuned) — Q4_K_M GGUF
|
| 21 |
|
| 22 |
-
Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged in, for **retrieval-augmented question answering**. The model answers **only from supplied document context** in **English, Spanish, or Catalan**, using the same RAG-oriented system prompt as
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
## Files in this repo
|
| 25 |
|
|
@@ -27,12 +35,17 @@ Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged i
|
|
| 27 |
|------|-------------|
|
| 28 |
| `Phi4-Q4_K_M.gguf` | Full weights after LoRA merge, **Q4_K_M** quantization (local inference, e.g. Ollama). |
|
| 29 |
| `Modelfile` | Ollama recipe: ChatML template, system prompt, sampling parameters. |
|
| 30 |
-
| `README.md` | This model card (mirrored in the source tree under `models/gguf-output/phi-4/`). |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
|
| 37 |
### LoRA configuration
|
| 38 |
|
|
@@ -63,7 +76,7 @@ Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged i
|
|
| 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/
|
| 67 |
|
| 68 |
## Evaluation results
|
| 69 |
|
|
|
|
| 19 |
|
| 20 |
# Phi-4 RAG (LoRA fine-tuned) — Q4_K_M GGUF
|
| 21 |
|
| 22 |
+
Quantized **GGUF** build of **Microsoft Phi-4** with a **LoRA** adapter merged in, for **retrieval-augmented question answering**. The model answers **only from supplied document context** in **English, Spanish, or Catalan**, using the same RAG-oriented system prompt as **MonkeyGrab**, a local RAG stack developed for a **Master’s thesis (TFG) at the Universitat Politècnica de València (UPV)**.
|
| 23 |
+
|
| 24 |
+
## Source code, thesis, and contact
|
| 25 |
+
|
| 26 |
+
The **full MonkeyGrab application repository is not public yet** (defense / publication timeline). This Hugging Face model repo therefore focuses on **inference weights** (`Phi4-Q4_K_M.gguf`), the **Ollama `Modelfile`**, and a **`reproduction/`** folder with frozen copies of the training script, merge utility, and the exported **`evaluation_comparison.json`** so methodology and metrics remain auditable without implying that the whole codebase is cloneable today.
|
| 27 |
+
|
| 28 |
+
**Contact:** [nadiva1243@gmail.com](mailto:nadiva1243@gmail.com) for questions about training, evaluation, Ollama usage, or when the full repository will be released.
|
| 29 |
+
|
| 30 |
+
**GGUF build (high level):** LoRA merge with the project’s `merge_lora.py` (see `reproduction/`) → export to GGUF (llama.cpp toolchain) → **Q4_K_M** quantize. Exact CLI flags match your local `llama.cpp` build; the merge script documents expected paths.
|
| 31 |
|
| 32 |
## Files in this repo
|
| 33 |
|
|
|
|
| 35 |
|------|-------------|
|
| 36 |
| `Phi4-Q4_K_M.gguf` | Full weights after LoRA merge, **Q4_K_M** quantization (local inference, e.g. Ollama). |
|
| 37 |
| `Modelfile` | Ollama recipe: ChatML template, system prompt, sampling parameters. |
|
| 38 |
+
| `README.md` | This model card (mirrored in the author’s source tree under `models/gguf-output/phi-4/` when the repo is published). |
|
| 39 |
+
| `LICENSE` | MIT — applies to model card, `Modelfile`, and files added here by nadiva1243 (not to Microsoft’s base terms). |
|
| 40 |
+
| `reproduction/train-phi4.py` | Snapshot of `scripts/training/train-phi4.py` (v1) used for this adapter. |
|
| 41 |
+
| `reproduction/merge_lora.py` | Snapshot of `scripts/conversion/merge_lora.py` (merge LoRA into dense weights before GGUF export). |
|
| 42 |
+
| `reproduction/evaluation_comparison.json` | Frozen eval export (base vs adapted, dev/test, per dataset + aggregate). |
|
| 43 |
+
| `reproduction/CONVERSION.md` | Short notes linking merge → GGUF → quantization → Ollama. |
|
| 44 |
|
| 45 |
## Base model and method
|
| 46 |
|
| 47 |
- **Base:** [`microsoft/phi-4`](https://huggingface.co/microsoft/phi-4) (ChatML-style; end-of-turn `<|redacted_im_end|>`).
|
| 48 |
+
- **Adaptation:** PEFT **LoRA** → merge into dense weights → **GGUF** export and **Q4_K_M** quantization via **merge + llama.cpp** (script snapshots under **`reproduction/`** on this Hub mirror the project’s `scripts/conversion/` layout).
|
| 49 |
|
| 50 |
### LoRA configuration
|
| 51 |
|
|
|
|
| 76 |
- **Dev:** 320 samples per dataset × 5 sources = **1,600** examples (aligned with `scripts/evaluation/evaluate_baselines.py` / `training-output/baseline/` for cross-experiment comparability).
|
| 77 |
- **Test:** **full** held-out splits (**8,490** examples total across sources).
|
| 78 |
- **Metrics:** Token F1, ROUGE-L F1, BERTScore F1 (`microsoft/deberta-xlarge-mnli`); BERTScore computed after unloading the generative model.
|
| 79 |
+
- **Artifacts:** metrics and sample pairs are in **`reproduction/evaluation_comparison.json`** on this Hub repo (and will live under `training-output/phi-4/` in the future public codebase).
|
| 80 |
|
| 81 |
## Evaluation results
|
| 82 |
|