hiraki commited on
Commit
1b2eae3
·
verified ·
1 Parent(s): 0429d43

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +216 -190
README.md CHANGED
@@ -3,200 +3,226 @@ base_model: google/gemma-2-9b-it
3
  library_name: peft
4
  ---
5
 
6
- # Model Card for Model ID
7
 
8
- <!-- Provide a quick summary of what the model is/does. -->
9
 
 
10
 
 
11
 
12
- ## Model Details
 
 
 
13
 
14
- ### Model Description
 
 
 
 
 
 
 
 
15
 
16
- <!-- Provide a longer summary of what this model is. -->
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
17
 
18
-
19
-
20
- - **Developed by:** [More Information Needed]
21
- - **Funded by [optional]:** [More Information Needed]
22
- - **Shared by [optional]:** [More Information Needed]
23
- - **Model type:** [More Information Needed]
24
- - **Language(s) (NLP):** [More Information Needed]
25
- - **License:** [More Information Needed]
26
- - **Finetuned from model [optional]:** [More Information Needed]
27
-
28
- ### Model Sources [optional]
29
-
30
- <!-- Provide the basic links for the model. -->
31
-
32
- - **Repository:** [More Information Needed]
33
- - **Paper [optional]:** [More Information Needed]
34
- - **Demo [optional]:** [More Information Needed]
35
-
36
- ## Uses
37
-
38
- <!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->
39
-
40
- ### Direct Use
41
-
42
- <!-- This section is for the model use without fine-tuning or plugging into a larger ecosystem/app. -->
43
-
44
- [More Information Needed]
45
-
46
- ### Downstream Use [optional]
47
-
48
- <!-- This section is for the model use when fine-tuned for a task, or when plugged into a larger ecosystem/app -->
49
-
50
- [More Information Needed]
51
-
52
- ### Out-of-Scope Use
53
-
54
- <!-- This section addresses misuse, malicious use, and uses that the model will not work well for. -->
55
-
56
- [More Information Needed]
57
-
58
- ## Bias, Risks, and Limitations
59
-
60
- <!-- This section is meant to convey both technical and sociotechnical limitations. -->
61
-
62
- [More Information Needed]
63
-
64
- ### Recommendations
65
-
66
- <!-- This section is meant to convey recommendations with respect to the bias, risk, and technical limitations. -->
67
-
68
- Users (both direct and downstream) should be made aware of the risks, biases and limitations of the model. More information needed for further recommendations.
69
-
70
- ## How to Get Started with the Model
71
-
72
- Use the code below to get started with the model.
73
-
74
- [More Information Needed]
75
-
76
- ## Training Details
77
-
78
- ### Training Data
79
-
80
- <!-- 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. -->
81
-
82
- [More Information Needed]
83
-
84
- ### Training Procedure
85
-
86
- <!-- This relates heavily to the Technical Specifications. Content here should link to that section when it is relevant to the training procedure. -->
87
-
88
- #### Preprocessing [optional]
89
-
90
- [More Information Needed]
91
-
92
-
93
- #### Training Hyperparameters
94
-
95
- - **Training regime:** [More Information Needed] <!--fp32, fp16 mixed precision, bf16 mixed precision, bf16 non-mixed precision, fp16 non-mixed precision, fp8 mixed precision -->
96
-
97
- #### Speeds, Sizes, Times [optional]
98
-
99
- <!-- This section provides information about throughput, start/end time, checkpoint size if relevant, etc. -->
100
-
101
- [More Information Needed]
102
-
103
- ## Evaluation
104
-
105
- <!-- This section describes the evaluation protocols and provides the results. -->
106
-
107
- ### Testing Data, Factors & Metrics
108
-
109
- #### Testing Data
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]
200
- ### Framework versions
201
-
202
- - PEFT 0.14.0
 
3
  library_name: peft
4
  ---
5
 
6
+ # Gemma-9B Instruction Tuned Model Inference Guide
7
 
8
+ このガイドでは、Hugging Faceからhiraki/gemma9b-it-sftモデルをダウンロードし、推論を実行する手順を説明します。
9
 
10
+ ## パッケージのインストール
11
 
12
+ はじめに、必要なパッケージをインストールします:
13
 
14
+ ```bash
15
+ # 依存関係のアップグレード
16
+ pip install --upgrade datasets bitsandbytes trl peft
17
+ pip install --upgrade torch
18
 
19
+ # その他の必要なパッケージ
20
+ pip install transformers tqdm
21
+ ```
22
+
23
+ ## 環境設定
24
+
25
+ - CUDA対応のGPU(最低16GB以上のVRAMを推奨)
26
+ - Python 3.8以上
27
+ - 十分なストレージ空間(モデルのダウンロード用)
28
 
29
+ ## インストールの確認
30
+
31
+ インストール後、以下のコードで環境を確認できます:
32
+
33
+ ```python
34
+ import torch
35
+ print(f"PyTorch version: {torch.__version__}")
36
+ print(f"CUDA available: {torch.cuda.is_available()}")
37
+ print(f"CUDA device count: {torch.cuda.device_count()}")
38
+ ```
39
+
40
+ ## 手順
41
+
42
+ ### 1. Hugging Faceの設定
43
+
44
+ ```python
45
+ import os
46
+
47
+ # HuggingFaceのトークンを設定
48
+ os.environ["HF_TOKEN"] = "your_token_here" # あなたのトークンに置き換えてください
49
+ ```
50
+
51
+ ### 2. 推論スクリプトの作成
52
+
53
+ 以下の内容で`inference.py`を作成してください:
54
+
55
+ ```python
56
+ import os
57
+ import json
58
+ import torch
59
+ from tqdm import tqdm
60
+ from peft import AutoPeftModelForCausalLM
61
+ from transformers import AutoTokenizer
62
+
63
+ def run_inference(model_path, input_file, output_file):
64
+ # モデルとトークナイザーの読み込み
65
+ print("モデルを読み込んでいます...")
66
+ model = AutoPeftModelForCausalLM.from_pretrained(
67
+ model_path,
68
+ device_map={"": "cuda"},
69
+ torch_dtype=torch.float16,
70
+ )
71
+
72
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
73
+
74
+ if tokenizer.pad_token is None:
75
+ tokenizer.pad_token = tokenizer.eos_token
76
+ tokenizer.padding_side = "right"
77
+
78
+ # 入力データの読み込み
79
+ print("入力データを読み込んでいます...")
80
+ data = []
81
+ with open(input_file, 'r', encoding='utf-8') as f:
82
+ for line in f:
83
+ data.append(json.loads(line))
84
 
85
+ # 推論実行
86
+ results = []
87
+ print("推論を実行中...")
88
+ for dt in tqdm(data, desc="Processing"):
89
+ task_id = dt["task_id"]
90
+ input_text = dt["input"]
91
+
92
+ # プロンプトの生成
93
+ prompt = f"### 指示\n{input_text}\n### 回答\n"
94
+
95
+ # 入力のトークン化
96
+ inputs = tokenizer([prompt], return_tensors="pt").to("cuda")
97
+
98
+ # 出力の生成
99
+ outputs = model.generate(
100
+ inputs.input_ids,
101
+ attention_mask=inputs.attention_mask,
102
+ max_new_tokens=512,
103
+ temperature=0.7,
104
+ top_p=0.9,
105
+ repetition_penalty=1.2,
106
+ do_sample=False
107
+ )
108
+
109
+ # 出力のデコード
110
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('### 回答\n')[-1].strip()
111
+
112
+ # 結果を保存
113
+ results.append({
114
+ "task_id": task_id,
115
+ "input": input_text,
116
+ "output": prediction
117
+ })
118
+
119
+ # 結果の保存
120
+ print(f"結果を保存中: {output_file}")
121
+ with open(output_file, 'w', encoding='utf-8') as f:
122
+ for result in results:
123
+ json.dump(result, f, ensure_ascii=False)
124
+ f.write('\n')
125
+
126
+ print("処理が完了しました")
127
+ return results
128
+
129
+ if __name__ == "__main__":
130
+ model_path = "hiraki/gemma9b-it-sft"
131
+ input_file = "elyza-tasks-100-TV_0.jsonl" # 入力ファイル名
132
+ output_file = "output.jsonl" # 出力ファイル名
133
+
134
+ results = run_inference(model_path, input_file, output_file)
135
+
136
+ # 最初の結果を表示して確認
137
+ print("\n最初の結果の例:")
138
+ print(json.dumps(results[0], ensure_ascii=False, indent=2))
139
+ ```
140
+
141
+ ### 3. 入力データの準備
142
+
143
+ 入力JSONLファイルは以下の形式である必要があります:
144
+
145
+ ```json
146
+ {
147
+ "task_id": "タスクの一意な識別子",
148
+ "input": "入力テキスト"
149
+ }
150
+ ```
151
+
152
+ ### 4. 実行
153
+
154
+ ```bash
155
+ python inference.py
156
+ ```
157
+
158
+ ## 出力形式
159
+
160
+ 出力されるJSONLファイルは以下の形式です:
161
+
162
+ ```json
163
+ {
164
+ "task_id": "タスクID",
165
+ "input": "入力テキスト",
166
+ "output": "生成されたテキスト"
167
+ }
168
+ ```
169
+
170
+ ## 生成パラメータのカスタマイズ
171
+
172
+ スクリプト内の以下のパラメータを調整することで、生成結果をカスタマイズできます:
173
+
174
+ - `max_new_tokens`: 生成する最大トークン数 (デフォルト: 512)
175
+ - `temperature`: 生成の多様性 (デフォルト: 0.7)
176
+ - `top_p`: サンプリングの閾値 (デフォルト: 0.9)
177
+ - `repetition_penalty`: 繰り返しの抑制 (デフォルト: 1.2)
178
+ - `do_sample`: ランダムサンプリングの有効/無効 (デフォルト: False)
179
+
180
+ ## トラブルシューティング
181
+
182
+ ### よくあるエラー
183
+
184
+ 1. CUDA Out of Memory
185
+ ```
186
+ RuntimeError: CUDA out of memory
187
+ ```
188
+ - 解決策:
189
+ - GPUのメモリを解放する
190
+ - `max_new_tokens`の値を小さくする
191
+ - より小さいバッチサイズを使用する
192
+
193
+ 2. パッケージのバージョンの不一致
194
+ ```
195
+ ImportError: Cannot import name 'X' from 'Y'
196
+ ```
197
+ - 解決策:
198
+ - すべてのパッケージを最新バージョンにアップグレードする
199
+ - `pip install --upgrade`コマンドを再実行する
200
+
201
+ 3. モデルのダウンロードエラー
202
+ ```
203
+ OSError: Incorrect Hugging Face token
204
+ ```
205
+ - 解決策:
206
+ - HF_TOKENが正しく設定されているか確認
207
+ - インターネット接続を確認
208
+
209
+ 4. 入力ファイルのフォーマットエラー
210
+ ```
211
+ JSONDecodeError: Expecting value
212
+ ```
213
+ - 解決策:
214
+ - 入力JSONLファイルの形式を確認
215
+ - ファイルのエンコーディングがUTF-8であることを確認
216
+
217
+ ## 注意事項
218
+
219
+ - 推論には十分なGPUメモリが必要です
220
+ - 大量のデータを処理する場合は、進捗バーで進行状況を確認できます
221
+ - 出力ファイルは自動的に上書きされるため、必要に応じてバックアップを作成してください
222
+
223
+ ## サポート
224
+
225
+ 問題が発生した場合は、以下を確認してください:
226
+ 1. Hugging Faceのモデルカード: [hiraki/gemma9b-it-sft](https://huggingface.co/hiraki/gemma9b-it-sft)
227
+ 2. PEFT GitHub: [microsoft/PEFT](https://github.com/microsoft/PEFT)
228
+ 3. Transformers GitHub: [huggingface/transformers](https://github.com/huggingface/transformers)