Update README.md
Browse files
README.md
CHANGED
@@ -1,22 +1,59 @@
|
|
1 |
---
|
2 |
base_model: llm-jp/llm-jp-3-13b
|
3 |
-
tags:
|
4 |
-
- text-generation-inference
|
5 |
-
- transformers
|
6 |
-
- unsloth
|
7 |
-
- llama
|
8 |
-
- trl
|
9 |
-
license: apache-2.0
|
10 |
-
language:
|
11 |
-
- en
|
12 |
-
---
|
13 |
|
14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
19 |
|
20 |
-
|
21 |
|
22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
base_model: llm-jp/llm-jp-3-13b
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
|
4 |
+
# Inference
|
5 |
+
```python
|
6 |
+
from unsloth import FastLanguageModel
|
7 |
+
from peft import PeftModel
|
8 |
+
import torch
|
9 |
+
import json
|
10 |
+
from tqdm import tqdm
|
11 |
+
import re
|
12 |
+
|
13 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
14 |
+
adapter_id = ""
|
15 |
+
HF_TOKEN = "" # use your token
|
16 |
+
|
17 |
+
dtype = None
|
18 |
+
load_in_4bit = True # 今回は13Bモデルを扱うためTrue
|
19 |
+
|
20 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
21 |
+
model_name=model_id,
|
22 |
+
dtype=dtype,
|
23 |
+
load_in_4bit=load_in_4bit,
|
24 |
+
trust_remote_code=True,
|
25 |
+
)
|
26 |
+
|
27 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
28 |
+
|
29 |
+
datasets = []
|
30 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
31 |
+
item = ""
|
32 |
+
for line in f:
|
33 |
+
line = line.strip()
|
34 |
+
item += line
|
35 |
+
if item.endswith("}"):
|
36 |
+
datasets.append(json.loads(item))
|
37 |
+
item = ""
|
38 |
+
|
39 |
+
FastLanguageModel.for_inference(model)
|
40 |
+
|
41 |
+
results = []
|
42 |
+
for dt in tqdm(datasets):
|
43 |
+
input = dt["input"]
|
44 |
+
|
45 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
46 |
+
|
47 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
48 |
|
49 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
50 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
|
|
51 |
|
52 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
53 |
|
54 |
+
json_file_id = re.sub(".*/", "", adapter_id)
|
55 |
+
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
56 |
+
for result in results:
|
57 |
+
json.dump(result, f, ensure_ascii=False)
|
58 |
+
f.write('\n')
|
59 |
+
```
|