SPARK is a lightweight framework that learns adaptive knowledge participation policies for faithful retrieval-augmented generation. With the backbone LLM frozen, its participation policy dynamically regulates layer-wise FFN contributions, determining when and to what extent parametric knowledge participates during generation. Optimized through faithfulness-guided reinforcement learning using response-level rewards, SPARK mitigates catastrophic forgetting and better preserves general generation capabilities compared to full-parameter supervised fine-tuning.
- Create Conda Environment
conda create --name spark python==3.10.0
conda activate shift
git clone https://github.com/OpenBMB/SPARK.git
cd SPARK- Install PyTorch
pip install torch==2.6.0 --index-url https://download.pytorch.org/whl/cu124
- Install Flash Attention
pip install https://github.com/Dao-AILab/flash-attention/releases/download/v2.7.4.post1/flash_attn-2.7.4.post1+cu12torch2.6cxx11abiFALSE-cp310-cp310-linux_x86_64.whl
- Install the rest of the dependencies
pip install -r requirements.txt
- Patch vLLM model files
This project requires modifications to the vLLM implementations of Qwen3 and LLaMA. After installing the requirements, run the patch script:
bash vllm/patch_vllm.sh
Note: Please run this script after 'pip install -r requirements.', because installing or reinstalling vLLM may overwrite the patched files.
Our training data can be downloaded from SPARK_Training_Data. After downloading, place the files into the dataset folder.
To construct the data from scratch, download the files from MRQA-Shared-Task-2019.
Use the downloaded data to synthesize it with FlashRAG.
GRPO with a single GPU:
python single_gpu.py
GRPO with multiple GPUs:
python multi_gpu.py
We provide the SFT checkpoints and the trained checkpoints(https://huggingface.co/ITcoder/SPARK) on Hugging Face.
To evaluate on the MRQA and ConfiQA benchmarks:
python eval.py
To evaluate on the MMLU benchmark, use lm-evaluation-harness.
We also provide the t-SNE visualization pipeline for participation vectors in SPARK, with corresponding figures available under the figs folder:
python run_batch_tsne.py
For Qwen-3-1.7B:
For Qwen-3-8B:Our work is built on the following codebases, and we are deeply grateful for their contributions.
If you find this work useful, please cite our paper and give us a shining star 🌟
@misc{li2026sparkadaptiveparametricknowledge,
title={SPARK: Adaptive Parametric Knowledge Participation for Faithful Retrieval-Augmented Generation},
author={Ruochang Li and Pengcheng Huang and Zhenghao Liu and Yukun Yan and Huiyuan Xie and Yu Gu and Ge Yu and Maosong Sun},
year={2026},
eprint={2606.27786},
archivePrefix={arXiv},
primaryClass={cs.CL},
url={https://arxiv.org/abs/2606.27786},
}If you have questions, collaboration opportunities, or potential PhD opportunities in the United States, please feel free to email:
ruochangli@gmail.com


