Update
Browse files
README.md
CHANGED
@@ -8,10 +8,10 @@ tags:
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
-
-
|
12 |
---
|
13 |
|
14 |
-
# Uploaded
|
15 |
|
16 |
- **Developed by:** harutoshi
|
17 |
- **License:** apache-2.0
|
@@ -20,3 +20,59 @@ language:
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
+
- jp
|
12 |
---
|
13 |
|
14 |
+
# Uploaded model
|
15 |
|
16 |
- **Developed by:** harutoshi
|
17 |
- **License:** apache-2.0
|
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
# Sample Use
|
25 |
+
|
26 |
+
以下は、推論を実行するためのサンプルコードです。
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
30 |
+
import torch
|
31 |
+
from unsloth import FastLanguageModel
|
32 |
+
from tqdm import tqdm
|
33 |
+
import json
|
34 |
+
|
35 |
+
HF_TOKEN = {あなたのHugging Faceのトークン}
|
36 |
+
model_name = "harutoshi/llm-jp-3-13b-it"
|
37 |
+
|
38 |
+
max_seq_length = 2048
|
39 |
+
dtype = None
|
40 |
+
load_in_4bit = True
|
41 |
+
|
42 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
43 |
+
model_name = model_name,
|
44 |
+
max_seq_length = max_seq_length,
|
45 |
+
dtype = dtype,
|
46 |
+
load_in_4bit = load_in_4bit,
|
47 |
+
token = "HF token",
|
48 |
+
)
|
49 |
+
FastLanguageModel.for_inference(model)
|
50 |
+
|
51 |
+
datasets = []
|
52 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
53 |
+
item = ""
|
54 |
+
for line in f:
|
55 |
+
line = line.strip()
|
56 |
+
item += line
|
57 |
+
if item.endswith("}"):
|
58 |
+
datasets.append(json.loads(item))
|
59 |
+
item = ""
|
60 |
+
|
61 |
+
results = []
|
62 |
+
for dt in tqdm(datasets):
|
63 |
+
input = dt["input"]
|
64 |
+
|
65 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
66 |
+
|
67 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
68 |
+
|
69 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
70 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
71 |
+
|
72 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
73 |
+
|
74 |
+
with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
75 |
+
for result in results:
|
76 |
+
json.dump(result, f, ensure_ascii=False)
|
77 |
+
f.write('\n')
|
78 |
+
```
|