daekeun-ml commited on
Commit
5791b0d
β€’
1 Parent(s): e56c3e9

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +97 -185
README.md CHANGED
@@ -1,200 +1,112 @@
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
  ---
2
  library_name: transformers
3
+ license: apache-2.0
4
+ datasets:
5
+ - nampdn-ai/tiny-codes
6
+ - nlpai-lab/openassistant-guanaco-ko
7
+ - philschmid/guanaco-sharegpt-style
8
+ language:
9
+ - ko
10
+ - en
11
+ inference: false
12
  tags:
13
  - unsloth
14
+ - phi-3
15
+ pipeline_tag: text-generation
16
  ---
17
 
18
+ # Phi-3-medium-4k-instruct-ko-poc-v0.1
 
 
 
 
19
 
20
  ## Model Details
21
+ This model is trained using unsloth toolkit based on Microsoft's phi-3 model with some Korean instruction data added to enhance its Korean generation performance
22
 
23
+ Since my role is not as a working developer, but as ML Technical Specialist helping customers with quick PoCs/prototypes, and I was limited by Azure GPU resources available, I only trained with 40,000 samples on a single A100 GPU () for PoC purposes. Because I have not done any tokenizer extensions, you need a lot more tokens than English for text generation.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
+ ### Dataset
26
 
27
+ The dataset used for training is as follows. To prevent catastrophic forgetting, I included non-Korean corpus as training data. Note that we did not use all of the data, but only sampled some of it. Korean textbooks were converted to Q&A format. The Guanaco dataset has been reformatted to fit the multiturn format like <|user|>\n{Q1}<|end|>\n<|assistant|>\n{A1}<|end|>\n<|user|>\n{Q2}<|end|>\n<|assistant|>\n{A2}<|end|>.
28
 
29
+ - Korean textbooks (https://huggingface.co/datasets/nampdn-ai/tiny-codes)
30
+ - Korean translation of Guanaco (https://huggingface.co/datasets/nlpai-lab/openassistant-guanaco-ko)
31
+ - Guanaco Sharegpt style (https://huggingface.co/datasets/philschmid/guanaco-sharegpt-style)
32
 
 
33
 
34
  ## How to Get Started with the Model
35
+ ```python
36
+ ### Load model
37
+ import torch
38
+ from unsloth import FastLanguageModel
39
+ from unsloth.chat_templates import get_chat_template
40
+ from transformers import TextStreamer
41
+
42
+ max_seq_length = 2048 # Choose any! We auto support RoPE Scaling internally!
43
+ dtype = None # None for auto detection. Float16 for Tesla T4, V100, Bfloat16 for Ampere+
44
+ load_in_4bit = True # Use 4bit quantization to reduce memory usage. Can be False.
45
+ model_path = "daekeun-ml/Phi-3-medium-4k-instruct-ko-poc-v0.1"
46
+
47
+ model, tokenizer = FastLanguageModel.from_pretrained(
48
+ model_name = model_tar_dir, # Choose ANY! eg teknium/OpenHermes-2.5-Mistral-7B
49
+ max_seq_length = max_seq_length,
50
+ dtype = dtype,
51
+ load_in_4bit = load_in_4bit,
52
+ # token = "hf_...", # use one if using gated models like meta-llama/Llama-2-7b-hf
53
+ )
54
+ tokenizer = get_chat_template(
55
+ tokenizer,
56
+ chat_template = "phi-3", # Supports zephyr, chatml, mistral, llama, alpaca, vicuna, vicuna_old, unsloth
57
+ mapping = {"role" : "from", "content" : "value", "user" : "human", "assistant" : "gpt"}, # ShareGPT style
58
+ )
59
+
60
+ params = {
61
+ "max_new_tokens": 256,
62
+ "use_cache": True,
63
+ "temperature": 0.05,
64
+ "do_sample": True
65
+ }
66
+
67
+ ### Inference
68
+ FastLanguageModel.for_inference(model) # Enable native 2x faster inference
69
+
70
+ messages = [
71
+ {"from": "human", "value": "Continue the fibonnaci sequence in Korean: 1, 1, 2, 3, 5, 8,"},
72
+ {"from": "assistant", "value": "ν”Όλ³΄λ‚˜μΉ˜ μˆ˜μ—΄μ˜ λ‹€μŒ μˆ«μžλŠ” 13, 21, 34, 55, 89 λ“±μž…λ‹ˆλ‹€. 각 μˆ«μžλŠ” μ•žμ˜ 두 숫자의 ν•©μž…λ‹ˆλ‹€."},
73
+ {"from": "human", "value": "Compute 2x+3=12 in Korean"},
74
+ ]
75
+ inputs = tokenizer.apply_chat_template(
76
+ messages,
77
+ tokenize = True,
78
+ add_generation_prompt = True, # Must add for generation
79
+ return_tensors = "pt",
80
+ ).to("cuda")
81
+
82
+ text_streamer = TextStreamer(tokenizer)
83
+ _ = model.generate(input_ids = inputs, streamer = text_streamer, **params)
84
+
85
+ messages = [
86
+ {"from": "human", "value": "What is Machine Learning in Korean?"},
87
+ {"from": "assistant", "value": "인곡지λŠ₯의 ν•œ λΆ„μ•Όλ‘œ λ°©λŒ€ν•œ 데이터λ₯Ό 뢄석해 ν–₯ν›„ νŒ¨ν„΄μ„ μ˜ˆμΈ‘ν•˜λŠ” κΈ°λ²•μž…λ‹ˆλ‹€."},
88
+ {"from": "human", "value": "What is Deep Learning in Korean?"},
89
+ ]
90
+ inputs = tokenizer.apply_chat_template(
91
+ messages,
92
+ tokenize = True,
93
+ add_generation_prompt = True, # Must add for generation
94
+ return_tensors = "pt",
95
+ ).to("cuda")
96
+
97
+ from transformers import TextStreamer
98
+ text_streamer = TextStreamer(tokenizer)
99
+ _ = model.generate(input_ids = inputs, streamer = text_streamer, **params)
100
+ ```
101
+
102
+ ### References
103
+ - Base model: [microsoft/phi-2](https://huggingface.co/microsoft/phi-2)
104
+
105
+ ## Notes
106
+
107
+ ### License
108
+
109
+ apache 2.0; The license of phi-3 is MIT, but I considered the licensing of the dataset and library used for training.
110
+
111
+ ### Caution
112
+ This model was created as a personal experiment, unrelated to the organization I work for. The model may not operate correctly because separate verification was not performed. Please be careful unless it is for personal experimentation or PoC (Proof of Concept)!