hi-sa-gi commited on
Commit
c43d706
·
verified ·
1 Parent(s): ba327f5

Update README.md

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
+ # 提出用JSONLファイルの出力方法
25
+ 以下の処理により提出用JSONLファイルを出力します。
26
+
27
+ ※提供されているサンプルコードと同じです。
28
+
29
+ ## 導入パッケージ
30
+ ```
31
+ %%capture
32
+ !pip install unsloth
33
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
34
+ ```
35
+ ## モデル取得、実行、出力保存
36
+ ```python
37
+ from unsloth import FastLanguageModel
38
+ import torch
39
+ import json
40
+
41
+ DATASET_JSONL_PATH="./elyza-tasks-100-TV_0.jsonl" # 評価用データセット格納パス
42
+
43
+ model_name = "hi-sa-gi/llm-jp-3-13b-finetune-2"
44
+ max_seq_length = 2048
45
+ dtype = None
46
+ load_in_4bit = True
47
+
48
+ model, tokenizer = FastLanguageModel.from_pretrained(
49
+ model_name = model_name,
50
+ max_seq_length = max_seq_length,
51
+ dtype = dtype,
52
+ load_in_4bit = load_in_4bit,
53
+ token = "HF token",
54
+ )
55
+ FastLanguageModel.for_inference(model)
56
+
57
+ datasets = []
58
+ with open(DATASET_JSONL_PATH, "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
+ from tqdm import tqdm
68
+
69
+ # 推論
70
+ results = []
71
+ for dt in tqdm(data):
72
+ input = dt["input"]
73
+
74
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
75
+
76
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
77
+
78
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
79
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
80
+
81
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
82
+
83
+ with open(f"./{model_name}_output.jsonl", 'w', encoding='utf-8') as f:
84
+ for result in results:
85
+ json.dump(result, f, ensure_ascii=False)
86
+ f.write('\n')