Transformers
Safetensors
English
Japanese
text-generation-inference
unsloth
llama
trl
Inference Endpoints
rlcgn589 commited on
Commit
d9928ad
·
verified ·
1 Parent(s): 87077ab

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +171 -195
README.md CHANGED
@@ -1,200 +1,176 @@
 
 
1
  ---
2
- library_name: transformers
3
  tags:
 
 
4
  - unsloth
 
 
 
 
 
 
 
 
 
5
  ---
6
 
7
- # Model Card for Model ID
8
-
9
- <!-- Provide a quick summary of what the model is/does. -->
10
-
11
-
12
-
13
- ## Model Details
14
-
15
- ### Model Description
16
-
17
- <!-- Provide a longer summary of what this model is. -->
18
-
19
- This is the model card of a 🤗 transformers model that has been pushed on the Hub. This model card has been automatically generated.
20
-
21
- - **Developed by:** [More Information Needed]
22
- - **Funded by [optional]:** [More Information Needed]
23
- - **Shared by [optional]:** [More Information Needed]
24
- - **Model type:** [More Information Needed]
25
- - **Language(s) (NLP):** [More Information Needed]
26
- - **License:** [More Information Needed]
27
- - **Finetuned from model [optional]:** [More Information Needed]
28
-
29
- ### Model Sources [optional]
30
-
31
- <!-- Provide the basic links for the model. -->
32
-
33
- - **Repository:** [More Information Needed]
34
- - **Paper [optional]:** [More Information Needed]
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]
 
1
+ 最終提出README
2
+
3
  ---
4
+ base_model: llm-jp/llm-jp-3-13b
5
  tags:
6
+ - text-generation-inference
7
+ - transformers
8
  - unsloth
9
+ - llama
10
+ - trl
11
+ license: other
12
+ language:
13
+ - en
14
+ - ja
15
+ datasets:
16
+ - Aratako/Magpie-Tanuki-8B—annotated-96k
17
+ - tohoku-nlp/abc-multiple-choice
18
  ---
19
 
20
+ # Uploaded model
21
+
22
+ - **Developed by:** rlcgn589
23
+ - **License:** other
24
+ - **Finetuned from model :** llm-jp/llm-jp-3-13b
25
+
26
+ This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
27
+
28
+ [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
29
+
30
+ # Usage(Code for inference)
31
+ 本モデルを用いてELYZA-tasks-100-TVの出力を得るためのコードです。
32
+ なお、松尾研LLM講座2024の最終コンペ課題の提出物を得ることを目的としたコードです。そのため、コンペの評価用途以外は使用禁止とします。
33
+ このコードで生成されたjsonlファイルは課題の成果として提出可能なフォーマットになっています。
34
+
35
+ ## 環境構築
36
+ omnicampus環境下で事前にterminalで環境構築の必要があります。
37
+ ```
38
+ # conda環境の構築
39
+ wget "https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-$(uname)-$(uname -m).sh"
40
+
41
+ # このコマンドではいくつか質問があるので答えて下さい
42
+ bash Miniforge3-$(uname)-$(uname -m).sh
43
+
44
+ # 以下、インストール先が/root/miniforge3であることを前提とします
45
+ export PATH=/root/miniforge3/bin:$PATH
46
+ conda init
47
+
48
+ # ここで一度、terminalを立ち上げ直す必要があります。
49
+ # 以下のリンク先に従い環境を作ります
50
+ # https://docs.unsloth.ai/get-started/installation/conda-install
51
+ conda create --name unsloth_env python=3.10 pytorch-cuda=12.1 pytorch cudatoolkit xformers -c pytorch -c nvidia -c xformers -y
52
+ conda activate unsloth_env
53
+ pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
54
+ pip install --no-deps "trl<0.9.0" peft accelerate bitsandbytes
55
+
56
+ # jupyter notebook用のセットアップ。
57
+ conda install -c conda-forge ipykernel -y
58
+ python -m ipykernel install --user --name=unsloth_env --display-name "Python (unsloth_env)"
59
+ ```
60
+
61
+ ## 推論用コードの実行
62
+ ```python
63
+ # 必要なライブラリを読み込み
64
+ from unsloth import FastLanguageModel
65
+ from peft import PeftModel
66
+ import torch
67
+ import json
68
+ from tqdm import tqdm
69
+ import re
70
+
71
+ # ベースとなるモデルと学習したLoRAのアダプタ。
72
+ # model_idの値はomnicampusの環境におけるモデルのパスを表しており、それ以外の環境で実行する場合は変更の必要があります。
73
+ model_id = "models/models--llm-jp--llm-jp-3-13b/snapshots/cd3823f4c1fcbb0ad2e2af46036ab1b0ca13192a"
74
+ adapter_id = "rlcgn589/llm-jp-3-13b-it-12_lora"
75
+
76
+ # Hugging Face Token を指定。
77
+ HF_TOKEN = "your Hugging Face Token"
78
+
79
+ # unslothのFastLanguageModelで元のモデルをロード。
80
+ dtype = None # Noneにしておけば自動で設定
81
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
82
+
83
+ model, tokenizer = FastLanguageModel.from_pretrained(
84
+ model_name=model_id,
85
+ dtype=dtype,
86
+ load_in_4bit=load_in_4bit,
87
+ trust_remote_code=True,
88
+ )
89
+
90
+ # 元のモデルにLoRAのアダプタを統合。
91
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
92
+
93
+ # データセットの読み込み。
94
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
95
+ datasets = []
96
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
97
+ item = ""
98
+ for line in f:
99
+ line = line.strip()
100
+ item += line
101
+ if item.endswith("}"):
102
+ datasets.append(json.loads(item))
103
+ item = ""
104
+
105
+ # モデルを用いてタスクの推論。
106
+
107
+ # 推論するためにモデルのモードを変更
108
+ FastLanguageModel.for_inference(model)
109
+
110
+ results = []
111
+ for dt in tqdm(datasets):
112
+ input = dt["input"]
113
+
114
+ prompt = f"""### 指示\n{input}簡潔に回答してください。\n### 回答\n"""
115
+
116
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
117
+
118
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
119
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
120
+
121
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
122
+
123
+ # 結果をjsonlで保存。
124
+ jsonl_id = re.sub(".*/", "", adapter_id)
125
+ with open(f"./{jsonl_id}-outputs.jsonl", 'w', encoding='utf-8') as f:
126
+ for result in results:
127
+ json.dump(result, f, ensure_ascii=False) # ensure_ascii=False for handling non-ASCII characters
128
+ f.write('\n')
129
+ ```
130
+
131
+ ## Datasets
132
+
133
+ ### Instruction tuning
134
+ 本モデルは以下のデータセットでファインチューニングしました。
135
+
136
+ | Language | Dataset | description |
137
+ |:---|:---|:---|
138
+ |Japanese| Aratako/Magpie-Tanuki-8B-annotated-96k | MagpieとTanuki-8B-dpo-v1.0で作成されたデータにcalm3-22bでアノテーションを施した合成データを一部使用 |
139
+ |Japanese| tohoku-nlp/abc-multiple-choice | オリジナルの4択の選択肢問題を一部加工(クイズと回答は変えていない) |
140
+
141
+ ### Data Source
142
+ ファインチューニング用のデータセット作成に作成者が使用したモデルとツールを示します。データを使わせていただきありがとうございます。
143
+
144
+ #### Tanuki-8B-dpo-v1.0
145
+ https://huggingface.co/weblab-GENIAC/Tanuki-8B-dpo-v1.0
146
+
147
+ #### Magpie
148
+ ```tex
149
+ @misc{xu2024magpiealignmentdatasynthesis,
150
+ title={Magpie: Alignment Data Synthesis from Scratch by Prompting Aligned LLMs with Nothing},
151
+ author={Zhangchen Xu and Fengqing Jiang and Luyao Niu and Yuntian Deng and Radha Poovendran and Yejin Choi and Bill Yuchen Lin},
152
+ year={2024},
153
+ eprint={2406.08464},
154
+ archivePrefix={arXiv},
155
+ primaryClass={cs.CL},
156
+ url={https://arxiv.org/abs/2406.08464},
157
+ }
158
+ ```
159
+
160
+ #### CyberAgentLM3-22B-Chat 
161
+ ```tex
162
+ @misc{cyberagent-calm3-22b-chat,
163
+ title={cyberagent/calm3-22b-chat},
164
+ url={https://huggingface.co/cyberagent/calm3-22b-chat},
165
+ author={Ryosuke Ishigami},
166
+ year={2024},
167
+ }
168
+ ```
169
+
170
+ #### abc-multiple-choice
171
+ https://github.com/cl-tohoku/abc-multiple-choice
172
+ https://jedworkshop.github.io/JLR2024/materials/a-1.pdf
173
+
174
+ abc-multiple-choiceのライセンスに関する記載を抜粋して記します。
175
+ - 本データセットのクイズ問題の著作権は abc/EQIDEN 実行委員会 に帰属します。
176
+ - 本データセットは研究目的での利用許諾を得ているものです。商用目的での利用は不可とします。