ACRMiyamoto commited on
Commit
02108f9
·
verified ·
1 Parent(s): cf2fdff

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +58 -0
README.md CHANGED
@@ -20,3 +20,61 @@ 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
+ ```python
27
+ from unsloth import FastLanguageModel
28
+ from peft import PeftModel
29
+ import torch
30
+ import json
31
+ from tqdm import tqdm
32
+ import re
33
+
34
+ model_id = "llm-jp/llm-jp-3-13b"
35
+ adapter_id = "ACRMiyamoto/llm-jp-3-13b-it_lora"
36
+
37
+ HF_TOKEN = "YourToken" #HuggingFaceのTokenを入力
38
+
39
+ dtype = None # Noneにしておけば自動で設定
40
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
41
+
42
+ model, tokenizer = FastLanguageModel.from_pretrained(
43
+ model_name=model_id,
44
+ dtype=dtype,
45
+ load_in_4bit=load_in_4bit,
46
+ trust_remote_code=True,
47
+ )
48
+
49
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
50
+
51
+ datasets = []
52
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
53
+ item = ""
54
+ for line in f:
55
+ line = line.strip()
56
+ item += line
57
+ if item.endswith("}"):
58
+ datasets.append(json.loads(item))
59
+ item = ""
60
+
61
+ FastLanguageModel.for_inference(model)
62
+
63
+ results = []
64
+ for dt in tqdm(datasets):
65
+ input = dt["input"]
66
+
67
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
68
+
69
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
70
+
71
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
72
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
73
+
74
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
75
+
76
+ json_file_id = re.sub(".*/", "", adapter_id)
77
+ with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
78
+ for result in results:
79
+ json.dump(result, f, ensure_ascii=False)
80
+ f.write('\n')