HarukaKawaji
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -3,197 +3,107 @@ library_name: transformers
|
|
3 |
tags: []
|
4 |
---
|
5 |
|
6 |
-
#
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
-
|
64 |
-
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
<!-- This should link to a Dataset Card if possible. -->
|
112 |
-
|
113 |
-
[More Information Needed]
|
114 |
-
|
115 |
-
#### Factors
|
116 |
-
|
117 |
-
<!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
|
118 |
-
|
119 |
-
[More Information Needed]
|
120 |
-
|
121 |
-
#### Metrics
|
122 |
-
|
123 |
-
<!-- These are the evaluation metrics being used, ideally with a description of why. -->
|
124 |
-
|
125 |
-
[More Information Needed]
|
126 |
-
|
127 |
-
### Results
|
128 |
-
|
129 |
-
[More Information Needed]
|
130 |
-
|
131 |
-
#### Summary
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
## Model Examination [optional]
|
136 |
-
|
137 |
-
<!-- Relevant interpretability work for the model goes here -->
|
138 |
-
|
139 |
-
[More Information Needed]
|
140 |
-
|
141 |
-
## Environmental Impact
|
142 |
-
|
143 |
-
<!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
|
144 |
-
|
145 |
-
Carbon emissions can be estimated using the [Machine Learning Impact calculator](https://mlco2.github.io/impact#compute) presented in [Lacoste et al. (2019)](https://arxiv.org/abs/1910.09700).
|
146 |
-
|
147 |
-
- **Hardware Type:** [More Information Needed]
|
148 |
-
- **Hours used:** [More Information Needed]
|
149 |
-
- **Cloud Provider:** [More Information Needed]
|
150 |
-
- **Compute Region:** [More Information Needed]
|
151 |
-
- **Carbon Emitted:** [More Information Needed]
|
152 |
-
|
153 |
-
## Technical Specifications [optional]
|
154 |
-
|
155 |
-
### Model Architecture and Objective
|
156 |
-
|
157 |
-
[More Information Needed]
|
158 |
-
|
159 |
-
### Compute Infrastructure
|
160 |
-
|
161 |
-
[More Information Needed]
|
162 |
-
|
163 |
-
#### Hardware
|
164 |
-
|
165 |
-
[More Information Needed]
|
166 |
-
|
167 |
-
#### Software
|
168 |
-
|
169 |
-
[More Information Needed]
|
170 |
-
|
171 |
-
## Citation [optional]
|
172 |
-
|
173 |
-
<!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
|
174 |
-
|
175 |
-
**BibTeX:**
|
176 |
-
|
177 |
-
[More Information Needed]
|
178 |
-
|
179 |
-
**APA:**
|
180 |
-
|
181 |
-
[More Information Needed]
|
182 |
-
|
183 |
-
## Glossary [optional]
|
184 |
-
|
185 |
-
<!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
|
186 |
-
|
187 |
-
[More Information Needed]
|
188 |
-
|
189 |
-
## More Information [optional]
|
190 |
-
|
191 |
-
[More Information Needed]
|
192 |
-
|
193 |
-
## Model Card Authors [optional]
|
194 |
-
|
195 |
-
[More Information Needed]
|
196 |
-
|
197 |
-
## Model Card Contact
|
198 |
-
|
199 |
-
[More Information Needed]
|
|
|
3 |
tags: []
|
4 |
---
|
5 |
|
6 |
+
# Uploaded model
|
7 |
+
|
8 |
+
- **Developed by:** haruka
|
9 |
+
- **License:** apache-2.0
|
10 |
+
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
11 |
+
|
12 |
+
# Code
|
13 |
+
|
14 |
+
```python
|
15 |
+
# python 3.10.12
|
16 |
+
!pip install -U pip
|
17 |
+
!pip install -U transformers
|
18 |
+
!pip install -U bitsandbytes
|
19 |
+
!pip install -U accelerate
|
20 |
+
!pip install -U datasets
|
21 |
+
!pip install -U peft
|
22 |
+
!pip install -U trl
|
23 |
+
!pip install -U wandb
|
24 |
+
!pip install ipywidgets --upgrade
|
25 |
+
from transformers import (
|
26 |
+
AutoModelForCausalLM,
|
27 |
+
AutoTokenizer,
|
28 |
+
BitsAndBytesConfig,
|
29 |
+
)
|
30 |
+
from peft import PeftModel
|
31 |
+
import torch
|
32 |
+
from tqdm import tqdm
|
33 |
+
import json
|
34 |
+
# Hugging Faceで取得したTokenをこちらに貼る。
|
35 |
+
from google.colab import userdata
|
36 |
+
HF_TOKEN = userdata.get('HF_TOKEN')
|
37 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
38 |
+
adapter_id = "totsukash/llm-jp-3-13b-finetune"
|
39 |
+
# QLoRA config
|
40 |
+
bnb_config = BitsAndBytesConfig(
|
41 |
+
load_in_4bit=True,
|
42 |
+
bnb_4bit_quant_type="nf4",
|
43 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
44 |
+
)
|
45 |
+
# Load model
|
46 |
+
model = AutoModelForCausalLM.from_pretrained(
|
47 |
+
model_id,
|
48 |
+
quantization_config=bnb_config,
|
49 |
+
device_map="auto",
|
50 |
+
token = HF_TOKEN
|
51 |
+
)
|
52 |
+
# Load tokenizer
|
53 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN)
|
54 |
+
# 元のモデルにLoRAのアダプタを統合。
|
55 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
56 |
+
# データセットの読み込み。
|
57 |
+
# (評価データセットのjsonlファイルのパスを設定してください)
|
58 |
+
datasets = []
|
59 |
+
with open("/content/elyza-tasks-100-TV_0.jsonl", "r") as f:
|
60 |
+
item = ""
|
61 |
+
for line in f:
|
62 |
+
line = line.strip()
|
63 |
+
item += line
|
64 |
+
if item.endswith("}"):
|
65 |
+
datasets.append(json.loads(item))
|
66 |
+
item = ""
|
67 |
+
# gemma
|
68 |
+
results = []
|
69 |
+
for data in tqdm(datasets):
|
70 |
+
input = data["input"]
|
71 |
+
prompt = f"""### 指示
|
72 |
+
{input}
|
73 |
+
### 回答
|
74 |
+
"""
|
75 |
+
|
76 |
+
# input_ids だけを取り出して使用
|
77 |
+
input_ids = tokenizer(prompt, return_tensors="pt").input_ids.to(model.device)
|
78 |
+
outputs = model.generate(input_ids, max_new_tokens=512, do_sample=False, repetition_penalty=1.2)
|
79 |
+
output = tokenizer.decode(outputs[0][input_ids.size(1):], skip_special_tokens=True)
|
80 |
+
|
81 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
82 |
+
# # llmjp
|
83 |
+
# results = []
|
84 |
+
# for data in tqdm(datasets):
|
85 |
+
# input = data["input"]
|
86 |
+
# prompt = f"""### 指示
|
87 |
+
# {input}
|
88 |
+
# ### 回答
|
89 |
+
# """
|
90 |
+
# tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
91 |
+
# attention_mask = torch.ones_like(tokenized_input)
|
92 |
+
# with torch.no_grad():
|
93 |
+
# outputs = model.generate(
|
94 |
+
# tokenized_input,
|
95 |
+
# attention_mask=attention_mask,
|
96 |
+
# max_new_tokens=100,
|
97 |
+
# do_sample=False,
|
98 |
+
# repetition_penalty=1.2,
|
99 |
+
# pad_token_id=tokenizer.eos_token_id
|
100 |
+
# )[0]
|
101 |
+
# output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
102 |
+
# results.append({"task_id": data["task_id"], "input": input, "output": output})
|
103 |
+
import re
|
104 |
+
jsonl_id = re.sub(".*/", "", adapter_id)
|
105 |
+
with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
|
106 |
+
for result in results:
|
107 |
+
json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
|
108 |
+
f.write('\n')
|
109 |
+
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|