RichardErkhov commited on
Commit
1c4e0db
·
verified ·
1 Parent(s): dce2137

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +178 -0
README.md ADDED
@@ -0,0 +1,178 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ phi3-mini-python-code-20k - AWQ
11
+ - Model creator: https://huggingface.co/edumunozsala/
12
+ - Original model: https://huggingface.co/edumunozsala/phi3-mini-python-code-20k/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ library_name: transformers
20
+ license: apache-2.0
21
+ datasets:
22
+ - iamtarun/python_code_instructions_18k_alpaca
23
+ language:
24
+ - en
25
+ metrics:
26
+ - rouge
27
+ ---
28
+
29
+ # Phi-3-mini 3.8B LoRA Python Coder 👩‍💻
30
+
31
+ **Phi-3-mini 3.8B** fine-tuned on the **python_code_instructions_18k_alpaca Code instructions dataset** by using the method **LoRA** with [PEFT](https://github.com/huggingface/peft) library.
32
+
33
+ ## Pretrained description
34
+
35
+ [Phi-3-mini-4k-instruct](https://huggingface.co/microsoft/Phi-3-mini-4k-instruct)
36
+
37
+ The Phi-3-Mini-4K-Instruct is a 3.8B parameters, lightweight, state-of-the-art open model trained with the Phi-3 datasets that includes both synthetic data and the filtered publicly available websites data with a focus on high-quality and reasoning dense properties. The model belongs to the Phi-3 family with the Mini version in two variants 4K and 128K which is the context length (in tokens) that it can support.
38
+
39
+ ## Tokenizer
40
+ Phi-3 Mini-4K-Instruct supports a vocabulary size of up to 32064 tokens. The tokenizer files already provide placeholder tokens that can be used for downstream fine-tuning, but they can also be extended up to the model's vocabulary size.
41
+
42
+ ## Training data
43
+
44
+ [python_code_instructions_18k_alpaca](https://huggingface.co/datasets/iamtarun/python_code_instructions_18k_alpaca)
45
+
46
+ The dataset contains problem descriptions and code in python language. This dataset is taken from sahil2801/code_instructions_120k, which adds a prompt column in alpaca style.
47
+
48
+ ### Chat Format
49
+ Given the nature of the training data, the Phi-3 Mini-4K-Instruct model is best suited for prompts using the chat format as follows. You can provide the prompt as a question with a generic template as follow:
50
+
51
+ ```
52
+ <|user|>\nQuestion <|end|>\n<|assistant|>
53
+ ```
54
+
55
+ For example:
56
+
57
+ ```
58
+ <|user|>
59
+ How to explain Internet for a medieval knight?<|end|>
60
+ <|assistant|>
61
+ ```
62
+
63
+ where the model generates the text after <|assistant|> . In case of few-shots prompt, the prompt can be formatted as the following:
64
+ ```
65
+ <|user|>
66
+ I am going to Paris, what should I see?<|end|>
67
+ <|assistant|>
68
+ Paris, the capital of France, is known for its stunning architecture, art museums, historical landmarks, and romantic atmosphere. Here are some of the top attractions to see in Paris:\n\n1. The Eiffel Tower: The iconic Eiffel Tower is one of the most recognizable landmarks in the world and offers breathtaking views of the city.\n2. The Louvre Museum: The Louvre is one of the world's largest and most famous museums, housing an impressive collection of art and artifacts, including the Mona Lisa.\n3. Notre-Dame Cathedral: This beautiful cathedral is one of the most famous landmarks in Paris and is known for its Gothic architecture and stunning stained glass windows.\n\nThese are just a few of the many attractions that Paris has to offer. With so much to see and do, it's no wonder that Paris is one of the most popular tourist destinations in the world."<|end|>
69
+ <|user|>
70
+ What is so great about #1?<|end|>
71
+ <|assistant|>
72
+ ```
73
+
74
+ ### Training hyperparameters
75
+
76
+ The following `PEFT` config was used during training:
77
+ ```py
78
+ ################################################################################
79
+ # LoRA parameters
80
+ ################################################################################
81
+ # LoRA attention dimension
82
+ lora_r = 16
83
+ # Alpha parameter for LoRA scaling
84
+ lora_alpha = 16
85
+ # Dropout probability for LoRA layers
86
+ lora_dropout = 0.05
87
+ # Modules
88
+ target_modules= ['k_proj', 'q_proj', 'v_proj', 'o_proj', "gate_proj", "down_proj", "up_proj"]
89
+ ```
90
+
91
+ **SFTTrainer arguments**
92
+ ```py
93
+ evaluation_strategy="steps",
94
+ do_eval=True,
95
+ optim="adamw_torch",
96
+ per_device_train_batch_size=8,
97
+ gradient_accumulation_steps=4,
98
+ per_device_eval_batch_size=8,
99
+ log_level="debug",
100
+ save_strategy="epoch",
101
+ logging_steps=100,
102
+ learning_rate=1e-4,
103
+ fp16 = not torch.cuda.is_bf16_supported(),
104
+ bf16 = torch.cuda.is_bf16_supported(),
105
+ eval_steps=100,
106
+ num_train_epochs=3,
107
+ warmup_ratio=0.1,
108
+ lr_scheduler_type="linear",
109
+ report_to="wandb",
110
+ ```
111
+
112
+ ### Framework versions
113
+ - PEFT 0.4.0
114
+
115
+ ## Evaluation
116
+ Evaluating on a test dataset of 500 samples:
117
+
118
+ ```text
119
+ Rouge 1 Mean: 56.65322508234244
120
+ Rouge 2 Mean: 37.547274096577084
121
+ Rouge L Mean: 51.08407579855678
122
+ Rouge Lsum Mean: 56.256016384803075
123
+
124
+ ```
125
+
126
+ ### Example of usage
127
+
128
+ ```py
129
+ import torch
130
+ from transformers import AutoModelForCausalLM, AutoTokenizer
131
+
132
+ model_id = "edumunozsala/phi3-mini-python-code-20k"
133
+
134
+ tokenizer = AutoTokenizer.from_pretrained(hf_model_repo,trust_remote_code=True)
135
+ model = AutoModelForCausalLM.from_pretrained(hf_model_repo, trust_remote_code=True, torch_dtype="auto", device_map="cuda")
136
+
137
+
138
+ instruction="Create an algorithm in Python to sort an array of numbers."
139
+ input="[9, 3, 5, 1, 6]"
140
+
141
+ prompt = f"""### Instruction:
142
+ Below is an instruction that describes a task. Write a response that appropriately completes the request.
143
+
144
+ ### Instruction:
145
+ {instruction}
146
+
147
+ ### Input:
148
+ {input}
149
+
150
+ ### Output:
151
+ """
152
+
153
+ pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
154
+
155
+ # Function to execute inference on a prompt
156
+ def test_inference(prompt):
157
+ prompt = pipe.tokenizer.apply_chat_template([{"role": "user", "content": prompt}], tokenize=False, add_generation_prompt=True)
158
+ outputs = pipe(prompt, max_new_tokens=256, do_sample=True, num_beams=1, temperature=0.3, top_k=50, top_p=0.95,
159
+ max_time= 180) #, eos_token_id=eos_token)
160
+ return outputs[0]['generated_text'][len(prompt):].strip()
161
+
162
+
163
+ test_inference(prompt)
164
+
165
+ ```
166
+
167
+ ### Citation
168
+
169
+ ```
170
+ @misc {edumunozsala_2023,
171
+ author = { {Eduardo Muñoz} },
172
+ title = { phi3-mini-python-code-20k },
173
+ year = 2024,
174
+ url = { https://huggingface.co/edumunozsala/phi3-mini-python-code-20k },
175
+ publisher = { Hugging Face }
176
+ }
177
+ ```
178
+