HayatoF-1015 commited on
Commit
dd623b1
·
verified ·
1 Parent(s): 57b5887

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +70 -0
README.md CHANGED
@@ -16,7 +16,77 @@ language:
16
  - **Developed by:** HayatoF-1015
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** llm-jp/llm-jp-3-13b
 
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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  - **Developed by:** HayatoF-1015
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** llm-jp/llm-jp-3-13b
19
+ - **Improved using Qwen**
20
 
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
+ # elyza-tasks-100-TV_0.jsonlの解答出力の仕方
26
+
27
+ ```python
28
+ # 必要なライブラリを読み込み
29
+ from unsloth import FastLanguageModel
30
+ from peft import PeftModel
31
+ import torch
32
+ import json
33
+ from tqdm import tqdm
34
+ import re
35
+
36
+ # ベースとなるモデルと学習したLoRAのアダプタ(Hugging FaceのIDを指定)。
37
+ model_id = "llm-jp/llm-jp-3-13b"
38
+ adapter_id = "HayatoF-1015/magpie_lora_elyza_12-15-v2"
39
+
40
+ # unslothのFastLanguageModelで元のモデルをロード。
41
+ dtype = None # Noneにしておけば自動で設定
42
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
43
+
44
+ model, tokenizer = FastLanguageModel.from_pretrained(
45
+ model_name=model_id,
46
+ dtype=dtype,
47
+ load_in_4bit=load_in_4bit,
48
+ trust_remote_code=True,
49
+ )
50
+
51
+ # 元のモデルにLoRAのアダプタを統合。
52
+ model = PeftModel.from_pretrained(model, adapter_id)
53
+
54
+
55
+ # タスクとなるデータの読み込み。
56
+ # 事前にデータをアップロードしてください。
57
+ datasets = []
58
+ with open("/content/elyza-tasks-100-TV_0.jsonl", "r") as f:
59
+ item = ""
60
+ for line in f:
61
+ line = line.strip()
62
+ item += line
63
+ if item.endswith("}"):
64
+ datasets.append(json.loads(item))
65
+ item = ""
66
+
67
+ # モデルを用いてタスクの推論。
68
+
69
+ # 推論するためにモデルのモードを変更
70
+ FastLanguageModel.for_inference(model)
71
+
72
+ results = []
73
+ for dt in tqdm(datasets):
74
+ input = dt["input"]
75
+
76
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
77
+
78
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
79
+
80
+ outputs = model.generate(**inputs, max_new_tokens = 2048, use_cache = True, do_sample=False, repetition_penalty=1.2)
81
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
82
+
83
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
84
+
85
+ # ここではadapter_idを元にファイル名を決定している.
86
+ json_file_id = re.sub(".*/", "", adapter_id)
87
+ with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
88
+ for result in results:
89
+ json.dump(result, f, ensure_ascii=False)
90
+ f.write('\n')
91
+
92
+ ```