qcube commited on
Commit
e18d4f2
·
verified ·
1 Parent(s): cc9d773

Update README

Browse files
Files changed (1) hide show
  1. README.md +73 -0
README.md CHANGED
@@ -20,3 +20,76 @@ 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
+ 以下は、elyza-tasks-100-TV_0.jsonl の回答のためのコードです。
27
+
28
+ ```python
29
+ from unsloth import FastLanguageModel
30
+ import torch
31
+ import json
32
+
33
+
34
+ HF_TOKEN = "your-token"
35
+ model_name = "qcube/llm-jp-3-13b-finetune6"
36
+
37
+ max_seq_length = 2048
38
+ dtype = None
39
+ load_in_4bit = True
40
+
41
+ model, tokenizer = FastLanguageModel.from_pretrained(
42
+ model_name=model_name,
43
+ max_seq_length=max_seq_length,
44
+ dtype=dtype,
45
+ load_in_4bit=load_in_4bit,
46
+ token=HF_TOKEN,
47
+ )
48
+ FastLanguageModel.for_inference(model)
49
+
50
+ # データセットの読み込み。
51
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
52
+ datasets = []
53
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
54
+ item = ""
55
+ for line in f:
56
+ line = line.strip()
57
+ item += line
58
+ if item.endswith("}"):
59
+ datasets.append(json.loads(item))
60
+ item = ""
61
+
62
+
63
+ from tqdm import tqdm
64
+
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(
75
+ **inputs,
76
+ max_new_tokens=512,
77
+ use_cache=True,
78
+ do_sample=False,
79
+ repetition_penalty=1.2,
80
+ )
81
+ prediction = tokenizer.decode(
82
+ outputs[0],
83
+ skip_special_tokens=True,
84
+ ).split(
85
+ "\n### 回答"
86
+ )[-1]
87
+
88
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
89
+
90
+
91
+ with open(f"./llm-jp-3-13b-finetune6-outputs-3.jsonl", "w", encoding="utf-8") as f:
92
+ for result in results:
93
+ json.dump(result, f, ensure_ascii=False)
94
+ f.write("\n")
95
+ ```