kanbac5 commited on
Commit
ac517d6
1 Parent(s): ab9b541

Update Model

Browse files
Files changed (1) hide show
  1. README.md +64 -0
README.md CHANGED
@@ -20,3 +20,67 @@ 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
+ import yaml
32
+ from tqdm import tqdm
33
+ import re
34
+
35
+ model_id = "llm-jp/llm-jp-3-13b"
36
+ adapter_id = "kanbac5/llm-jp-3-13b-it-1217llm2024_lora_1217"
37
+
38
+ with open("api_info.yaml", 'r', encoding="utf-8") as yml:
39
+ parameters = yaml.safe_load(yml)
40
+ HF_TOKEN = parameters["token"]
41
+
42
+ dtype = None
43
+ load_in_4bit = 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("data/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
+
80
+ json_file_id = re.sub(".*/", "", adapter_id)
81
+ with open(f"{json_file_id}_output_1217.jsonl", 'w', encoding='utf-8') as f:
82
+ for result in results:
83
+ json.dump(result, f, ensure_ascii=False)
84
+ f.write('\n')
85
+
86
+ ```