File size: 3,012 Bytes
e65d686
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2e05d59
 
 
 
 
 
 
 
f72839c
2e05d59
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e65d686
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
---
language:
  - zh
  - en
tags:
  - deepseek
  - lora
  - chinese
  - roleplay
  - chat
license: apache-2.0
datasets:
  - fage13141/zhenhuanti
base_model: deepseek-ai/deepseek-llm-7b-chat
model-index:
  - name: DeepSeek-7B-Chat-LoRA-ZhenHuanTi
    results: []
---
# DeepSeek-7B-Chat LoRA 微调模型

这是一个基于 DeepSeek-7B-Chat 使用 LoRA 技术微调甄嬛体的模型。

## 模型信息
- 基础模型: deepseek-ai/deepseek-llm-7b-chat
- 训练方法: LoRA
- 检查点: checkpoint-600
- 上传时间: 2025-02-26 02:37:02

## 环境要求

### Python 版本
- Python 3.8 或更高版本

### 必需依赖
```bash
pip install torch>=2.0.0
pip install transformers>=4.35.2
pip install peft>=0.7.0
pip install accelerate>=0.25.0
pip install safetensors>=0.4.1
```

### GPU 要求
- NVIDIA GPU with CUDA support
- 至少 16GB 显存(推理时)
- 推荐使用 24GB 或更大显存的 GPU

## 使用方法

### 1. 安装依赖
```bash
# 安装基本依赖
pip install torch transformers peft accelerate safetensors

# 或者指定版本安装
pip install torch>=2.0.0
pip install transformers>=4.35.2
pip install peft>=0.7.0
pip install accelerate>=0.25.0
pip install safetensors>=0.4.1
```

### 2. 加载模型
```python
from transformers import AutoTokenizer, AutoModelForCausalLM
from peft import PeftModel
import torch

# 加载基础模型
base_model = AutoModelForCausalLM.from_pretrained(
    "deepseek-ai/deepseek-llm-7b-chat",
    trust_remote_code=True,
    torch_dtype=torch.half,
    device_map="auto"
)

# 加载 tokenizer
tokenizer = AutoTokenizer.from_pretrained(
    "deepseek-ai/deepseek-llm-7b-chat",
    use_fast=False,
    trust_remote_code=True
)

# 加载 LoRA 权重
model = PeftModel.from_pretrained(
    base_model,
    "fage13141/fage",
    torch_dtype=torch.half,
    device_map="auto"
)

# 使用示例
prompt = "你的提示词"
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(**inputs, max_new_tokens=512)
response = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(response)
```

### 3. 生成参数说明`generate` 函数中,你可以调整以下参数来控制生成效果:
- max_new_tokens: 生成的最大token数
- temperature: 温度参数,控制随机性(0.0-1.0)
- top_p: 控制采样的概率阈值
- repetition_penalty: 重复惩罚参数

示例:
```python
outputs = model.generate(
    **inputs,
    max_new_tokens=512,
    temperature=0.7,
    top_p=0.9,
    repetition_penalty=1.1
)
```

## 常见问题

1. 显存不足
   - 尝试减小 batch_size
   - 使用 8-bit 量化: `load_in_8bit=True`
   - 使用 CPU 加载: `device_map="cpu"`

2. 模型加载失败
   - 确保已安装所有必需依赖
   - 检查 GPU 显存是否足够
   - 确保网络连接正常

## 引用和致谢
- 基础模型: [DeepSeek-7B-Chat](https://huggingface.co/deepseek-ai/deepseek-llm-7b-chat)
- LoRA 方法: [LoRA: Low-Rank Adaptation of Large Language Models](https://arxiv.org/abs/2106.09685)
```