qcube commited on
Commit
2ac45c3
·
verified ·
1 Parent(s): 227f49a

first update

Browse files
Files changed (1) hide show
  1. README.md +89 -0
README.md CHANGED
@@ -20,3 +20,92 @@ 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 transformers import (
30
+ AutoModelForCausalLM,
31
+ AutoTokenizer,
32
+ BitsAndBytesConfig,
33
+ )
34
+ import torch
35
+ from tqdm import tqdm
36
+ import json
37
+
38
+ HF_TOKEN = "your-token"
39
+ model_name = "qcube/llm-jp-3-13b-finetune2"
40
+
41
+ # QLoRA config
42
+ bnb_config = BitsAndBytesConfig(
43
+ load_in_4bit=True,
44
+ bnb_4bit_quant_type="nf4",
45
+ bnb_4bit_compute_dtype=torch.bfloat16,
46
+ bnb_4bit_use_double_quant=False,
47
+ )
48
+
49
+ # Load model
50
+ model = AutoModelForCausalLM.from_pretrained(
51
+ model_name,
52
+ quantization_config=bnb_config,
53
+ device_map="auto",
54
+ token=HF_TOKEN,
55
+ )
56
+
57
+ # Load tokenizer
58
+ tokenizer = AutoTokenizer.from_pretrained(
59
+ model_name,
60
+ trust_remote_code=True,
61
+ token=HF_TOKEN,
62
+ )
63
+
64
+ # データセットの読み込み。
65
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
66
+ datasets = []
67
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
68
+ item = ""
69
+ for line in f:
70
+ line = line.strip()
71
+ item += line
72
+ if item.endswith("}"):
73
+ datasets.append(json.loads(item))
74
+ item = ""
75
+
76
+ # llmjp
77
+ results = []
78
+ for data in tqdm(datasets):
79
+
80
+ input = data["input"]
81
+
82
+ prompt = f"""### 指示
83
+ {input}
84
+ ### 回答:
85
+ """
86
+
87
+ tokenized_input = tokenizer.encode(
88
+ prompt, add_special_tokens=False, return_tensors="pt"
89
+ ).to(model.device)
90
+ with torch.no_grad():
91
+ outputs = model.generate(
92
+ tokenized_input, max_new_tokens=100, do_sample=False, repetition_penalty=1.2
93
+ )[0]
94
+ output = tokenizer.decode(
95
+ outputs[tokenized_input.size(1) :], skip_special_tokens=True
96
+ )
97
+
98
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
99
+
100
+
101
+ import re
102
+
103
+ model_name = re.sub(".*/", "", model_name)
104
+ with open(f"./{model_name}-outputs.jsonl", "w", encoding="utf-8") as f:
105
+ for result in results:
106
+ json.dump(
107
+ result, f, ensure_ascii=False
108
+ ) # ensure_ascii=False for handling non-ASCII characters
109
+ f.write("\n")
110
+
111
+ ```