yuki-2000 commited on
Commit
c1e21b2
·
verified ·
1 Parent(s): 39eca32

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +93 -133
README.md CHANGED
@@ -2,6 +2,10 @@
2
  library_name: transformers
3
  datasets:
4
  - weblab-GENIAC/aya-ja-evol-instruct-calm3-dpo-masked
 
 
 
 
5
  ---
6
 
7
  # Model Card for Model ID
@@ -35,166 +39,122 @@ This is the model card of a 🤗 transformers model that has been pushed on the
35
  - **Demo [optional]:** [More Information Needed]
36
 
37
  ## Uses
 
38
 
39
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
 
 
 
 
 
 
 
40
 
41
- ### Direct Use
42
 
43
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
 
 
 
 
 
 
 
 
 
44
 
45
- [More Information Needed]
46
 
47
- ### Downstream Use [optional]
48
 
49
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
 
50
 
51
- [More Information Needed]
52
 
53
- ### Out-of-Scope Use
54
 
55
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
56
 
57
- [More Information Needed]
 
 
 
 
 
 
58
 
59
- ## Bias, Risks, and Limitations
60
 
61
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
62
 
63
- [More Information Needed]
64
 
65
- ### Recommendations
 
 
 
 
 
66
 
67
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
68
 
69
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
70
 
71
- ## How to Get Started with the Model
72
 
73
- Use the code below to get started with the model.
74
 
75
- [More Information Needed]
 
 
 
 
 
 
76
 
77
- ## Training Details
 
78
 
79
- ### Training Data
80
 
81
- <!-- This should link to a Dataset Card, perhaps with a short stub of information on what the training data is all about as well as documentation related to data pre-processing or additional filtering. -->
 
82
 
83
- [More Information Needed]
 
84
 
85
- ### Training Procedure
 
 
 
 
 
 
 
 
 
 
86
 
87
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
 
 
88
 
89
- #### Preprocessing [optional]
90
 
91
- [More Information Needed]
 
 
 
92
 
 
 
 
 
 
 
 
 
 
 
 
 
93
 
94
- #### Training Hyperparameters
95
 
96
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
97
-
98
- #### Speeds, Sizes, Times [optional]
99
-
100
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
101
-
102
- [More Information Needed]
103
-
104
- ## Evaluation
105
-
106
- <!-- This section describes the evaluation protocols and provides the results. -->
107
-
108
- ### Testing Data, Factors & Metrics
109
-
110
- #### Testing Data
111
-
112
- <!-- This should link to a Dataset Card if possible. -->
113
-
114
- [More Information Needed]
115
-
116
- #### Factors
117
-
118
- <!-- These are the things the evaluation is disaggregating by, e.g., subpopulations or domains. -->
119
-
120
- [More Information Needed]
121
-
122
- #### Metrics
123
-
124
- <!-- These are the evaluation metrics being used, ideally with a description of why. -->
125
-
126
- [More Information Needed]
127
-
128
- ### Results
129
-
130
- [More Information Needed]
131
-
132
- #### Summary
133
-
134
-
135
-
136
- ## Model Examination [optional]
137
-
138
- <!-- Relevant interpretability work for the model goes here -->
139
-
140
- [More Information Needed]
141
-
142
- ## Environmental Impact
143
-
144
- <!-- Total emissions (in grams of CO2eq) and additional considerations, such as electricity usage, go here. Edit the suggested text below accordingly -->
145
-
146
- 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).
147
-
148
- - **Hardware Type:** [More Information Needed]
149
- - **Hours used:** [More Information Needed]
150
- - **Cloud Provider:** [More Information Needed]
151
- - **Compute Region:** [More Information Needed]
152
- - **Carbon Emitted:** [More Information Needed]
153
-
154
- ## Technical Specifications [optional]
155
-
156
- ### Model Architecture and Objective
157
-
158
- [More Information Needed]
159
-
160
- ### Compute Infrastructure
161
-
162
- [More Information Needed]
163
-
164
- #### Hardware
165
-
166
- [More Information Needed]
167
-
168
- #### Software
169
-
170
- [More Information Needed]
171
-
172
- ## Citation [optional]
173
-
174
- <!-- If there is a paper or blog post introducing the model, the APA and Bibtex information for that should go in this section. -->
175
-
176
- **BibTeX:**
177
-
178
- [More Information Needed]
179
-
180
- **APA:**
181
-
182
- [More Information Needed]
183
-
184
- ## Glossary [optional]
185
-
186
- <!-- If relevant, include terms and calculations in this section that can help readers understand the model or model card. -->
187
-
188
- [More Information Needed]
189
-
190
- ## More Information [optional]
191
-
192
- [More Information Needed]
193
-
194
- ## Model Card Authors [optional]
195
-
196
- [More Information Needed]
197
-
198
- ## Model Card Contact
199
-
200
- [More Information Needed]
 
2
  library_name: transformers
3
  datasets:
4
  - weblab-GENIAC/aya-ja-evol-instruct-calm3-dpo-masked
5
+ language:
6
+ - ja
7
+ base_model:
8
+ - llm-jp/llm-jp-3-13b
9
  ---
10
 
11
  # Model Card for Model ID
 
39
  - **Demo [optional]:** [More Information Needed]
40
 
41
  ## Uses
42
+ 実行の仕方は以下の通りです。 以下は、Model_Inference_Template_DPO_20241207.ipynbについて、モデルidのみを変えたものになっています。 omnicampus上での演習環境での使用を想定しています。
43
 
44
+ ```
45
+ !pip install -U ipywidgets
46
+ !pip install transformers
47
+ !pip install -U bitsandbytes
48
+ !pip install -U accelerate
49
+ !pip install -U datasets
50
+ !pip install -U peft
51
+ ```
52
 
 
53
 
54
+ ```python
55
+ from transformers import (
56
+ AutoModelForCausalLM,
57
+ AutoTokenizer,
58
+ BitsAndBytesConfig,
59
+ )
60
+ from peft import PeftModel
61
+ import torch
62
+ from tqdm import tqdm
63
+ import json
64
 
 
65
 
 
66
 
67
+ # Hugging Faceで取得したTokenをこちらに貼る。
68
+ HF_TOKEN = "your_token"
69
 
 
70
 
 
71
 
 
72
 
73
+ # ベースとなるモデルと学習したLoRAのアダプタ。
74
+ # model_idの値はomnicampusの環境におけるモデルのパスを表しており、それ以外の環境で実行する場合は変更の必要があります。
75
+ model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a"
76
+ # omnicampus以外の環境をご利用の方は以下をご利用ください。
77
+ # base_model_id = "llm-jp/llm-jp-3-13b"
78
+ adapter_id = "yuki-2000/llm-jp-3-13b-finetune1" # こちらにアップロードしたLoRAアダプタのHugging FaceのIDを指定してください。
79
+ adapter_dpo_id = "yuki-2000/llm-jp-3-13b-finetune1-dpo1" # こちらにアップロードしたDPOアダプタのHugging FaceのIDを指定してください。
80
 
 
81
 
 
82
 
 
83
 
84
+ # QLoRA config
85
+ bnb_config = BitsAndBytesConfig(
86
+ load_in_4bit=True,
87
+ bnb_4bit_quant_type="nf4",
88
+ bnb_4bit_compute_dtype=torch.bfloat16,
89
+ )
90
 
 
91
 
 
92
 
 
93
 
 
94
 
95
+ # Load model
96
+ model = AutoModelForCausalLM.from_pretrained(
97
+ model_id,
98
+ quantization_config=bnb_config,
99
+ device_map="auto",
100
+ token = HF_TOKEN
101
+ )
102
 
103
+ # Load tokenizer
104
+ tokenizer = AutoTokenizer.from_pretrained(model_id, trust_remote_code=True, token = HF_TOKEN)
105
 
 
106
 
107
+ # 元のモデルにLoRAのアダプタを統合。
108
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
109
 
110
+ # LoRAのモデルにDPOのアダプタを統合。
111
+ model = PeftModel.from_pretrained(model, adapter_dpo_id, token = HF_TOKEN)
112
 
113
+ # データセットの読み込み。
114
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
115
+ datasets = []
116
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
117
+ item = ""
118
+ for line in f:
119
+ line = line.strip()
120
+ item += line
121
+ if item.endswith("}"):
122
+ datasets.append(json.loads(item))
123
+ item = ""
124
 
125
+ # llmjp
126
+ results = []
127
+ for data in tqdm(datasets):
128
 
129
+ input = data["input"]
130
 
131
+ prompt = f"""### 指示
132
+ {input}
133
+ ### 回答
134
+ """
135
 
136
+ tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
137
+ attention_mask = torch.ones_like(tokenized_input)
138
+ with torch.no_grad():
139
+ outputs = model.generate(
140
+ tokenized_input,
141
+ attention_mask=attention_mask,
142
+ max_new_tokens=100,
143
+ do_sample=False,
144
+ repetition_penalty=1.2,
145
+ pad_token_id=tokenizer.eos_token_id
146
+ )[0]
147
+ output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
148
 
149
+ results.append({"task_id": data["task_id"], "input": input, "output": output})
150
 
151
+ # こちらで生成されたjsolを提出してください。
152
+ # 本コードではinputも含んでいますが、なくても問題ありません。
153
+ # 必須なのはtask_idとoutputとなります。
154
+ import re
155
+ jsonl_id = re.sub(".*/", "", adapter_dpo_id)
156
+ with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
157
+ for result in results:
158
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
159
+ f.write('\n')
160
+ ```