HayatoF-1015 commited on
Commit
32024d7
1 Parent(s): 2b2c8eb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +59 -0
README.md CHANGED
@@ -20,3 +20,62 @@ 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
+ # Ssmpe use
25
+
26
+ 以下は、elyza-tasks-100-TV_0.jsonlの回答のためのコードです。
27
+
28
+ ```python
29
+
30
+ from unsloth import FastLanguageModel
31
+ import torch
32
+ import json
33
+
34
+ model_name = "HayatoF-1015/llm-jp-3-13b-finetune2024-11-24"
35
+
36
+ max_seq_length = 2048
37
+ dtype = None
38
+ load_in_4bit = True
39
+
40
+ model, tokenizer = FastLanguageModel.from_pretrained(
41
+ model_name = model_name,
42
+ max_seq_length = max_seq_length,
43
+ dtype = dtype,
44
+ load_in_4bit = load_in_4bit,
45
+ token = "HF token",
46
+ )
47
+ FastLanguageModel.for_inference(model)
48
+
49
+ # データセットの読み込み。
50
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
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
+ from tqdm import tqdm
62
+
63
+ # 推論
64
+ results = []
65
+ for dt in tqdm(data):
66
+ input = dt["input"]
67
+
68
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
69
+
70
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
71
+
72
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
73
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
74
+
75
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
76
+
77
+ with open(f"/content/{model_name}_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')
81
+ ```