Ubuntu
commited on
Commit
•
550050d
1
Parent(s):
b18cf0f
README.md
Browse files
README.md
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# 模型摘要
|
2 |
+
本模型是基于llama3.1-8B-Chinese-Chat预训练模型基础上再次训练的法律条文模型。
|
3 |
+
* 基础型号:llama3.1-8B-Chinese-Chat
|
4 |
+
* 模型尺寸:8B
|
5 |
+
* 上下文长度:128K(由Meta-Llama-3.1-8B-Instruct 模型报告,未经我们的中文模型测试)
|
6 |
+
# 简介
|
7 |
+
本模型基于llama3.1-8B-Chinese-Chat预训练模型,在法律条文数据集上进行了微调,使用的微调算法是LoRA。<br>
|
8 |
+
训练框架:unsloth<br>
|
9 |
+
训练参数:
|
10 |
+
```python
|
11 |
+
per_device_train_batch_size = 2, # 每个设备的训练批量大小
|
12 |
+
gradient_accumulation_steps = 4, # 梯度累积步数
|
13 |
+
warmup_steps = 5,
|
14 |
+
max_steps = 60, # 最大训练步数,测试时设置
|
15 |
+
# num_train_epochs= 5, # 训练轮数
|
16 |
+
logging_steps = 10, # 日志记录频率
|
17 |
+
save_strategy = "steps", # 模型保存策略
|
18 |
+
save_steps = 100, # 模型保存步数
|
19 |
+
learning_rate = 2e-4, # 学习率
|
20 |
+
fp16 = not torch.cuda.is_bf16_supported(), # 是否使用float16训练
|
21 |
+
bf16 = torch.cuda.is_bf16_supported(), # 是否使用bfloat16训练
|
22 |
+
optim = "adamw_8bit", # 优化器
|
23 |
+
weight_decay = 0.01, # 正则化技术,在损失函数中添加正则化项来减小权重的大小
|
24 |
+
lr_scheduler_type = "linear", # 学习率衰减策略
|
25 |
+
seed = 3407, # 随机种子
|
26 |
+
```
|
27 |
+
# 使用方法
|
28 |
+
## 使用python脚本下载BF16模型:
|
29 |
+
```python
|
30 |
+
from huggingface_hub import snapshot_download
|
31 |
+
snapshot_download(repo_id="basuo/llama-law", ignore_patterns=["*.gguf"]) # Download our BF16 model without downloading GGUF models.
|
32 |
+
```
|
33 |
+
模型推理:
|
34 |
+
```python
|
35 |
+
import torch
|
36 |
+
from unsloth import FastLanguageModel
|
37 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
38 |
+
model_name = "models/llama_lora",
|
39 |
+
max_seq_length = 2048,
|
40 |
+
dtype = torch.float16,
|
41 |
+
load_in_4bit = True,
|
42 |
+
)
|
43 |
+
FastLanguageModel.for_inference(model)
|
44 |
+
```
|
45 |
+
```python
|
46 |
+
alpaca_prompt = """
|
47 |
+
下面是一项描述任务的说明,配有提供进一步背景信息的输入。写出一个适当完成请求的回应。
|
48 |
+
|
49 |
+
### Instruction:
|
50 |
+
{}
|
51 |
+
|
52 |
+
### Input:
|
53 |
+
{}
|
54 |
+
|
55 |
+
### Response:
|
56 |
+
{}
|
57 |
+
"""
|
58 |
+
|
59 |
+
inputs = tokenizer(
|
60 |
+
[
|
61 |
+
alpaca_prompt.format(
|
62 |
+
"没有赡养老人就无法继承财产吗?", # instruction
|
63 |
+
"", # input
|
64 |
+
"", # output
|
65 |
+
)
|
66 |
+
], return_tensors = "pt").to("cuda")
|
67 |
+
|
68 |
+
outputs = model.generate(**inputs, max_new_tokens = 64, use_cache = True)
|
69 |
+
tokenizer.batch_decode(outputs)
|
70 |
+
```
|
71 |
+
```js
|
72 |
+
['\n下面是一项描述任务的说明,配有提供进一步背景信息的输入。写出一个适当完成请求的回应。\n\n### Instruction:\n没有赡养老人就无法继承财产吗?\n\n### Input:\n\n\n### Response:\n\n不是的,根据《中华人民共和国继承法》规定,继承人应当履行赡养义务,未履行赡养义务的,应当承担赡养费用。因此,如果没有赡养老人,继承人可以继承财产,但需要承担']
|
73 |
+
```
|
74 |
+
## GGUF模型
|
75 |
+
1.从模型文件中下载GGUF文件;<br>
|
76 |
+
2.将GGUF模型与LM Studio或Ollama结合使用;
|