Manoj21k commited on
Commit
f74c54d
1 Parent(s): 53baec4

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +34 -107
README.md CHANGED
@@ -12,110 +12,56 @@ tags:
12
 
13
  ## Model Summary
14
 
15
- Phi-2 is a Transformer with **2.7 billion** parameters. It was trained using the same data sources as [Phi-1.5](https://huggingface.co/microsoft/phi-1.5), augmented with a new data source that consists of various NLP synthetic texts and filtered websites (for safety and educational value). When assessed against benchmarks testing common sense, language understanding, and logical reasoning, Phi-2 showcased a nearly state-of-the-art performance among models with less than 13 billion parameters.
16
 
17
- Our model hasn't been fine-tuned 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.
 
 
18
 
19
- ## Intended Uses
 
 
 
20
 
21
- Given the nature of the training data, the Phi-2 model is best suited for prompts using the QA format, the chat format, and the code format.
 
 
22
 
23
- ### QA Format:
 
 
24
 
25
- You can provide the prompt as a standalone question as follows:
 
26
 
27
- ```markdown
28
- Write a detailed analogy between mathematics and a lighthouse.
29
- ```
30
- where the model generates the text after "." .
31
- To encourage the model to write more concise answers, you can also try the following QA format using "Instruct: \<prompt\>\nOutput:"
32
- ```markdown
33
- Instruct: Write a detailed analogy between mathematics and a lighthouse.
34
- Output: Mathematics is like a lighthouse. Just as a lighthouse guides ships safely to shore, mathematics provides a guiding light in the world of numbers and logic. It helps us navigate through complex problems and find solutions. Just as a lighthouse emits a steady beam of light, mathematics provides a consistent framework for reasoning and problem-solving. It illuminates the path to understanding and helps us make sense of the world around us.
35
- ```
36
- where the model generates the text after "Output:".
37
 
38
- ### Chat Format:
39
-
40
- ```markdown
41
- Alice: I don't know why, I'm struggling to maintain focus while studying. Any suggestions?
42
- Bob: Well, have you tried creating a study schedule and sticking to it?
43
- Alice: Yes, I have, but it doesn't seem to help much.
44
- Bob: Hmm, maybe you should try studying in a quiet environment, like the library.
45
- Alice: ...
46
- ```
47
-
48
- where the model generates the text after the first "Bob:".
49
 
50
  ### Code Format:
51
 
52
  ```python
53
- def print_prime(n):
54
- """
55
- Print all primes between 1 and n
56
- """
57
- primes = []
58
- for num in range(2, n+1):
59
- is_prime = True
60
- for i in range(2, int(math.sqrt(num))+1):
61
- if num % i == 0:
62
- is_prime = False
63
- break
64
- if is_prime:
65
- primes.append(num)
66
- print(primes)
67
- ```
68
- where the model generates the text after the comments.
69
-
70
- **Notes:**
71
- * Phi-2 is intended for QA, chat, and code 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.
72
- * Direct adoption for production tasks without evaluation is out of scope of this project. As a result, the Phi-2 model 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.
73
- * If you are using `transformers>=4.36.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
74
-
75
- ## Sample Code
76
-
77
- There are four types of execution mode:
78
-
79
- 1. FP16 / Flash-Attention / CUDA:
80
- ```python
81
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", flash_attn=True, flash_rotary=True, fused_dense=True, device_map="cuda", trust_remote_code=True)
82
- ```
83
- 2. FP16 / CUDA:
84
- ```python
85
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", device_map="cuda", trust_remote_code=True)
86
- ```
87
- 3. FP32 / CUDA:
88
- ```python
89
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype=torch.float32, device_map="cuda", trust_remote_code=True)
90
- ```
91
- 4. FP32 / CPU:
92
- ```python
93
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype=torch.float32, device_map="cpu", trust_remote_code=True)
94
- ```
95
-
96
- To ensure the maximum compatibility, we recommend using the second execution mode (FP16 / CUDA), as follows:
97
-
98
- ```python
99
- import torch
100
  from transformers import AutoModelForCausalLM, AutoTokenizer
101
 
102
- torch.set_default_device("cuda")
103
-
104
- model = AutoModelForCausalLM.from_pretrained("microsoft/phi-2", torch_dtype="auto", trust_remote_code=True)
105
- tokenizer = AutoTokenizer.from_pretrained("microsoft/phi-2", trust_remote_code=True)
106
 
107
- inputs = tokenizer('''def print_prime(n):
108
- """
109
- Print all primes between 1 and n
110
- """''', return_tensors="pt", return_attention_mask=False)
 
111
 
112
- outputs = model.generate(**inputs, max_length=200)
113
- text = tokenizer.batch_decode(outputs)[0]
114
- print(text)
115
  ```
 
 
 
 
 
 
 
116
 
117
- **Remark:** In the generation function, our model currently does not support beam search (`num_beams > 1`).
118
- Furthermore, in the forward pass of the model, we currently do not support outputting hidden states or attention values, or using custom input embeddings.
119
 
120
  ## Limitations of Phi-2
121
 
@@ -133,21 +79,6 @@ Furthermore, in the forward pass of the model, we currently do not support outpu
133
 
134
  * Verbosity: Phi-2 being a base model often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily textbooks, which results in textbook-like responses.
135
 
136
- ## Training
137
-
138
- ### Model
139
-
140
- * Architecture: a Transformer-based model with next-word prediction objective
141
-
142
- * Context length: 2048 tokens
143
-
144
- * Dataset size: 250B tokens, combination of NLP synthetic data created by AOAI GPT-3.5 and filtered web data from Falcon RefinedWeb and SlimPajama, which was assessed by AOAI GPT-4.
145
-
146
- * Training tokens: 1.4T tokens
147
-
148
- * GPUs: 96xA100-80G
149
-
150
- * Training time: 14 days
151
 
152
  ### Software
153
 
@@ -159,8 +90,4 @@ Furthermore, in the forward pass of the model, we currently do not support outpu
159
 
160
  ### License
161
 
162
- The model is licensed under the [MIT license](https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE).
163
-
164
- ## Trademarks
165
-
166
- 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.
 
12
 
13
  ## Model Summary
14
 
15
+ ## Finetuned Model - Manoj21k/microsoft-phi-2-finetuned
16
 
17
+ # Alpaca Datasets Instruction Finetuning
18
+ We are pleased to introduce the Manoj21k/microsoft-phi-2-finetuned model, which has undergone fine-tuning using Alpaca datasets with instructional objectives.
19
+ This process aims to enhance the model's performance in understanding and generating responses based on specific instructions. Here are key details about this finetuned model:
20
 
21
+ ## Fine-Tuning Details:
22
+ # Datasets Used:
23
+ The model has been fine-tuned using Alpaca datasets, which are curated for instructional objectives.
24
+ These datasets provide diverse examples and scenarios to improve the model's ability to follow instructions accurately.
25
 
26
+ # Instructional Objectives:
27
+ The fine-tuning process emphasizes the model's proficiency in understanding and responding to prompts provided in an instructional format.
28
+ This includes scenarios where explicit instructions are given, allowing the model to generate more contextually relevant and task-specific outputs.
29
 
30
+ ## Intended Use Cases:
31
+ # Instruction-Based Tasks:
32
+ The finetuned model is particularly well-suited for tasks that involve providing instructions in the prompt, such as generating detailed responses, following specific guidelines, or addressing instructional queries.
33
 
34
+ # Enhanced Controllability:
35
+ Users can expect improved controllability when using this model, making it a valuable asset for applications where precise instruction adherence is crucial.
36
 
 
 
 
 
 
 
 
 
 
 
37
 
 
 
 
 
 
 
 
 
 
 
 
38
 
39
  ### Code Format:
40
 
41
  ```python
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42
  from transformers import AutoModelForCausalLM, AutoTokenizer
43
 
44
+ # Load the finetuned model
45
+ finetuned_model = AutoModelForCausalLM.from_pretrained("Manoj21k/microsoft-phi-2-finetuned")
 
 
46
 
47
+ # Tokenize input with instruction and generate output
48
+ tokenizer = AutoTokenizer.from_pretrained("Manoj21k/microsoft-phi-2-finetuned")
49
+ input_text = "Instruct: Provide a detailed explanation of..."
50
+ inputs = tokenizer(input_text, return_tensors="pt", return_attention_mask=False)
51
+ output = finetuned_model.generate(**inputs, max_length=200)
52
 
53
+ # Decode and print the generated text
54
+ decoded_output = tokenizer.batch_decode(output)[0]
55
+ print(decoded_output)
56
  ```
57
+ where the model generates the text after the comments.
58
+
59
+ **Notes:**
60
+ *The fine-tuned model is specialized for instruction-based tasks and may outperform the base Phi-2 model in scenarios that require adherence to explicit instructions.
61
+ *Users are encouraged to experiment with various instructional prompts to leverage the model's capabilities effectively.
62
+ *As always, we appreciate user feedback to continue refining and improving the model for a wide range of applications. you are using `transformers>=4.36.0`, always load the model with `trust_remote_code=True` to prevent side-effects.
63
+
64
 
 
 
65
 
66
  ## Limitations of Phi-2
67
 
 
79
 
80
  * Verbosity: Phi-2 being a base model often produces irrelevant or extra text and responses following its first answer to user prompts within a single turn. This is due to its training dataset being primarily textbooks, which results in textbook-like responses.
81
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
 
83
  ### Software
84
 
 
90
 
91
  ### License
92
 
93
+ The model is licensed under the [MIT license](https://huggingface.co/microsoft/phi-2/resolve/main/LICENSE).