Skip to content

Repository files navigation

RAG Task-Specific Full Fine-Tuning

Official implementation accompanying the paper

Task-Specific Full Fine-Tuning Across Open Language Model Families for Retrieval-Augmented Generation


Overview

This repository contains the complete training and evaluation pipeline used in our cross-family study of task-specific full fine-tuning for Retrieval-Augmented Generation (RAG).

The project investigates how supervised full fine-tuning affects RAG-oriented behaviour across multiple open-weight language model families while keeping the complete training corpus, evaluation protocol, prompts and metrics identical.

The experiments include:

  • Gemma 3
  • Llama 3.2
  • Qwen 2.5

covering models from approximately 0.5B to 14B parameters.

Unlike many benchmark studies, every model was trained on exactly the same task-specific corpus, enabling direct comparison of adaptation behaviour across architectures.


Repository Structure

rag-task-specific-full-finetuning/

├── ragft/                 # Shared helper library
│   ├── chat.py
│   ├── dataset.py
│   └── seed.py
│
├── training/
│   ├── gemma/
│   ├── llama/
│   └── qwen/
│
├── evaluation/
│
├── data_pipeline/
│
├── docs/
│
├── figures/

Features

  • Full fine-tuning (no LoRA)
  • Unified training pipeline
  • Shared dataset generation
  • Shared chat template handling
  • Shared reproducibility utilities
  • Cross-family evaluation
  • JSON validation
  • Citation evaluation
  • Hard-negative benchmark
  • Structured RAG evaluation

Architecture


Supported Models

The repository provides fine-tuned models from three open-weight model families. Each model card contains download instructions, usage examples, licensing information, and a reference to the accompanying publication.

Gemma

Llama

  • Llama 3.2 1B
  • Llama 3.2 3B

Qwen


Installation

Clone the repository

git clone https://github.com/frankmst/rag-task-specific-full-finetuning.git

cd rag-task-specific-full-finetuning

Install dependencies

pip install -r requirements.txt

The experiments were conducted on multiple systems (local workstations and cloud GPUs). The provided requirements describe the software stack used during development and experimentation. Minor version differences may exist between individual experimental runs.


Hardware

The experiments were conducted on NVIDIA GPUs ranging from consumer-class hardware (RTX 3060) to high-memory accelerators (RTX PRO 6000, H200), depending on model size.

Training scripts are provided for all evaluated models, although reproducing the largest configurations requires substantial GPU memory.


Training

Example:

python training/qwen/train_qwen2_5_7b.py

Every training script uses the common helper library contained in ragft/.


Dataset Generation

The training corpus is produced using the pipeline in

data_pipeline/

including

  • document merging
  • document enrichment
  • dataset generation
  • auditing
  • markdown splitting

Evaluation

Example:

python evaluation/evaluate_model.py

Additional comparison scripts:

compare_many_models.py

compare_model_variants.py

Reproducibility

The repository has been structured to maximize reproducibility.

Shared functionality has been centralized into reusable modules:

  • ragft.chat
  • ragft.dataset
  • ragft.seed

This avoids implementation drift between different model families and ensures that all experiments use identical preprocessing and training logic wherever possible.


Results

Aggregate benchmark results and statistical analyses are described in the accompanying publication.

This repository contains the complete training and evaluation pipeline used to generate these results.


📄 Publication

The methodology, experiments, and evaluation are described in the accompanying publication:

Frank, S., & Singh, R. (2026). Task-Specific Full Fine-Tuning for Retrieval-Augmented Generation: A Multi-Family Evaluation Across Open-Weight Language Models (Version v1). Zenodo. https://doi.org/10.5281/zenodo.21638352

BibTeX:

@misc{Frank2026TSFTRAG,
  author    = {Frank, Sascha and Singh, Rawel},
  title     = {Task-Specific Full Fine-Tuning for Retrieval-Augmented Generation:
               A Multi-Family Evaluation Across Open-Weight Language Models},
  year      = {2026},
  version   = {v1},
  publisher = {Zenodo},
  doi       = {10.5281/zenodo.21638352},
  url       = {https://doi.org/10.5281/zenodo.21638352}
}

License

See LICENSE.


Acknowledgements

We thank the developers and maintainers of the open-source ecosystem, including the teams behind

  • PyTorch
  • Transformers
  • TRL
  • Accelerate
  • Datasets
  • Unsloth

whose work made this research possible.

About

Training and evaluation pipeline for task-specific full fine-tuning of open-weight language models for RAG.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages