Omarrran commited on
Commit
1bf92d5
·
verified ·
1 Parent(s): b359c26

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +113 -1
README.md CHANGED
@@ -17,6 +17,118 @@ language:
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** unsloth/phi-4-unsloth-bnb-4bit
19
 
20
- This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
17
  - **License:** apache-2.0
18
  - **Finetuned from model :** unsloth/phi-4-unsloth-bnb-4bit
19
 
20
+ # Fine-tuned Phi-4 Model Documentation
21
+
22
+ ## 📌 Introduction
23
+ This documentation provides an in-depth overview of the **fine-tuned Phi-4 conversational AI model**, detailing its **training methodology, parameters, dataset, model deployment, and usage instructions**.
24
+
25
+ ## 🔹 Model Overview
26
+ **Phi-4** is a transformer-based language model optimized for **natural language understanding and text generation**. We have fine-tuned it using **LoRA (Low-Rank Adaptation)** with the **Unsloth framework**, making it lightweight and efficient while preserving the base model's capabilities.
27
+
28
+ ## 🔹 Training Details
29
+ ### **🛠 Fine-tuning Methodology**
30
+ We employed **LoRA (Low-Rank Adaptation)** for fine-tuning, which significantly reduces the number of trainable parameters while retaining the model’s expressive power.
31
+
32
+ ### **📑 Dataset Used**
33
+ - **Dataset Name**: `mlabonne/FineTome-100k`
34
+ - **Dataset Size**: 100,000 examples
35
+ - **Data Format**: Conversational AI dataset with structured prompts and responses.
36
+ - **Preprocessing**: The dataset was standardized using `unsloth.chat_templates.standardize_sharegpt()`
37
+
38
+ ### **🔢 Training Parameters**
39
+ | Parameter | Value |
40
+ |----------------------|-------|
41
+ | LoRA Rank (`r`) | 16 |
42
+ | LoRA Alpha | 16 |
43
+ | LoRA Dropout | 0 |
44
+ | Target Modules | `q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj` |
45
+ | Max Sequence Length | 2048 |
46
+ | Load in 4-bit | True |
47
+ | Gradient Checkpointing | `unsloth` |
48
+ | Fine-tuning Duration | **10 epochs** |
49
+ | Optimizer Used | AdamW |
50
+ | Learning Rate | 2e-5 |
51
+
52
+ ## 🔹 How to Load the Model
53
+ To load the fine-tuned model, use the **Unsloth framework**:
54
+
55
+ ```python
56
+ from unsloth import FastLanguageModel
57
+ from unsloth.chat_templates import get_chat_template
58
+ from peft import PeftModel
59
+
60
+ model_name = "unsloth/Phi-4"
61
+ max_seq_length = 2048
62
+ load_in_4bit = True
63
+
64
+ # Load model and tokenizer
65
+ model, tokenizer = FastLanguageModel.from_pretrained(
66
+ model_name=model_name,
67
+ max_seq_length=max_seq_length,
68
+ load_in_4bit=load_in_4bit
69
+ )
70
+
71
+ # Apply LoRA adapter
72
+ model = FastLanguageModel.get_peft_model(
73
+ model,
74
+ r=16,
75
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj",
76
+ "gate_proj", "up_proj", "down_proj"],
77
+ lora_alpha=16,
78
+ lora_dropout=0,
79
+ bias="none",
80
+ use_gradient_checkpointing="unsloth"
81
+ )
82
+ ```
83
+
84
+ ## 🔹 Deploying the Model
85
+ ### **🚀 Using Google Colab**
86
+ 1. Install dependencies:
87
+ ```bash
88
+ pip install gradio transformers torch unsloth peft
89
+ ```
90
+ 2. Load the model using the script above.
91
+ 3. Run inference using the chatbot interface.
92
+
93
+ ### **🚀 Deploy on Hugging Face Spaces**
94
+ 1. Save the script as `app.py`.
95
+ 2. Create a `requirements.txt` file with:
96
+ ```
97
+ gradio
98
+ transformers
99
+ torch
100
+ unsloth
101
+ peft
102
+ ```
103
+ 3. Upload the files to a new **Hugging Face Space**.
104
+ 4. Select **Python environment** and click **Deploy**.
105
+
106
+ ## 🔹 Using the Model
107
+ ### **🗨 Chatbot Interface (Gradio UI)**
108
+ To interact with the fine-tuned model using **Gradio**, use:
109
+
110
+ ```python
111
+ import gradio as gr
112
+
113
+ def chat_with_model(user_input):
114
+ inputs = tokenizer(user_input, return_tensors="pt")
115
+ output = model.generate(**inputs, max_length=200)
116
+ response = tokenizer.decode(output[0], skip_special_tokens=True)
117
+ return response
118
+
119
+ demo = gr.Interface(
120
+ fn=chat_with_model,
121
+ inputs=gr.Textbox(label="Your Message"),
122
+ outputs=gr.Textbox(label="Chatbot's Response"),
123
+ title="LoRA-Enhanced Phi-4 Chatbot"
124
+ )
125
+
126
+ demo.launch()
127
+ ```
128
+
129
+ ## 📌 Conclusion
130
+ This **fine-tuned Phi-4 model** delivers **optimized conversational AI capabilities** using **LoRA fine-tuning and Unsloth’s 4-bit quantization**. The model is **lightweight, memory-efficient**, and suitable for chatbot applications in both **research and production environments**.
131
+
132
+
133
 
134
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)