Upload 3 files
Browse files- README.md +93 -3
- adapter_config.json +39 -0
- adapter_model.safetensors +3 -0
README.md
CHANGED
@@ -1,3 +1,93 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
base_model: llm-jp/llm-jp-3-13b
|
3 |
+
library_name: peft
|
4 |
+
---
|
5 |
+
|
6 |
+
# 概要
|
7 |
+
[llm-jp/llm-jp-3-13b](https://huggingface.co/llm-jp/llm-jp-3-13b) を [ichikara-instruction](https://liat-aip.sakura.ne.jp/wp/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf%e4%bd%9c%e6%88%90/llm%e3%81%ae%e3%81%9f%e3%82%81%e3%81%ae%e6%97%a5%e6%9c%ac%e8%aa%9e%e3%82%a4%e3%83%b3%e3%82%b9%e3%83%88%e3%83%a9%e3%82%af%e3%82%b7%e3%83%a7%e3%83%b3%e3%83%87%e3%83%bc%e3%82%bf-%e5%85%ac%e9%96%8b) でSFTしたモデル。SFTの際は、モデルパラメータに対し8bit量子化を行ったQLoRAを用いている。
|
8 |
+
|
9 |
+
|
10 |
+
# 推論方法
|
11 |
+
本モデルを用いて `elyza-tasks-100-TV_0.jsonl` に対して推論する方法を示す。
|
12 |
+
|
13 |
+
## データ
|
14 |
+
`elyza-tasks-100-TV_0.jsonl` を事前にダウンロードする。
|
15 |
+
|
16 |
+
## サンプルコード
|
17 |
+
```
|
18 |
+
import json
|
19 |
+
import re
|
20 |
+
|
21 |
+
import peft
|
22 |
+
import torch
|
23 |
+
import transformers
|
24 |
+
|
25 |
+
|
26 |
+
def load_jsonl(fname):
|
27 |
+
with open(fname, encoding="utf-8") as f:
|
28 |
+
data = []
|
29 |
+
for line in f:
|
30 |
+
_data = json.loads(line.strip())
|
31 |
+
data.append(_data)
|
32 |
+
return data
|
33 |
+
|
34 |
+
|
35 |
+
# loading dataset
|
36 |
+
dataset = load_jsonl("./elyza-tasks-100-TV_0.jsonl")
|
37 |
+
|
38 |
+
|
39 |
+
# loading model
|
40 |
+
bnb_config = transformers.BitsAndBytesConfig(load_in_8bit=True)
|
41 |
+
|
42 |
+
model = transformers.AutoModelForCausalLM.from_pretrained(
|
43 |
+
pretrained_model_name_or_path="llm-jp/llm-jp-3-13b", device_map="auto", quantization_config=bnb_config
|
44 |
+
)
|
45 |
+
model = peft.PeftModel.from_pretrained(model, "orihihsoy/llm-jp-3-13b_qlora_8bit")
|
46 |
+
|
47 |
+
tokenizer = transformers.AutoTokenizer.from_pretrained(
|
48 |
+
pretrained_model_name_or_path=="llm-jp/llm-jp-3-13b"
|
49 |
+
)
|
50 |
+
|
51 |
+
|
52 |
+
# evaluation
|
53 |
+
PROMPT_TEMPLATE = """{instruction}
|
54 |
+
|
55 |
+
### 指示:
|
56 |
+
{input}
|
57 |
+
|
58 |
+
### 回答:
|
59 |
+
{output}"""
|
60 |
+
|
61 |
+
results = []
|
62 |
+
for data in dataset:
|
63 |
+
input = data["input"]
|
64 |
+
BOS_TOKEN = tokenizer.bos_token
|
65 |
+
|
66 |
+
prompt = BOS_TOKEN + PROMPT_TEMPLATE.format(
|
67 |
+
instruction="以下は、タスクを説明する指示です。要求を適切に満たす応答を書きなさい。", input=input, output="")
|
68 |
+
|
69 |
+
tokenized_input = tokenizer.encode(
|
70 |
+
prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
71 |
+
attention_mask = torch.ones_like(tokenized_input)
|
72 |
+
with torch.no_grad():
|
73 |
+
outputs = model.generate(
|
74 |
+
tokenized_input,
|
75 |
+
attention_mask=attention_mask,
|
76 |
+
max_new_tokens=1024,
|
77 |
+
do_sample=True,
|
78 |
+
top_p=0.95,
|
79 |
+
temperature=0.7,
|
80 |
+
repetition_penalty=1.05,
|
81 |
+
pad_token_id=tokenizer.eos_token_id
|
82 |
+
)[0]
|
83 |
+
output = tokenizer.decode(
|
84 |
+
outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
85 |
+
|
86 |
+
results.append({"task_id": data["task_id"],
|
87 |
+
"input": input, "output": output})
|
88 |
+
|
89 |
+
with open(f"gen.jsonl", 'w', encoding='utf-8') as f:
|
90 |
+
for result in results:
|
91 |
+
json.dump(result, f, ensure_ascii=False)
|
92 |
+
f.write('\n')
|
93 |
+
```
|
adapter_config.json
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"alpha_pattern": {},
|
3 |
+
"auto_mapping": null,
|
4 |
+
"base_model_name_or_path": "llm-jp/llm-jp-3-13b",
|
5 |
+
"bias": "none",
|
6 |
+
"eva_config": null,
|
7 |
+
"exclude_modules": null,
|
8 |
+
"fan_in_fan_out": false,
|
9 |
+
"inference_mode": true,
|
10 |
+
"init_lora_weights": true,
|
11 |
+
"layer_replication": null,
|
12 |
+
"layers_pattern": null,
|
13 |
+
"layers_to_transform": null,
|
14 |
+
"loftq_config": {},
|
15 |
+
"lora_alpha": 32,
|
16 |
+
"lora_bias": false,
|
17 |
+
"lora_dropout": 0.05,
|
18 |
+
"megatron_config": null,
|
19 |
+
"megatron_core": "megatron.core",
|
20 |
+
"modules_to_save": null,
|
21 |
+
"peft_type": "LORA",
|
22 |
+
"r": 16,
|
23 |
+
"rank_pattern": {},
|
24 |
+
"revision": null,
|
25 |
+
"target_modules": [
|
26 |
+
"q_proj",
|
27 |
+
"gate_proj",
|
28 |
+
"up_proj",
|
29 |
+
"lm_head",
|
30 |
+
"o_proj",
|
31 |
+
"v_proj",
|
32 |
+
"down_proj",
|
33 |
+
"k_proj",
|
34 |
+
"embed_tokens"
|
35 |
+
],
|
36 |
+
"task_type": "CAUSAL_LM",
|
37 |
+
"use_dora": false,
|
38 |
+
"use_rslora": false
|
39 |
+
}
|
adapter_model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:b0ad9ea0b37ec9ebc76630ffcb0c9ae804aa0972e78ba38f996a0bca2041410a
|
3 |
+
size 2303306144
|