RichardErkhov
commited on
Commit
•
ffa8b1f
1
Parent(s):
bfe051f
uploaded readme
Browse files
README.md
ADDED
@@ -0,0 +1,161 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Quantization made by Richard Erkhov.
|
2 |
+
|
3 |
+
[Github](https://github.com/RichardErkhov)
|
4 |
+
|
5 |
+
[Discord](https://discord.gg/pvy7H8DZMG)
|
6 |
+
|
7 |
+
[Request more models](https://github.com/RichardErkhov/quant_request)
|
8 |
+
|
9 |
+
|
10 |
+
phi-1 - bnb 4bits
|
11 |
+
- Model creator: https://huggingface.co/microsoft/
|
12 |
+
- Original model: https://huggingface.co/microsoft/phi-1/
|
13 |
+
|
14 |
+
|
15 |
+
|
16 |
+
|
17 |
+
Original model description:
|
18 |
+
---
|
19 |
+
license: mit
|
20 |
+
license_link: https://huggingface.co/microsoft/phi-1/resolve/main/LICENSE
|
21 |
+
language:
|
22 |
+
- en
|
23 |
+
pipeline_tag: text-generation
|
24 |
+
tags:
|
25 |
+
- code
|
26 |
+
---
|
27 |
+
|
28 |
+
## Model Summary
|
29 |
+
|
30 |
+
The language model Phi-1 is a Transformer with 1.3 billion parameters, specialized for basic Python coding. Its training involved a variety of data sources, including subsets of Python codes from [The Stack v1.2](https://huggingface.co/datasets/bigcode/the-stack), Q&A content from [StackOverflow](https://archive.org/download/stackexchange), competition code from [code_contests](https://github.com/deepmind/code_contests), and synthetic Python textbooks and exercises generated by [gpt-3.5-turbo-0301](https://platform.openai.com/docs/models/gpt-3-5). Even though the model and the datasets are relatively small compared to contemporary Large Language Models (LLMs), Phi-1 has demonstrated an impressive accuracy rate exceeding 50% on the simple Python coding benchmark, HumanEval.
|
31 |
+
|
32 |
+
## How to Use
|
33 |
+
|
34 |
+
Phi-1 has been integrated in the `transformers` version 4.37.0. If you are using a lower version, ensure that you are doing the following:
|
35 |
+
|
36 |
+
* When loading the model, ensure that `trust_remote_code=True` is passed as an argument of the `from_pretrained()` function.
|
37 |
+
|
38 |
+
The current `transformers` version can be verified with: `pip list | grep transformers`.
|
39 |
+
|
40 |
+
## Intended Uses
|
41 |
+
|
42 |
+
Given the nature of the training data, Phi-1 is best suited for prompts using the code format:
|
43 |
+
|
44 |
+
### Code Format:
|
45 |
+
|
46 |
+
```python
|
47 |
+
def print_prime(n):
|
48 |
+
"""
|
49 |
+
Print all primes between 1 and n
|
50 |
+
"""
|
51 |
+
for num in range(2, n+1):
|
52 |
+
for i in range(2, num):
|
53 |
+
if num % i == 0:
|
54 |
+
break
|
55 |
+
else:
|
56 |
+
print(num)
|
57 |
+
```
|
58 |
+
|
59 |
+
where the model generates the code after the comments. (Note: This is a legitimate and correct use of the else statement in Python loops.)
|
60 |
+
|
61 |
+
**Notes:**
|
62 |
+
|
63 |
+
* Phi-1 is intended for code purposes. The model-generated code should be treated as a starting point rather than a definitive solution for potential use cases. Users should be cautious when employing this model in their applications.
|
64 |
+
|
65 |
+
* Direct adoption for production coding tasks is out of the scope of this research project. As a result, Phi-1 has not been tested to ensure that it performs adequately for production-level code. Please refer to the limitation sections of this document for more details.
|
66 |
+
|
67 |
+
* If you are using `transformers<4.37.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
|
68 |
+
|
69 |
+
## Sample Code
|
70 |
+
|
71 |
+
```python
|
72 |
+
import torch
|
73 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
74 |
+
|
75 |
+
torch.set_default_device("cuda")
|
76 |
+
|
77 |
+
model = AutoModelForCausalLM.from_pretrained("microsoft/phi-1", torch_dtype="auto", trust_remote_code=True)
|
78 |
+
tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-1", trust_remote_code=True)
|
79 |
+
|
80 |
+
inputs = tokenizer('''def print_prime(n):
|
81 |
+
"""
|
82 |
+
Print all primes between 1 and n
|
83 |
+
"""''', return_tensors="pt", return_attention_mask=False)
|
84 |
+
|
85 |
+
outputs = model.generate(**inputs, max_length=200)
|
86 |
+
text = tokenizer.batch_decode(outputs)[0]
|
87 |
+
print(text)
|
88 |
+
```
|
89 |
+
|
90 |
+
## Limitations of Phi-1
|
91 |
+
|
92 |
+
* Limited Scope: 99.8% of the Python scripts in our fine-tuning dataset use only the packages "typing, math, random, collections, datetime, itertools". If the model generates Python scripts that utilize other packages, we strongly recommend users manually verify all API uses.
|
93 |
+
|
94 |
+
* Replicate Scripts Online: As our model is trained on Python scripts found online, there is a small chance it may replicate such scripts, especially if they appear repetitively across different online sources.
|
95 |
+
|
96 |
+
* Generate Inaccurate Code: The model frequently generates incorrect code. We suggest that users view these outputs as a source of inspiration rather than definitive solutions.
|
97 |
+
* Unreliable Responses to Alternate Formats: Despite appearing to comprehend instructions in formats like Q&A or chat, our models often respond with inaccurate answers, even when seeming confident. Their capabilities with non-code formats are significantly more limited.
|
98 |
+
|
99 |
+
* Limitations on Natural Language Comprehension. As a coding bot, Phi-1's main focus is to help with coding-related questions. While it may have some natural language comprehension capabilities, its primary function is not to engage in general conversations or demonstrate common sense like a general AI assistant. Its strength lies in providing assistance and guidance in the context of programming and software development.
|
100 |
+
|
101 |
+
* Potential Biases: Phi-1, like other AI models, is trained on web and synthetic data. This data can contain biases and errors that might affect the AI's performance. Biases could stem from various sources like unbalanced representation, stereotypes, or controversial opinions present in the training data. As a result, the model might sometimes generate responses that reflect these biases or errors.
|
102 |
+
|
103 |
+
## Warning about Security Risks
|
104 |
+
|
105 |
+
When leveraging Phi-1, it's paramount to be vigilant. The model, though powerful, can inadvertently introduce security vulnerabilities in the generated code. Examples include, but are not limited to:
|
106 |
+
|
107 |
+
* Directory Traversal: The code might fail to implement safe checks against directory traversal attacks, potentially allowing unauthorized access to sensitive files on your system.
|
108 |
+
|
109 |
+
* Injection Attacks: There could be lapses in escaping strings properly, making the application susceptible to SQL, OS commands, or other injection attacks.
|
110 |
+
|
111 |
+
* Misunderstanding Requirements: The model might sometimes misunderstand or oversimplify user requirements, leading to incomplete or insecure solutions.
|
112 |
+
|
113 |
+
* Lack of Input Validation: In some cases, the model might neglect to incorporate input validation or sanitize user inputs, opening doors to attacks like Cross-Site Scripting (XSS).
|
114 |
+
|
115 |
+
* Insecure Defaults: The model might recommend or generate code with insecure default settings, such as weak password requirements or unencrypted data transmissions.
|
116 |
+
|
117 |
+
* Failure in Error Handling: Improper error handling can inadvertently reveal sensitive information about the system or the application's internal workings.
|
118 |
+
|
119 |
+
Given these potential pitfalls, and others not explicitly mentioned, it's essential to thoroughly review, test, and verify the generated code before deploying it in any application, especially those that are security-sensitive. Always consult with security experts or perform rigorous penetration testing when in doubt.
|
120 |
+
|
121 |
+
## Training
|
122 |
+
|
123 |
+
### Model
|
124 |
+
|
125 |
+
* Architecture: a Transformer-based model with next-word prediction objective
|
126 |
+
|
127 |
+
* Training tokens: 54B tokens (7B unique tokens)
|
128 |
+
|
129 |
+
* Precision: fp16
|
130 |
+
|
131 |
+
* GPUs: 8 A100
|
132 |
+
|
133 |
+
* Training time: 6 days
|
134 |
+
|
135 |
+
### Software
|
136 |
+
|
137 |
+
* [PyTorch](https://github.com/pytorch/pytorch)
|
138 |
+
|
139 |
+
* [DeepSpeed](https://github.com/microsoft/DeepSpeed)
|
140 |
+
|
141 |
+
* [Flash-Attention](https://github.com/HazyResearch/flash-attention)
|
142 |
+
|
143 |
+
### License
|
144 |
+
|
145 |
+
The model is licensed under the [MIT license](https://huggingface.co/microsoft/phi-1/resolve/main/LICENSE).
|
146 |
+
|
147 |
+
### Citation
|
148 |
+
|
149 |
+
```bib
|
150 |
+
@article{gunasekar2023textbooks,
|
151 |
+
title={Textbooks Are All You Need},
|
152 |
+
author={Gunasekar, Suriya and Zhang, Yi and Aneja, Jyoti and Mendes, Caio C{\'e}sar Teodoro and Del Giorno, Allie and Gopi, Sivakanth and Javaheripi, Mojan and Kauffmann, Piero and de Rosa, Gustavo and Saarikivi, Olli and others},
|
153 |
+
journal={arXiv preprint arXiv:2306.11644},
|
154 |
+
year={2023}
|
155 |
+
}
|
156 |
+
```
|
157 |
+
|
158 |
+
## Trademarks
|
159 |
+
|
160 |
+
This project may contain trademarks or logos for projects, products, or services. Authorized use of Microsoft trademarks or logos is subject to and must follow [Microsoft’s Trademark & Brand Guidelines](https://www.microsoft.com/en-us/legal/intellectualproperty/trademarks). Use of Microsoft trademarks or logos in modified versions of this project must not cause confusion or imply Microsoft sponsorship. Any use of third-party trademarks or logos are subject to those third-party’s policies.
|
161 |
+
|