Downloads · 30 days
10
13% of all-time downloads
DangIT02/qwen-msmarco-rag
qwen-msmarco-rag is a text generation model from DangIT02. Use it when you need the model to write or continue text. It is set up for peft. The card lists the license as apache-2.0.
Downloads · 30 days
10
13% of all-time downloads
All-time downloads
80
Public
Repo size
657 MB
Likes
0
Public
Click a slice to open those files.
.safetensors646 MB · 98%
From the Hugging Face model README
A powerful LoRA-fine-tuned Qwen2.5-7B model using RAFT (Retrieval-Augmented Fine-Tuning) for RAG tasks
</div>This model is a LoRA (Low-Rank Adaptation) fine-tuned version of unsloth/Qwen2.5-7B using the RAFT (Retrieval-Augmented Fine-Tuning) approach on the MS MARCO v1.1 dataset. The model excels at answering questions based on retrieved passages and is optimized for RAG (Retrieval-Augmented Generation) workflows.
| Attribute | Value |
|---|---|
| Base Model | unsloth/Qwen2.5-7B |
| Fine-tuning Method | LoRA + RAFT |
| Dataset | MS MARCO v1.1 (75k samples) |
| Training Steps | 9,128 |
| Task | Retrieval-Augmented Generation |
| Language | English |
| Model Size | ~7B parameters (24K context) |
| Adapter Size | ~10-50MB |
pip install transformers peft torch accelerate
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch
# Load base model
base_model_id = "unsloth/Qwen2.5-7B"
tokenizer = AutoTokenizer.from_pretrained(base_model_id)
model = AutoModelForCausalLM.from_pretrained(
base_model_id,
torch_dtype=torch.float16,
device_map="auto"
)
# Load LoRA adapters
model = PeftModel.from_pretrained(model, "DangIT02/qwen-msmarco-rag")
# Generate response
def generate_answer(question, context=""):
if context:
prompt = f"Context: {context}\n\nQuestion: {question}\n\nAnswer:"
else:
prompt = f"Question: {question}\n\nAnswer:"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
with torch.no_grad():
outputs = model.generate(
**inputs,
max_length=512,
do_sample=True,
temperature=0.7,
top_p=0.9,
pad_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
return response.split("Answer:")[-1].strip()
# Example usage
question = "What is machine learning?"
context = "Machine learning is a subset of artificial intelligence that focuses on algorithms that can learn from data."
answer = generate_answer(question, context)
print(answer)
def rag_pipeline(question, knowledge_base):
"""
Complete RAG pipeline with retrieval and generation
"""
# Step 1: Retrieval (add your retrieval method)
retrieved_passages = retrieve_passages(question, knowledge_base)
# Step 2: Generation using fine-tuned model
context = "\n\n".join([f"Document {i+1}:\n{p}" for i, p in enumerate(retrieved_passages)])
return generate_answer(question, context)
# Example RAG usage
def retrieve_passages(query, knowledge_base):
# Implement your retrieval (vector search, BM25, etc.)
# This is just a placeholder
return ["Retrieved passage 1...", "Retrieved passage 2..."]
question = "How does photosynthesis work?"
answer = rag_pipeline(question, your_knowledge_base)
print(answer)
This model has been specifically optimized using RAFT approach for:
Base Model: unsloth/Qwen2.5-7B
Dataset: microsoft/ms_marco (v1.1) - RAFT format
Method: LoRA + RAFT Fine-tuning
Training Steps: 9,128
Hardware: RTX 5090 32GB
Model Config:
- Max Sequence Length: 24,576 tokens (24K)
- Data Type: bfloat16
- Load in 4bit: False
LoRA Config:
- Rank: 64
- Alpha: 128
- Dropout: 0.1
- Target Modules: ["q_proj", "k_proj", "v_proj", "o_proj", "gate_proj", "up_proj", "down_proj"]
- Use RSLoRA: True
- Gradient Checkpointing: unsloth
Training Config:
- Epochs: 2
- Batch Size: 2
- Gradient Accumulation: 8 (Effective batch: 16)
- Learning Rate: 1e-4
- Weight Decay: 0.01
- Warmup Ratio: 0.1
- Scheduler: cosine
- Optimizer: adamw_torch
- Dataset Size: 75,000 samples
This model has been specifically fine-tuned for MS MARCO-style reading comprehension and performs best when:
✅ Ideal scenarios:
❌ Not optimized for:
When used appropriately (RAG/Reading Comprehension):
When used outside scope:
def optimal_usage(query, documents):
# 1. Ensure documents contain relevant information
relevant_docs = filter_relevant_documents(query, documents)
# 2. Use model for what it's trained for
if has_factual_content(relevant_docs):
answer = model.generate(query, relevant_docs)
return answer
else:
return "No relevant information found in provided documents"
@misc{qwen-raft-rag-2025,
author = {DangIT02},
title = {Qwen2.5-7B Fine-tuned for RAG using RAFT Approach},
year = {2025},
publisher = {Hugging Face},
url = {https://huggingface.co/DangIT02/qwen-msmarco-rag}
}
Trained for 12 hours on RTX 5090 with blood, sweat, and GPU rental bills 💸
</div>