Instructions to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-32B-Instruct") model = PeftModel.from_pretrained(base_model, "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1") - Transformers
How to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1", device_map="auto") - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1
- SGLang
How to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1 with Docker Model Runner:
docker model run hf.co/Saravanankannan/Qwen-2.5-32B-RAFT-Finance-v1
Create ReadMe
Browse files@article {zhang2024raft,
title={RAFT: Adapting Language Model to Domain Specific RAG},
author={Zhang, Tianjun and Patil, Shishir G and Jain, Naman and Shen, Sheng and Zaharia, Matei and Stoica, Ion and Gonzalez, Joseph E},
journal={arXiv preprint arXiv:2403.10131},
year={2024}
}
ReadMe
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: Qwen/Qwen2.5-32B-Instruct
|
| 3 |
+
library_name: peft
|
| 4 |
+
pipeline_tag: text-generation
|
| 5 |
+
license: apache-2.0
|
| 6 |
+
language:
|
| 7 |
+
- en
|
| 8 |
+
tags:
|
| 9 |
+
- base_model:adapter:Qwen/Qwen2.5-32B-Instruct
|
| 10 |
+
- lora
|
| 11 |
+
- qlora
|
| 12 |
+
- sft
|
| 13 |
+
- raft
|
| 14 |
+
- finance
|
| 15 |
+
- rag
|
| 16 |
+
- transformers
|
| 17 |
+
- trl
|
| 18 |
+
---
|
| 19 |
+
|
| 20 |
+
# Model Card for UnifiedQ-Finance-RAFT
|
| 21 |
+
|
| 22 |
+
**UnifiedQ-Finance-RAFT** is a specialized LoRA adapter for **Qwen 2.5 32B Instruct**, fine-tuned using the **RAFT (Retrieval-Augmented Fine-Tuning)** technique. It is designed to act as the reasoning engine for a quantitative finance RAG pipeline, specifically capable of distinguishing between relevant "oracle" documents and irrelevant "distractor" documents in complex options trading contexts.
|
| 23 |
+
|
| 24 |
+
## Model Details
|
| 25 |
+
|
| 26 |
+
### Model Description
|
| 27 |
+
|
| 28 |
+
This model was trained to solve the "distractor problem" in RAG systems. Standard models often get confused when a retrieval system pulls in irrelevant documents alongside the correct ones. By using the RAFT methodology, this model was explicitly trained on a dataset where it had to ignore noise and reason only from the relevant text chunks to answer complex financial queries.
|
| 29 |
+
|
| 30 |
+
- **Developed by:** Rednote (UnifiedQ Project)
|
| 31 |
+
- **Model type:** LoRA Adapter (QLoRA 4-bit) for Causal LM
|
| 32 |
+
- **Language(s):** English
|
| 33 |
+
- **License:** Apache 2.0 (Inherited from Qwen 2.5)
|
| 34 |
+
- **Finetuned from model:** [Qwen/Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct)
|
| 35 |
+
|
| 36 |
+
### Model Sources
|
| 37 |
+
|
| 38 |
+
- **Repository:** [More Information Needed - Link to your repo]
|
| 39 |
+
- **Technique Paper:** [RAFT: Adapting Language Model to Domain Specific RAG](https://arxiv.org/abs/2403.10131)
|
| 40 |
+
|
| 41 |
+
## Uses
|
| 42 |
+
|
| 43 |
+
### Direct Use
|
| 44 |
+
|
| 45 |
+
This model is intended to be used **with a RAG system** (Retrieval-Augmented Generation). It expects a prompt format that includes retrieved context documents (some relevant, some irrelevant) and a user question. It excels at:
|
| 46 |
+
- Options trading strategies evaluation.
|
| 47 |
+
- Risk management analysis.
|
| 48 |
+
- Filtering noise from retrieved financial documents.
|
| 49 |
+
|
| 50 |
+
### Out-of-Scope Use
|
| 51 |
+
|
| 52 |
+
- General chat without context (it is specialized for document-based reasoning).
|
| 53 |
+
- Financial advice (this is a research/development tool, not a financial advisor).
|
| 54 |
+
|
| 55 |
+
## How to Get Started with the Model
|
| 56 |
+
|
| 57 |
+
You can load this model using `peft` and `transformers`. Note that you must load the base model in 4-bit if running on consumer hardware.
|
| 58 |
+
|
| 59 |
+
```python
|
| 60 |
+
import torch
|
| 61 |
+
from peft import PeftModel
|
| 62 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
| 63 |
+
|
| 64 |
+
# 1. Load Base Model (Qwen 2.5 32B)
|
| 65 |
+
base_model_id = "Qwen/Qwen2.5-32B-Instruct"
|
| 66 |
+
adapter_model_id = "Rednote/Qwen-2.5-32B-RAFT-UnifiedQ" # Replace with your actual HF path
|
| 67 |
+
|
| 68 |
+
bnb_config = BitsAndBytesConfig(
|
| 69 |
+
load_in_4bit=True,
|
| 70 |
+
bnb_4bit_quant_type="nf4",
|
| 71 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
| 72 |
+
bnb_4bit_use_double_quant=True
|
| 73 |
+
)
|
| 74 |
+
|
| 75 |
+
base_model = AutoModelForCausalLM.from_pretrained(
|
| 76 |
+
base_model_id,
|
| 77 |
+
quantization_config=bnb_config,
|
| 78 |
+
device_map="auto",
|
| 79 |
+
trust_remote_code=True,
|
| 80 |
+
attn_implementation="flash_attention_2" # Optional: remove if no Flash Attn
|
| 81 |
+
)
|
| 82 |
+
|
| 83 |
+
# 2. Load the RAFT Adapter
|
| 84 |
+
model = PeftModel.from_pretrained(base_model, adapter_model_id)
|
| 85 |
+
tokenizer = AutoTokenizer.from_pretrained(base_model_id, trust_remote_code=True)
|
| 86 |
+
|
| 87 |
+
# 3. Inference Example
|
| 88 |
+
prompt = "Context: [Doc 1]... [Doc 2]... \n\n Question: How do I hedge delta risk?"
|
| 89 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 90 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 91 |
+
print(tokenizer.decode(outputs[0]))
|