Skip to content

Commit 6645885

Browse files
Add Phi_4_14B_GRPO notebook
1 parent d50891d commit 6645885

File tree

1 file changed

+123
-0
lines changed

1 file changed

+123
-0
lines changed
Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"id": "cc1b7810",
6+
"metadata": {
7+
"id": "cc1b7810"
8+
},
9+
"source": [
10+
"# Phi-4 (14B) Conversational with GRPO"
11+
]
12+
},
13+
{
14+
"cell_type": "markdown",
15+
"id": "9c882a2d",
16+
"metadata": {
17+
"id": "9c882a2d"
18+
},
19+
"source": [
20+
"**Description:**\n",
21+
"\n",
22+
"This notebook demonstrates inference using the Phi-4 14B parameter model with GRPO optimization strategy."
23+
]
24+
},
25+
{
26+
"cell_type": "markdown",
27+
"source": [
28+
"[![Open in Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/DhivyaBharathy-web/PraisonAI/blob/main/examples/cookbooks/Phi_4_14B_GRPO.ipynb)\n"
29+
],
30+
"metadata": {
31+
"id": "Z7azojscP0Ax"
32+
},
33+
"id": "Z7azojscP0Ax"
34+
},
35+
{
36+
"cell_type": "markdown",
37+
"id": "e8616784",
38+
"metadata": {
39+
"id": "e8616784"
40+
},
41+
"source": [
42+
"**Dependencies**\n",
43+
"\n",
44+
"```python\n",
45+
"!pip install transformers accelerate\n",
46+
"!pip install torch\n",
47+
"```"
48+
]
49+
},
50+
{
51+
"cell_type": "markdown",
52+
"id": "09866448",
53+
"metadata": {
54+
"id": "09866448"
55+
},
56+
"source": [
57+
"**Tools Used**\n",
58+
"\n",
59+
"- HuggingFace Transformers\n",
60+
"- GRPO Optimization\n",
61+
"- PyTorch"
62+
]
63+
},
64+
{
65+
"cell_type": "markdown",
66+
"id": "403b0c37",
67+
"metadata": {
68+
"id": "403b0c37"
69+
},
70+
"source": [
71+
"**YAML Prompt**\n",
72+
"\n",
73+
"```yaml\n",
74+
"system: Act as a professional consultant.\n",
75+
"user: How can AI help in healthcare?\n",
76+
"```"
77+
]
78+
},
79+
{
80+
"cell_type": "code",
81+
"execution_count": null,
82+
"id": "e1785bcd",
83+
"metadata": {
84+
"id": "e1785bcd"
85+
},
86+
"outputs": [],
87+
"source": [
88+
"from transformers import AutoTokenizer, AutoModelForCausalLM\n",
89+
"\n",
90+
"tokenizer = AutoTokenizer.from_pretrained(\"microsoft/phi-4-14b\")\n",
91+
"model = AutoModelForCausalLM.from_pretrained(\"microsoft/phi-4-14b\")\n",
92+
"\n",
93+
"prompt = \"How can AI help in healthcare?\"\n",
94+
"inputs = tokenizer(prompt, return_tensors=\"pt\")\n",
95+
"outputs = model.generate(**inputs, max_new_tokens=60)\n",
96+
"print(tokenizer.decode(outputs[0], skip_special_tokens=True))"
97+
]
98+
},
99+
{
100+
"cell_type": "markdown",
101+
"id": "074e4e6e",
102+
"metadata": {
103+
"id": "074e4e6e"
104+
},
105+
"source": [
106+
"**Output**\n",
107+
"\n",
108+
"The model generates thoughtful insights on AI applications in healthcare.\n",
109+
"\n",
110+
"How can AI help in healthcare?\n",
111+
"\n",
112+
"AI can assist in healthcare by improving diagnostics, predicting patient outcomes, personalizing treatments, and enhancing administrative workflows. It enables faster data analysis and decision-making, leading to better patient care.\n"
113+
]
114+
}
115+
],
116+
"metadata": {
117+
"colab": {
118+
"provenance": []
119+
}
120+
},
121+
"nbformat": 4,
122+
"nbformat_minor": 5
123+
}

0 commit comments

Comments
 (0)