codemafia0000
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -19,4 +19,58 @@ language:
|
|
19 |
|
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)
|
|
|
19 |
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
+
## how to inference
|
23 |
+
```py
|
24 |
+
!pip install unsloth
|
25 |
+
|
26 |
+
from unsloth import FastLanguageModel
|
27 |
+
from tqdm import tqdm
|
28 |
+
import torch
|
29 |
+
import json
|
30 |
+
|
31 |
+
model_name = "codemafia0000/llm-jp-3-13b-finetune-LoRA-241124"
|
32 |
+
HF_TOKEN = "YOUR_TOKEN"
|
33 |
+
|
34 |
+
max_seq_length = 2048
|
35 |
+
dtype = None
|
36 |
+
load_in_4bit = True
|
37 |
+
|
38 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
39 |
+
model_name = model_name,
|
40 |
+
max_seq_length = max_seq_length,
|
41 |
+
dtype = dtype,
|
42 |
+
load_in_4bit = load_in_4bit,
|
43 |
+
token = HF_TOKEN,
|
44 |
+
)
|
45 |
+
FastLanguageModel.for_inference(model)
|
46 |
+
|
47 |
+
datasets = []
|
48 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
49 |
+
item = ""
|
50 |
+
for line in f:
|
51 |
+
line = line.strip()
|
52 |
+
item += line
|
53 |
+
if item.endswith("}"):
|
54 |
+
datasets.append(json.loads(item))
|
55 |
+
item = ""
|
56 |
+
|
57 |
+
results = []
|
58 |
+
for dt in tqdm(datasets):
|
59 |
+
input = dt["input"]
|
60 |
+
|
61 |
+
prompt = f"""### question\n{input}\n### answer\n"""
|
62 |
+
|
63 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
64 |
+
|
65 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
66 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### answer')[-1]
|
67 |
+
|
68 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
69 |
+
|
70 |
+
with open(f"{model_name}_output.jsonl", 'w', encoding='utf-8') as f:
|
71 |
+
for result in results:
|
72 |
+
json.dump(result, f, ensure_ascii=False)
|
73 |
+
f.write('\n')
|
74 |
+
```
|
75 |
+
|
76 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|