|
--- |
|
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) |
|
``` |