michaelfeil commited on
Commit
c4cfb8c
1 Parent(s): 60a6856

Upload microsoft/phi-1_5 ctranslate2 weights

Browse files
README.md ADDED
@@ -0,0 +1,206 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ tags:
3
+ - ctranslate2
4
+ - int8
5
+ - float16
6
+
7
+ license: other
8
+ license_name: microsoft-research-license
9
+ license_link: https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx
10
+ language:
11
+ - en
12
+ pipeline_tag: text-generation
13
+ ---
14
+ # # Fast-Inference with Ctranslate2
15
+ Speedup inference while reducing memory by 2x-4x using int8 inference in C++ on CPU or GPU.
16
+
17
+ quantized version of [microsoft/phi-1_5](https://huggingface.co/microsoft/phi-1_5)
18
+ ```bash
19
+ pip install hf-hub-ctranslate2>=2.12.0 ctranslate2>=3.17.1
20
+ ```
21
+
22
+ ```python
23
+ # from transformers import AutoTokenizer
24
+ model_name = "michaelfeil/ct2fast-phi-1_5"
25
+
26
+
27
+ from hf_hub_ctranslate2 import GeneratorCT2fromHfHub
28
+ model = GeneratorCT2fromHfHub(
29
+ # load in int8 on CUDA
30
+ model_name_or_path=model_name,
31
+ device="cuda",
32
+ compute_type="int8_float16",
33
+ # tokenizer=AutoTokenizer.from_pretrained("{ORG}/{NAME}")
34
+ )
35
+ outputs = model.generate(
36
+ text=["def fibonnaci(", "User: How are you doing? Bot:"],
37
+ max_length=64,
38
+ include_prompt_in_result=False
39
+ )
40
+ print(outputs)
41
+ ```
42
+
43
+ Checkpoint compatible to [ctranslate2>=3.22.0](https://github.com/OpenNMT/CTranslate2)
44
+ and [hf-hub-ctranslate2>=2.12.0](https://github.com/michaelfeil/hf-hub-ctranslate2)
45
+ - `compute_type=int8_float16` for `device="cuda"`
46
+ - `compute_type=int8` for `device="cpu"`
47
+
48
+ Converted on 2023-11-29 using
49
+ ```
50
+ TransformersConverter(
51
+ "microsoft/phi-1_5",
52
+ activation_scales=None,
53
+ copy_files=['vocab.json', 'tokenizer.json', 'generation_config.json', 'README.md', 'special_tokens_map.json', 'merges.txt', 'Research License.docx', 'tokenizer_config.json', 'added_tokens.json', '.gitattributes'],
54
+ load_as_float16=True,
55
+ revision=None,
56
+ low_cpu_mem_usage=True,
57
+ trust_remote_code=True,
58
+ ).convert(
59
+ output_dir=str(tmp_dir),
60
+ vmap = None,
61
+ quantization="int8_float16",
62
+ force = True,
63
+ )
64
+
65
+ ```
66
+
67
+ # Licence and other remarks:
68
+ This is just a quantized version. Licence conditions are intended to be idential to original huggingface repo.
69
+
70
+ # Original description
71
+
72
+ ## Model Summary
73
+
74
+ The language model phi-1.5 is a Transformer with **1.3 billion** parameters. It was trained using the same data sources as [phi-1](https://huggingface.co/microsoft/phi-1), augmented with a new data source that consists of various NLP synthetic texts. When assessed against benchmarks testing common sense, language understanding, and logical reasoning, phi-1.5 demonstrates a nearly state-of-the-art performance among models with less than 10 billion parameters.
75
+
76
+ We **did not** fine-tune phi-1.5 either for **instruction following or through reinforcement learning from human feedback**. The intention behind crafting this open-source model is to provide the research community with a non-restricted small model to explore vital safety challenges, such as reducing toxicity, understanding societal biases, enhancing controllability, and more.
77
+
78
+ For a safer model release, we exclude generic web-crawl data sources such as common-crawl from the training. This strategy prevents direct exposure to potentially harmful online content, enhancing the model's safety without RLHF. However, the model is still vulnerable to generating harmful content. We hope the model can help the research community to further study the safety of language models.
79
+
80
+ phi-1.5 can write poems, draft emails, create stories, summarize texts, write Python code (such as downloading a Hugging Face transformer model), etc.
81
+
82
+ ## Intended Uses
83
+ Given the nature of the training data, phi-1.5 is best suited for prompts using the QA format, the chat format, and the code format. Note that phi-1.5, being a base model, often produces irrelevant text following the main answer. In the following example, we've truncated the answer for illustrative purposes only.
84
+
85
+ #### QA format:
86
+
87
+ ```markdown
88
+ Write a detailed analogy between mathematics and a lighthouse.
89
+
90
+ Answer: Mathematics is like a lighthouse, guiding us through the vast ocean of numbers and calculations. Just as a lighthouse illuminates the darkness, mathematics provides us with a clear path to navigate through complex problems. It helps us make sense of the world around us, just like a lighthouse helps ships find their way home.
91
+ ```
92
+ where the model generates the text after "Answer:".
93
+
94
+ #### Chat format:
95
+
96
+ ```markdown
97
+ Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
98
+
99
+ Bob: Have you tried using a timer? It can help you stay on track and avoid distractions.
100
+
101
+ Alice: That's a good idea. I'll give it a try.
102
+
103
+ Charlie: Another thing that can help is to break up your study sessions into smaller chunks. It's easier to concentrate on one thing at a time.
104
+
105
+ Alice: That makes sense. I'll try that too.
106
+
107
+ Bob: And don't forget to take breaks! It's important to give your brain a rest so you can come back to your studies with a fresh perspective.
108
+
109
+ Alice: Thanks for the advice, guys. I feel more motivated now.
110
+
111
+ Charlie: No problem, Alice. We're all in this together.
112
+
113
+ Bob: Yeah, and remember that it's okay to ask for help if you need it. We're here to support each other.
114
+ ```
115
+ where the model generates the text after the first "Bob:".
116
+
117
+ #### Code format:
118
+ ```python
119
+ def print_prime(n):
120
+ """
121
+ Print all primes between 1 and n
122
+ """
123
+ primes = []
124
+ for num in range(2, n+1):
125
+ is_prime = True
126
+ for i in range(2, int(math.sqrt(num))+1):
127
+ if num % i == 0:
128
+ is_prime = False
129
+ break
130
+ if is_prime:
131
+ primes.append(num)
132
+ print(primes)
133
+ ```
134
+ where the model generates the text after the comments.
135
+
136
+ **Notes**
137
+ * phi-1.5 is intended for research purposes. The model-generated text/code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing these models in their applications.
138
+ * Direct adoption for production tasks is out of the scope of this research project. As a result, phi-1.5 has not been tested to ensure that it performs adequately for any production-level application. Please refer to the limitation sections of this document for more details.
139
+
140
+ ## Limitations of phi-1.5
141
+
142
+ * Generate Inaccurate Code and Facts: The model often produces incorrect code snippets and statements. Users should treat these outputs as suggestions or starting points, not as definitive or accurate solutions.
143
+ * Limited Scope for code: If the model generates Python scripts that utilize uncommon packages or scripts in other languages, we strongly recommend users manually verify all API uses.
144
+ * Unreliable Responses to Instruction: The model has not undergone instruction fine-tuning. As a result, it may struggle or fail to adhere to intricate or nuanced instructions provided by users.
145
+ * Language Limitations: The model is primarily designed to understand standard English. Informal English, slang, or any other language outside of English might pose challenges to its comprehension, leading to potential misinterpretations or errors in response.
146
+ * Potential Societal Biases: Regardless of the safe data used for its training, the model is not entirely free from societal biases. There's a possibility it may generate content that mirrors these societal biases, particularly if prompted or instructed to do so. We urge users to be aware of this and to exercise caution and critical thinking when interpreting model outputs.
147
+ * Toxicity: Despite that the model is trained with carefully selected data, the model can still produce harmful content if explicitly prompted or instructed to do so. We chose to release the model for research purposes only -- We hope to help the open-source community develop the most effective ways to reduce the toxicity of a model directly after pretraining.
148
+
149
+ ## Training
150
+
151
+ ### Model
152
+ * Architecture: a Transformer-based model with next-word prediction objective
153
+ * Dataset size: 30B tokens
154
+ * Training tokens: 150B tokens
155
+ * Precision: fp16
156
+ * GPUs: 32xA100-40G
157
+ * Training time: 8 days
158
+
159
+ ### Software
160
+ * [PyTorch](https://github.com/pytorch/pytorch)
161
+ * [DeepSpeed](https://github.com/microsoft/DeepSpeed)
162
+ * [flash-attention](https://github.com/HazyResearch/flash-attention)
163
+
164
+ ### License
165
+ The model is licensed under the [Research License](https://huggingface.co/microsoft/phi-1_5/resolve/main/Research%20License.docx).
166
+
167
+ ### Sample Code
168
+ ```python
169
+ import torch
170
+ from transformers import AutoModelForCausalLM, AutoTokenizer
171
+
172
+ torch.set_default_device("cuda")
173
+ model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1_5", trust_remote_code=True)
174
+ tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1_5", trust_remote_code=True)
175
+ inputs = tokenizer('''```python
176
+ def print_prime(n):
177
+ """
178
+ Print all primes between 1 and n
179
+ """''', return_tensors="pt", return_attention_mask=False)
180
+
181
+ outputs = model.generate(**inputs, max_length=200)
182
+ text = tokenizer.batch_decode(outputs)[0]
183
+ print(text)
184
+ ```
185
+
186
+ If you need to use the model in a lower precision (e.g., FP16), please wrap the model's forward pass with `torch.autocast()`, as follows:
187
+ ```python
188
+ with torch.autocast(model.device.type, dtype=torch.float16, enabled=True):
189
+ outputs = model.generate(**inputs, max_length=200)
190
+ ```
191
+
192
+ **Remark.** In the generation function, our model currently does not support beam search (`num_beams` > 1).
193
+ Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings (instead of the model's).
194
+
195
+ ### Citation
196
+
197
+ You can find the paper at https://arxiv.org/abs/2309.05463
198
+
199
+ ```bib
200
+ @article{textbooks2,
201
+ title={Textbooks Are All You Need II: \textbf{phi-1.5} technical report},
202
+ author={Li, Yuanzhi and Bubeck, S{\'e}bastien and Eldan, Ronen and Del Giorno, Allie and Gunasekar, Suriya and Lee, Yin Tat},
203
+ journal={arXiv preprint arXiv:2309.05463},
204
+ year={2023}
205
+ }
206
+ ```
Research License.docx ADDED
Binary file (38.9 kB). View file
 
added_tokens.json ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "\t\t": 50294,
3
+ "\t\t\t": 50293,
4
+ "\t\t\t\t": 50292,
5
+ "\t\t\t\t\t": 50291,
6
+ "\t\t\t\t\t\t": 50290,
7
+ "\t\t\t\t\t\t\t": 50289,
8
+ "\t\t\t\t\t\t\t\t": 50288,
9
+ "\t\t\t\t\t\t\t\t\t": 50287,
10
+ " ": 50286,
11
+ " ": 50285,
12
+ " ": 50284,
13
+ " ": 50283,
14
+ " ": 50282,
15
+ " ": 50281,
16
+ " ": 50280,
17
+ " ": 50279,
18
+ " ": 50278,
19
+ " ": 50277,
20
+ " ": 50276,
21
+ " ": 50275,
22
+ " ": 50274,
23
+ " ": 50273,
24
+ " ": 50272,
25
+ " ": 50271,
26
+ " ": 50270,
27
+ " ": 50269,
28
+ " ": 50268,
29
+ " ": 50267,
30
+ " ": 50266,
31
+ " ": 50265,
32
+ " ": 50264,
33
+ " ": 50263,
34
+ " ": 50262,
35
+ " ": 50261,
36
+ " ": 50260,
37
+ " ": 50259,
38
+ " ": 50258,
39
+ " ": 50257
40
+ }
config.json ADDED
@@ -0,0 +1,34 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "microsoft/phi-1_5",
3
+ "activation_function": "gelu_new",
4
+ "architectures": [
5
+ "PhiForCausalLM"
6
+ ],
7
+ "attn_pdrop": 0.0,
8
+ "auto_map": {
9
+ "AutoConfig": "configuration_phi.PhiConfig",
10
+ "AutoModelForCausalLM": "modeling_phi.PhiForCausalLM"
11
+ },
12
+ "embd_pdrop": 0.0,
13
+ "flash_attn": false,
14
+ "flash_rotary": false,
15
+ "fused_dense": false,
16
+ "initializer_range": 0.02,
17
+ "layer_norm_epsilon": null,
18
+ "model_type": "phi",
19
+ "n_embd": 2048,
20
+ "n_head": 32,
21
+ "n_head_kv": null,
22
+ "n_inner": null,
23
+ "n_layer": 24,
24
+ "n_positions": 2048,
25
+ "resid_pdrop": 0.0,
26
+ "rotary_dim": 32,
27
+ "tie_word_embeddings": false,
28
+ "torch_dtype": "float16",
29
+ "transformers_version": "4.34.1",
30
+ "vocab_size": 51200,
31
+ "bos_token": "<|endoftext|>",
32
+ "eos_token": "<|endoftext|>",
33
+ "unk_token": "<|endoftext|>"
34
+ }
generation_config.json ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "transformers_version": "4.32.1"
4
+ }
merges.txt ADDED
The diff for this file is too large to render. See raw diff
 
model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:074cee36d5a778ea5c274df988e533f1ea974e1ed0c977753779340dca7fb225
3
+ size 1421069301
special_tokens_map.json ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<|endoftext|>",
3
+ "eos_token": "<|endoftext|>",
4
+ "unk_token": "<|endoftext|>"
5
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "bos_token": "<|endoftext|>",
4
+ "clean_up_tokenization_spaces": true,
5
+ "eos_token": "<|endoftext|>",
6
+ "model_max_length": 2048,
7
+ "tokenizer_class": "CodeGenTokenizer",
8
+ "unk_token": "<|endoftext|>"
9
+ }
vocab.json ADDED
The diff for this file is too large to render. See raw diff
 
vocabulary.json ADDED
The diff for this file is too large to render. See raw diff
 
vocabulary.txt ADDED
The diff for this file is too large to render. See raw diff