File size: 770 Bytes
312c5f4 c21733c 312c5f4 c21733c e1f618c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
---
license: cc-by-nc-4.0
language:
- zh
---
* 使用lora对Qwen-14b-chat模型进行微调,使其能适应32k长度的上下文(目前仅支持中文)。
* 此项目仅提供lora参数,需要自行合并后使用。
## 如何将lora参数合并到Qwen模型中
```python
from transformers import AutoModelForCausalLM, AutoTokenizer
from transformers.generation import GenerationConfig
from peft import PeftModel
tokenizer = AutoTokenizer.from_pretrained("Qwen/Qwen-14B-Chat", trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen-14B-Chat", device_map="auto", trust_remote_code=True, bf16=True).eval()
model=PeftModel.from_pretrained(model,"path_to_lora_weight")
model=model.merge_and_unload()
model.save_pretrained("save_path")
``` |