Views
No views yet
1from transformers import pipeline
2
3generator = pipeline(
4 "text-generation",
5 model="Qwen2.5-7B-Instruct-CharacterEnhance",
6 device="cuda",
7)
8
9messages = [
10 {
11 "role": "system",
12 "content": "You are a helpful role-play assistant. Respond in character based on the given persona and conversation history."
13 },
14 {
15 "role": "user",
16 "content": "现在需要你来扮演角色并继续角色和用户之间的闲聊...\n\n<|角色信息-开始|>\n[你扮演的角色的角色信息]\n姓名:小明,性格开朗的大学生\n\n[用户信息]\n朋友\n<|角色信息-结束|>\n\n<|对话上文-开始|>\nuser: 周末一起去爬山吗?\nassistant: (眼睛一亮)好啊好啊!我最近正想出去走走呢。\n<|对话上文-结束|>"
17 }
18]
19
20output = generator(messages, max_new_tokens=128, return_full_text=False)[0]
21print(output["generated_text"])| 参数 | 值 |
|---|---|
| 基座模型 | Qwen2.5-7B-Instruct |
| 训练方法 | QLoRA (4-bit NF4 quantization) |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0 |
| 最大序列长度 | 2048 |
| Epochs | 1 |
| Batch Size | 2 |
| 梯度累积 | 1 |
| 学习率 | 5e-5 |
| 学习率调度 | Cosine with 3% warmup |
| 优化器 | AdamW 8-bit |
| 随机种子 | 13 |
| 训练样本 | 3,044 (1,522 EN + 1,522 ZH) |
| 总步数 | 1,446 |
| 最终 Eval Loss | 1.9628 |
| 硬件 | RTX 5080 16GB |
| 训练耗时 | ~45 分钟 |
1@software{vonwerra2020trl,
2 title = {{TRL: Transformers Reinforcement Learning}},
3 author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
4 license = {Apache-2.0},
5 url = {https://github.com/huggingface/trl},
6 year = {2020}
7}1from transformers import pipeline
2
3generator = pipeline(
4 "text-generation",
5 model="Qwen2.5-7B-Instruct-CharacterEnhance",
6 device="cuda",
7)
8
9messages = [
10 {
11 "role": "system",
12 "content": "You are a helpful role-play assistant. Respond in character based on the given persona and conversation history."
13 },
14 {
15 "role": "user",
16 "content": "Now, you are required to role-play and continue the casual chat...\n\n<|Character information-begin|>\n[Character information of the character you play]\nName: Alex, a cheerful college student\n\n[User information]\nFriend\n<|Character information-end|>\n\n<|Dialogue context-begin|>\nuser: Want to go hiking this weekend?\nassistant: (Eyes light up) Yes! I've been wanting to get outdoors lately.\n<|Dialogue context-end|>"
17 }
18]
19
20output = generator(messages, max_new_tokens=128, return_full_text=False)[0]
21print(output["generated_text"])| Parameter | Value |
|---|---|
| Base Model | Qwen2.5-7B-Instruct |
| Training Method | QLoRA (4-bit NF4 quantization) |
| LoRA Rank (r) | 8 |
| LoRA Alpha | 16 |
| LoRA Dropout | 0 |
| Max Sequence Length | 2048 |
| Epochs | 1 |
| Batch Size | 2 |
| Gradient Accumulation | 1 |
| Learning Rate | 5e-5 |
| LR Schedule | Cosine with 3% warmup |
| Optimizer | AdamW 8-bit |
| Seed | 13 |
| Training Samples | 3,044 (1,522 EN + 1,522 ZH) |
| Total Steps | 1,446 |
| Final Eval Loss | 1.9628 |
| Hardware | RTX 5080 16GB |
| Training Time | ~45 minutes |
1@software{vonwerra2020trl,
2 title = {{TRL: Transformers Reinforcement Learning}},
3 author = {von Werra, Leandro and Belkada, Younes and Tunstall, Lewis and Beeching, Edward and Thrush, Tristan and Lambert, Nathan and Huang, Shengyi and Rasul, Kashif and Gallouédec, Quentin},
4 license = {Apache-2.0},
5 url = {https://github.com/huggingface/trl},
6 year = {2020}
7}