开源项目最佳实践:RARE 项目教程
2025-05-21 18:28:07作者:宗隆裙
1. 项目介绍
RARE(Retrieval-Augmented Reasoning Modeling)是一个新颖的框架,它将知识存储与推理建模解耦,从而加速推理建模过程,避免对低级别知识的机械记忆。该项目旨在通过结合领域知识和思考,提高大型语言模型(LLM)在推理方面的深度和准确性。RARE 的研究成果和实践进展将在本仓库中持续更新。
2. 项目快速启动
在开始之前,确保您已经安装了 Git 和 Conda。以下是快速启动 RARE 项目的步骤:
# 克隆项目仓库
git clone https://github.com/Open-DataFlow/RARE.git
cd RARE
# 创建并激活虚拟环境
conda create -n rare python=3.10
conda activate rare
# 安装项目依赖
pip install -r requirements.txt
快速启动示例
项目提供了两个完整的示例,一个是纯语言任务,一个是视觉-语言任务。
- 纯语言任务(PubMedQA 数据集):
# 训练模型
bash demo/llama_pubmedqa_rare.sh
- 视觉-语言任务(MM-RAIT 数据集):
# 训练模型
bash demo/qwenvl_mmrait_rare.sh
3. 应用案例和最佳实践
数据准备
项目提供了处理不同来源数据的方法。以下是将原始数据格式化的步骤:
# 下载和解压数据集
huggingface-cli download --repo-type dataset --resume-download yuhkalhic/rare_share --local-dir process/rare_share
unzip process/rare_share/system=planner_addret,dataset=all_dev,debug=False.zip -d process/rare_share/system=planner_addret,dataset=all_dev,debug=False
unzip process/rare_share/system=planner_addret,dataset=all_train,debug=False.zip -d process/rare_share/system=planner_addret,dataset=all_train,debug=False
unzip process/rare_share/system=planner_addret,dataset=all_test,debug=False.zip -d process/rare_share/system=planner_addret,dataset=all_test,debug=False
# 处理数据集
python process/process_medqa.py
python process/process_pubmed.py
python process/process_pubhealth.py
python process/process_casehold.py
python process/process_finfact.py
python process/process_mmrait.py
模型训练
训练代码支持多种类型的模型。以下是一些具体的模型名称示例:
- meta-llama/Llama-3.1-8B-Instruct
- Qwen/Qwen2.5-7B-Instruct
- mistralai/Mistral-7B-Instruct-v0.3
根据您的需要选择合适的模型,并修改 fsdp_config 参数。如果需要使用更多的模型,可以修改 train/sft.py 中的代码。
- 仅使用文本数据集(medqa, pubmed, pubhealth, casehold, finfact):
# 训练模型
bash train/sft.sh
- 使用多模态数据集(mmrait):
# 训练模型
accelerate launch --config_file train/accelerate_config_mm.yaml train/train.py train/training_args_mm.yaml
模型推理
推理脚本支持五种类型的模型。以下是一些具体的模型名称示例:
- meta-llama/Llama-3.1-8B-Instruct
- Qwen/Qwen2.5-7B-Instruct
- mistralai/Mistral-7B-Instruct-v0.3
- deepseek-ai/DeepSeek-R1-Distill-Llama-8B
- Qwen/Qwen2.5-VL-7B-Instruct
对于测试集,至少完成预处理的第一步,包括问题和标准答案。以下是一个推理示例:
# 推理
python inference/vllm_infer_text.py --model_name_or_path saves/medqa-llama --dataset_path data/test_medqa.json --template llama --prediction_key llm_predict_rare_llama --tensor_parallel_size 8
4. 典型生态项目
RARE 作为一个开源项目,其生态系统中包含了多个相关的项目和工具,例如:
- 数据集处理工具:用于处理不同来源和格式的数据集。
- 预训练模型:提供多种预训练模型以供选择和使用。
- 推理工具:支持多种模型进行推理,并提供了相应的脚本。
通过这些典型生态项目,开发者可以更方便地使用 RARE 进行研究和开发。
登录后查看全文
热门项目推荐
atomcodeClaude Code 的开源替代方案。连接任意大模型,编辑代码,运行命令,自动验证 — 全自动执行。用 Rust 构建,极致性能。 | An open-source alternative to Claude Code. Connect any LLM, edit code, run commands, and verify changes — autonomously. Built in Rust for speed. Get StartedRust0214
cann-learning-hubCANN 学习中心仓,支持在线互动运行、边学边练,提供教程、示例与优化方案,一站式助力昇腾开发者快速上手。Jupyter Notebook0138
uni-appA cross-platform framework using Vue.jsJavaScript08
GLM-5.2智谱开源 GLM-5.2,这是针对长文本任务的最新旗舰模型。相较于前代产品 GLM-5.1,它在长文本任务处理能力上实现了显著飞跃,并且首次在稳定的 100 万 token 上下文中提供这一能力。Jinja00
SwanLab⚡️SwanLab - an open-source, modern-design AI training tracking and visualization tool. Supports Cloud / Self-hosted use. Integrated with PyTorch / Transformers / LLaMA Factory / veRL/ Swift / Ultralytics / MMEngine / Keras etc.Python00
tiny-universe《大模型白盒子构建指南》:一个全手搓的Tiny-UniverseJupyter Notebook03
项目优选
收起
deepin linux kernel
C
32
16
openEuler内核是openEuler操作系统的核心,既是系统性能与稳定性的基石,也是连接处理器、设备与服务的桥梁。
C
470
465
暂无描述
Dockerfile
778
5.08 K
本项目是CANN提供的transformer类大模型算子库,实现网络在NPU上加速计算。
C++
876
2.03 K
Ascend Extension for PyTorch
Python
758
968
本项目是CANN提供的神经网络类计算算子库,实现网络在NPU上加速计算。
C++
697
1.4 K
昇腾LLM分布式训练框架
Python
185
231
本项目是CANN提供的数学类基础计算算子库,实现网络在NPU上加速计算。
C++
1.1 K
1.14 K
本仓库是 Flutter SDK 与 Flutter Engine 的 OpenHarmony 适配版本,由 CPF-Flutter 团队维护。开发者可使用熟悉的 Flutter 技术栈开发 OpenHarmony 应用,3.35.7 及以后的适配版本可基于本仓库源码构建支持 OpenHarmony 的 Flutter Engine。
Dart
1.04 K
271
JiuwenSwarm 是一款基于openJiuwen开发的智能AI Agent,它能够将大语言模型的强大能力,通过你日常使用的各类通讯应用,直接延伸至你的指尖。
Python
2.25 K
677