JunichiroMorita
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -21,27 +21,68 @@ widget:
|
|
21 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
22 |
|
23 |
# Usage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
```python
|
|
|
|
|
25 |
import torch
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
|
|
|
|
|
|
|
|
|
45 |
```
|
46 |
|
47 |
# Data
|
|
|
21 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
22 |
|
23 |
# Usage
|
24 |
+
|
25 |
+
```python
|
26 |
+
!pip install unsloth
|
27 |
+
!pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
28 |
+
!pip install -U torch
|
29 |
+
!pip install -U peft
|
30 |
+
```
|
31 |
+
|
32 |
```python
|
33 |
+
from unsloth import FastLanguageModel
|
34 |
+
from peft import PeftModel
|
35 |
import torch
|
36 |
+
import json
|
37 |
+
from tqdm import tqdm
|
38 |
+
import re
|
39 |
+
|
40 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
41 |
+
adapter_id = f"JunichiroMorita/llm-jp-3-13b-it_lora_20241216"
|
42 |
+
|
43 |
+
HF_TOKEN = 'your_hugging_face_token'
|
44 |
+
|
45 |
+
dtype = None
|
46 |
+
load_in_4bit = True
|
47 |
+
|
48 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
49 |
+
model_name=model_id,
|
50 |
+
dtype=dtype,
|
51 |
+
load_in_4bit=load_in_4bit,
|
52 |
+
trust_remote_code=True,
|
53 |
+
)
|
54 |
+
|
55 |
+
model = PeftModel.from_pretrained(model, adapter_id, token=HF_TOKEN)
|
56 |
+
|
57 |
+
datasets = []
|
58 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
59 |
+
item = ""
|
60 |
+
for line in f:
|
61 |
+
line = line.strip()
|
62 |
+
item += line
|
63 |
+
if item.endswith("}"):
|
64 |
+
datasets.append(json.loads(item))
|
65 |
+
item = ""
|
66 |
+
|
67 |
+
FastLanguageModel.for_inference(model)
|
68 |
+
|
69 |
+
results = []
|
70 |
+
for dt in tqdm(datasets):
|
71 |
+
input = dt["input"]
|
72 |
+
|
73 |
+
prompt = f"""### 指示\n{input}\n\n### 回答\n"""
|
74 |
+
|
75 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
76 |
+
|
77 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
78 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答\n')[-1]
|
79 |
+
|
80 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
81 |
|
82 |
+
with open(f'./llm-jp-3-13b-it_lora_20241216_output.jsonl', 'w', encoding='utf-8') as f:
|
83 |
+
for result in results:
|
84 |
+
json.dump(result, f, ensure_ascii=False)
|
85 |
+
f.write('\n')
|
86 |
```
|
87 |
|
88 |
# Data
|