Skip to content

Commit ebd7d9e

Browse files
committed
fix
1 parent 57eeeec commit ebd7d9e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+8173
-32
lines changed

README.md

+12
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,15 @@ Follow these steps to get started using these resource :
3939
- [Using Guidance-ai and Phi](./md/01.Introduction/01/01.Guidance.md)
4040
- [GitHub Marketplace Models](https://github.com/marketplace/models)
4141
- [Azure AI Model Catalog](https://ai.azure.com)
42+
4243
- Inference Phi in different environment
4344
- [Hugging face](./md/01.Introduction/02/01.HF.md)
4445
- [GitHub Models](./md/01.Introduction/02/02.GitHubModel.md)
4546
- [Azure AI Foundry Model Catalog](./md/01.Introduction/02/03.AzureAIFoundry.md)
4647
- [Ollama](./md/01.Introduction/02/04.Ollama.md)
4748
- [AI Toolkit VSCode (AITK)](./md/01.Introduction/02/05.AITK.md)
4849
- [NVIDIA NIM](./md/01.Introduction/02/06.NVIDIA.md)
50+
4951
- Inference Phi Family
5052
- [Inference Phi in iOS](./md/01.Introduction/03/iOS_Inference.md)
5153
- [Inference Phi in Android](./md/01.Introduction/03/Android_Inference.md)
@@ -62,10 +64,12 @@ Follow these steps to get started using these resource :
6264
- [Quantizing Phi-3.5 / 4 using Generative AI extensions for onnxruntime](./md/01.Introduction/04/UsingORTGenAIQuantifyingPhi.md)
6365
- [Quantizing Phi-3.5 / 4 using Intel OpenVINO](./md/01.Introduction/04/UsingIntelOpenVINOQuantifyingPhi.md)
6466
- [Quantizing Phi-3.5 / 4 using Apple MLX Framework](./md/01.Introduction/04/UsingAppleMLXQuantifyingPhi.md)
67+
6568
- Evaluation Phi
6669
- [Response AI](./md/01.Introduction/05/ResponsibleAI.md)
6770
- [Azure AI Foundry for Evaluation](./md/01.Introduction/05/AIFoundry.md)
6871
- [Using Promptflow for Evaluation](./md/01.Introduction/05/Promptflow.md)
72+
6973
- Phi application development samples
7074
- Text & Chat Applications
7175
- Phi-4 Samples 🆕
@@ -85,15 +89,18 @@ Follow these steps to get started using these resource :
8589
- [Phi-3.5-Instruct WebGPU RAG Chatbot](./md/02.Application/01.TextAndChat/Phi3/WebGPUWithPhi35Readme.md)
8690
- [Using Windows GPU to create Prompt flow solution with Phi-3.5-Instruct ONNX](./md/02.Application/01.TextAndChat/Phi3/UsingPromptFlowWithONNX.md)
8791
- [Using Microsoft Phi-3.5 tflite to create Android app](./md/02.Application/01.TextAndChat/Phi3/UsingPhi35TFLiteCreateAndroidApp.md)
92+
8893
- Azure AI Inference SDK Code Based Samples
8994
- Phi-4 Samples 🆕
9095
- [📓] [Generate project code using Phi-4-multimodal](./md/02.Application/02.Code/Phi4/GenProjectCode/README.md)
9196
- Phi-3 / 3.5 Samples
9297
- [Build your own Visual Studio Code GitHub Copilot Chat with Microsoft Phi-3 Family](./md/02.Application/02.Code/Phi3/VSCodeExt/README.md)
9398
- [Create your own Visual Studio Code Chat Copilot Agent with Phi-3.5 by GitHub Models](/md/02.Application/02.Code/Phi3/CreateVSCodeChatAgentWithGitHubModels.md)
99+
94100
- Advanced Reasoning Samples
95101
- Phi-4 Samples 🆕
96102
- [📓] [Phi-4-mini Reasoning Samples](./md/02.Application/03.AdvancedReasoning/Phi4/AdvancedResoningPhi4mini/README.md)
103+
97104
- Vision Samples
98105
- Phi-4 Samples 🆕
99106
- [📓] [Use Phi-4-multimodal to read images and generate code](./md/02.Application/04.Vision/Phi4/CreateFrontend/README.md)
@@ -106,11 +113,13 @@ Follow these steps to get started using these resource :
106113
- [Phi-3 Vision Nvidia NIM](./md/02.Application/04.Vision/Phi3/E2E_Nvidia_NIM_Vision.md)
107114
- [Phi-3 Vision OpenVino](./md/02.Application/04.Vision/Phi3/E2E_OpenVino_Phi3Vision.md)
108115
- [📓][Phi-3.5 Vision multi-frame or multi-image sample](./md/02.Application/04.Vision/Phi3/phi3-vision-demo.ipynb)
116+
109117
- Audio Samples
110118
- Phi-4 Samples 🆕
111119
- [📓] [Extracting audio transcripts using Phi-4-multimodal](./md/02.Application/05.Audio/Phi4/Transciption/README.md)
112120
- [📓] [Phi-4-multimodal Audio Sample](./md/02.Application/05.Audio/Phi4/Siri/demo.ipynb)
113121
- [📓] [Phi-4-multimodal Speech Translation Sample](./md/02.Application/05.Audio/Phi4/Translate/demo.ipynb)
122+
114123
- MOE Samples
115124
- Phi-3 / 3.5 Samples
116125
- [📓] [Phi-3.5 Mixture of Experts Models (MoEs) Social Media Sample](./md/02.Application/06.MoE/Phi3/phi3_moe_demo.ipynb)
@@ -121,6 +130,7 @@ Follow these steps to get started using these resource :
121130
- Multimodal Mixing Samples
122131
- Phi-4 Samples 🆕
123132
- [📓] [Using Phi-4-multimodal as a Technology journalist](./md/02.Application/08.Multimodel/Phi4/TechJournalist/phi_4_mm_audio_text_publish_news.ipynb)
133+
124134
- Fine-tuning Phi Samples
125135
- [Fine-tuning Scenarios](./md/03.FineTuning/FineTuning_Scenarios.md)
126136
- [Fine-tuning vs RAG](./md/03.FineTuning/FineTuning_vs_RAG.md)
@@ -138,9 +148,11 @@ Follow these steps to get started using these resource :
138148
- [Fine-tuning Phi-3-vision (official support)](./md/03.FineTuning/FineTuning_Vision.md)
139149
- [Fine-Tuning Phi-3 with Kaito AKS , Azure Containers(official Support)](./md/03.FineTuning/FineTuning_Kaito.md)
140150
- [Fine-Tuning Phi-3 and 3.5 Vision](https://github.com/2U1/Phi3-Vision-Finetune)
151+
141152
- Hands on Lab
142153
- [Exploring cutting-edge models: LLMs, SLMs, local development and more](https://github.com/microsoft/aitour-exploring-cutting-edge-models)
143154
- [Unlocking NLP Potential: Fine-Tuning with Microsoft Olive](https://github.com/azure/Ignite_FineTuning_workshop)
155+
144156
- Academic Research Papers and Publications
145157
- [Textbooks Are All You Need II: phi-1.5 technical report](https://arxiv.org/abs/2309.05463)
146158
- [Phi-3 Technical Report: A Highly Capable Language Model Locally on Your Phone](https://arxiv.org/abs/2404.14219)
+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
# This code is for fine-tuning Phi-3 Models.
2+
# Note thi requires 7.4 GB of GPU RAM for the process.
3+
# Model available at https://huggingface.co/collections/microsoft/phi-3-6626e15e9585a200d2d761e3
4+
# Model Names
5+
# microsoft/Phi-3-mini-4k-instruct
6+
# microsoft/Phi-3-mini-128k-instruct
7+
# microsoft/Phi-3-small-8k-instruct
8+
# microsoft/Phi-3-small-128k-instruct
9+
# microsoft/Phi-3-medium-4k-instruct
10+
# microsoft/Phi-3-medium-128k-instruct
11+
# microsoft/Phi-3-vision-128k-instruct
12+
# microsoft/Phi-3-mini-4k-instruct-onnx
13+
# microsoft/Phi-3-mini-4k-instruct-onnx-web
14+
# microsoft/Phi-3-mini-128k-instruct-onnx
15+
# microsoft/Phi-3-small-8k-instruct-onnx-cuda
16+
# microsoft/Phi-3-small-128k-instruct-onnx-cuda
17+
# microsoft/Phi-3-medium-4k-instruct-onnx-cpu
18+
# microsoft/Phi-3-medium-4k-instruct-onnx-cuda
19+
# microsoft/Phi-3-medium-4k-instruct-onnx-directml
20+
# microsoft/Phi-3-medium-128k-instruct-onnx-cpu
21+
# microsoft/Phi-3-medium-128k-instruct-onnx-cuda
22+
# microsoft/Phi-3-medium-128k-instruct-onnx-directml
23+
# microsoft/Phi-3-mini-4k-instruct-gguf
24+
25+
# Load the pre-trained model and tokenizer
26+
model = AutoModelForCausalLM.from_pretrained('Model_Name', torch_dtype=torch.float16)
27+
tokenizer = AutoTokenizer.from_pretrained('Mode_Name')
28+
29+
# Load the dataset for fine-tuning
30+
dataset = load_dataset(DATASET_NAME, split="train")
31+
32+
# Define the formatting function for the prompts
33+
def formatting_prompts_func(examples):
34+
convos = examples["conversations"]
35+
texts = []
36+
mapper = {"system": "system\n", "human": "\nuser\n", "gpt": "\nassistant\n"}
37+
end_mapper = {"system": "", "human": "", "gpt": ""}
38+
for convo in convos:
39+
text = "".join(f"{mapper[(turn := x['from'])]} {x['value']}\n{end_mapper[turn]}" for x in convo)
40+
texts.append(f"{text}{tokenizer.eos_token}")
41+
return {"text": texts}
42+
43+
# Apply the formatting function to the dataset
44+
dataset = dataset.map(formatting_prompts_func, batched=True)
45+
46+
# Define the training arguments
47+
args = TrainingArguments(
48+
evaluation_strategy="steps",
49+
per_device_train_batch_size=7,
50+
gradient_accumulation_steps=4,
51+
gradient_checkpointing=True,
52+
learning_rate=1e-4,
53+
fp16=True,
54+
max_steps=-1,
55+
num_train_epochs=3,
56+
save_strategy="epoch",
57+
logging_steps=10,
58+
output_dir=NEW_MODEL_NAME,
59+
optim="paged_adamw_32bit",
60+
lr_scheduler_type="linear"
61+
)
62+
63+
# Create the trainer
64+
trainer = SFTTrainer(
65+
model=model,
66+
args=args,
67+
train_dataset=dataset,
68+
dataset_text_field="text",
69+
max_seq_length=128,
70+
formatting_func=formatting_prompts_func
71+
)
72+
73+
# Start the training process
74+
trainer.train()

code/04.Finetuning/Phi-3-finetune-lora-python.ipynb

+1
Large diffs are not rendered by default.

code/04.Finetuning/Phi-3-finetune-qlora-python.ipynb

+1
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)