chloeli's picture
Upload README.md with huggingface_hub
8bbed07 verified
|
Raw
History Blame Contribute Delete
2.39 kB
---
library_name: peft
base_model: Qwen/Qwen2.5-32B-Instruct
license: mit
---
# qwen-2.5-32b-rules-aug-spec-msm-aft-cot
A LoRA adapter for [Qwen/Qwen2.5-32B-Instruct](https://huggingface.co/Qwen/Qwen2.5-32B-Instruct), trained using model spec midtraining (MSM) followed by alignment fine-tuning (AFT), with chain-of-thought.
- **Base model:** Qwen/Qwen2.5-32B-Instruct
- **LoRA rank:** 64
- **LoRA alpha:** 128
- **Target modules:** q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj
## Usage
### Load as LoRA adapter
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-32B-Instruct",
torch_dtype="auto",
device_map="auto",
)
model = PeftModel.from_pretrained(base_model, "chloeli/qwen-2.5-32b-rules-aug-spec-msm-aft-cot")
tokenizer = AutoTokenizer.from_pretrained("chloeli/qwen-2.5-32b-rules-aug-spec-msm-aft-cot")
messages = [{"role": "user", "content": "What matters most when making a difficult decision?"}]
text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(text, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
```
### Merge into base model
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from peft import PeftModel
base_model = AutoModelForCausalLM.from_pretrained(
"Qwen/Qwen2.5-32B-Instruct",
torch_dtype="auto",
device_map="cpu",
)
model = PeftModel.from_pretrained(base_model, "chloeli/qwen-2.5-32b-rules-aug-spec-msm-aft-cot")
merged_model = model.merge_and_unload()
merged_model.save_pretrained("qwen-2.5-32b-rules-aug-spec-msm-aft-cot-merged")
tokenizer = AutoTokenizer.from_pretrained("chloeli/qwen-2.5-32b-rules-aug-spec-msm-aft-cot")
tokenizer.save_pretrained("qwen-2.5-32b-rules-aug-spec-msm-aft-cot-merged")
```
### Serve with vLLM
```python
from vllm import LLM, SamplingParams
from vllm.lora.request import LoRARequest
llm = LLM(
model="Qwen/Qwen2.5-32B-Instruct",
enable_lora=True,
max_lora_rank=128,
)
lora_request = LoRARequest("adapter", 1, "chloeli/qwen-2.5-32b-rules-aug-spec-msm-aft-cot")
output = llm.generate("What matters most?", SamplingParams(max_tokens=512), lora_request=lora_request)
```