HayatoF-1015
commited on
Commit
•
43bd9cd
1
Parent(s):
221b107
Update README
Browse files
README.md
CHANGED
@@ -20,3 +20,79 @@ 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)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
以下は、elyza-tasks-100-TV_0.jsonlの回答のためのコードです。
|
27 |
+
|
28 |
+
```python
|
29 |
+
from transformers import (
|
30 |
+
AutoModelForCausalLM,
|
31 |
+
AutoTokenizer,
|
32 |
+
BitsAndBytesConfig,
|
33 |
+
)
|
34 |
+
import torch
|
35 |
+
from tqdm import tqdm
|
36 |
+
import json
|
37 |
+
|
38 |
+
HF_TOKEN = "your-token"
|
39 |
+
model_name = "HayatoF-1015/llm-jp-3-13b-finetune-2024-11-22"
|
40 |
+
|
41 |
+
# QLoRA config
|
42 |
+
bnb_config = BitsAndBytesConfig(
|
43 |
+
load_in_4bit=True,
|
44 |
+
bnb_4bit_quant_type="nf4",
|
45 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
46 |
+
bnb_4bit_use_double_quant=False,
|
47 |
+
)
|
48 |
+
|
49 |
+
# Load model
|
50 |
+
model = AutoModelForCausalLM.from_pretrained(
|
51 |
+
model_name,
|
52 |
+
quantization_config=bnb_config,
|
53 |
+
device_map="auto",
|
54 |
+
token = HF_TOKEN
|
55 |
+
)
|
56 |
+
|
57 |
+
# Load tokenizer
|
58 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token = HF_TOKEN)
|
59 |
+
|
60 |
+
# データセットの読み込み。
|
61 |
+
datasets = []
|
62 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
63 |
+
item = ""
|
64 |
+
for line in f:
|
65 |
+
line = line.strip()
|
66 |
+
item += line
|
67 |
+
if item.endswith("}"):
|
68 |
+
datasets.append(json.loads(item))
|
69 |
+
item = ""
|
70 |
+
results = []
|
71 |
+
for data in tqdm(datasets):
|
72 |
+
|
73 |
+
input = data["input"]
|
74 |
+
|
75 |
+
prompt = f"""### 指示
|
76 |
+
{input}
|
77 |
+
### 回答:
|
78 |
+
"""
|
79 |
+
|
80 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
81 |
+
with torch.no_grad():
|
82 |
+
outputs = model.generate(
|
83 |
+
tokenized_input,
|
84 |
+
max_new_tokens=300,
|
85 |
+
do_sample=False,
|
86 |
+
repetition_penalty=1.2
|
87 |
+
)[0]
|
88 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
89 |
+
|
90 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
91 |
+
|
92 |
+
import re
|
93 |
+
model_name = re.sub(".*/", "", model_name)
|
94 |
+
with open(f"./{model_name}-my-original-outputs.jsonl", 'w', encoding='utf-8') as f:
|
95 |
+
for result in results:
|
96 |
+
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
|
97 |
+
f.write('\n')
|
98 |
+
```
|