ACRMiyamoto commited on
Commit
eca61c1
·
verified ·
1 Parent(s): ed32326

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +51 -0
README.md CHANGED
@@ -20,3 +20,54 @@ 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
+ ```python
25
+ from unsloth import FastLanguageModel
26
+ from peft import PeftModel
27
+ import torch
28
+ import json
29
+ from tqdm import tqdm
30
+ import re
31
+
32
+ model_id = "llm-jp/llm-jp-3-13b"
33
+ adapter_id = "ACRMiyamoto/llm-jp-3-13b-03-Tanuki-8B-annotated-DPO-12-11"
34
+
35
+ HF_TOKEN = "HF_Token" #HFのトークンを記載
36
+
37
+ dtype = None # Noneにしておけば自動で設定
38
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
39
+
40
+ model, tokenizer = FastLanguageModel.from_pretrained(
41
+ model_name=model_id,
42
+ dtype=dtype,
43
+ load_in_4bit=load_in_4bit,
44
+ trust_remote_code=True,
45
+ )
46
+
47
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
48
+
49
+ datasets = []
50
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
51
+ item = ""
52
+ for line in f:
53
+ line = line.strip()
54
+ item += line
55
+ if item.endswith("}"):
56
+ datasets.append(json.loads(item))
57
+ item = ""
58
+
59
+ FastLanguageModel.for_inference(model)
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
+ ```