daidaidaidaidai commited on
Commit
c6146e4
·
verified ·
1 Parent(s): edcf204

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +56 -0
README.md CHANGED
@@ -21,3 +21,59 @@ language:
21
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
22
 
23
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
22
 
23
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
24
+
25
+ # Sample Use
26
+
27
+ 以下は、elyza-tasks-100-TV_0.jsonlの回答の為のコードです。
28
+
29
+ ```python
30
+ from unsloth import FastLanguageModel
31
+ from peft import PeftModel
32
+ import torch
33
+ import json
34
+ from tqdm import tqdm
35
+ import re
36
+
37
+ model_id = "llm-jp/llm-jp-3-13b"
38
+ adapter_id = "daidaidaidaidai/llm-jp-3-13b-it-lora-elyza100_lora"
39
+
40
+ HF_TOKEN = "{YOUR TOKEN}"
41
+
42
+ dtype = None # Noneにしておけば自動で設定
43
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
44
+
45
+ model, tokenizer = FastLanguageModel.from_pretrained(
46
+ model_name=model_id,
47
+ dtype=dtype,
48
+ load_in_4bit=load_in_4bit,
49
+ trust_remote_code=True,
50
+ )
51
+
52
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
53
+
54
+ datasets = []
55
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
56
+ item = ""
57
+ for line in f:
58
+ line = line.strip()
59
+ item += line
60
+ if item.endswith("}"):
61
+ datasets.append(json.loads(item))
62
+ item = ""
63
+
64
+ FastLanguageModel.for_inference(model)
65
+
66
+ results = []
67
+ for dt in tqdm(datasets):
68
+ input = dt["input"]
69
+
70
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
71
+
72
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
73
+
74
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
75
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
76
+
77
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
78
+
79
+ ```