daekeun-ml
commited on
Commit
β’
5791b0d
1
Parent(s):
e56c3e9
Update README.md
Browse files
README.md
CHANGED
@@ -1,200 +1,112 @@
|
|
1 |
---
|
2 |
library_name: transformers
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
3 |
tags:
|
4 |
- unsloth
|
|
|
|
|
5 |
---
|
6 |
|
7 |
-
#
|
8 |
-
|
9 |
-
<!-- Provide a quick summary of what the model is/does. -->
|
10 |
-
|
11 |
-
|
12 |
|
13 |
## Model Details
|
|
|
14 |
|
15 |
-
|
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 |
-
|
64 |
|
65 |
-
|
66 |
|
67 |
-
|
|
|
|
|
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 |
-
|
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 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
##
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
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)!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|