chriscelaya commited on
Commit
8de36da
·
verified ·
1 Parent(s): c475491

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +152 -6
README.md CHANGED
@@ -10,13 +10,159 @@ license: apache-2.0
10
  language:
11
  - en
12
  ---
 
13
 
14
- # Uploaded model
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- - **Developed by:** chriscelaya
17
- - **License:** apache-2.0
18
- - **Finetuned from model :** unsloth/Qwen2.5-7B-bnb-4bit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- This qwen2 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)
 
10
  language:
11
  - en
12
  ---
13
+ Here is the README for your Hugging Face project:
14
 
15
+ ---
16
+
17
+ # Efficient Fine-Tuning of Large Language Models - Minecraft AI Assistant Tutorial
18
+
19
+ This repository demonstrates how to fine-tune the **Qwen 7B** model to create "Andy," an AI assistant for Minecraft. Using the **Unsloth framework**, this tutorial showcases efficient fine-tuning with 4-bit quantization and LoRA for scalable training on limited hardware.
20
+
21
+ ## 🚀 Resources
22
+ - **Source Code**: [GitHub Repository](#) #todo: add mindcraft repo
23
+ - **Colab Notebook**: [Run the Tutorial](#) #todo: add colab notebook url
24
+
25
+ ## Overview
26
+
27
+ This guide provides step-by-step instructions to:
28
+ 1. Install and set up the **Unsloth framework**.
29
+ 2. Initialize the **Qwen 7B** model with **4-bit quantization**.
30
+ 3. Implement **LoRA Adapters** for memory-efficient fine-tuning.
31
+ 4. Prepare the **Andy-3.5 dataset** with Minecraft-specific knowledge.
32
+ 5. Configure and execute training in a resource-efficient manner.
33
+ 6. Evaluate and deploy the fine-tuned AI assistant.
34
+
35
+ ---
36
+
37
+ ### Key Features
38
+ - **Memory-Efficient Training**: Fine-tune large models on GPUs as low as T4 (Google Colab).
39
+ - **LoRA Integration**: Modify only key model layers for efficient domain-specific adaptation.
40
+ - **Minecraft-Optimized Dataset**: Format data using **ChatML templates** for seamless integration.
41
+ - **Accessible Hardware**: Utilize cost-effective setups with GPU quantization techniques.
42
+
43
+ ---
44
+
45
+ ## Prerequisites
46
+ - **Python Knowledge**: Familiarity with basic programming concepts.
47
+ - **GPU Access**: T4 (Colab Free Tier) is sufficient; higher-tier GPUs like V100/A100 recommended.
48
+ - **Optional**: [Hugging Face Account](https://huggingface.co/) for model sharing.
49
+
50
+ ---
51
+
52
+ ## Setup
53
+
54
+ Install the required packages:
55
+ ```bash
56
+ !pip install "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
57
+ !pip install --no-deps xformers trl peft accelerate bitsandbytes
58
+ ```
59
+
60
+ ---
61
+
62
+ ## Model Initialization
63
+
64
+ Load the **Qwen 7B** model with 4-bit quantization for reduced resource usage:
65
+
66
+ ```python
67
+ from unsloth import FastLanguageModel
68
+ import torch
69
+
70
+ model, tokenizer = FastLanguageModel.from_pretrained(
71
+ model_name="unsloth/Qwen2.5-7B-bnb-4bit",
72
+ max_seq_length=2048,
73
+ dtype=torch.bfloat16, # Or torch.float16 for older GPUs
74
+ load_in_4bit=True,
75
+ trust_remote_code=True,
76
+ )
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Adding LoRA Adapters
82
 
83
+ Add LoRA to fine-tune specific layers efficiently:
84
+ ```python
85
+ model = FastLanguageModel.get_peft_model(
86
+ model,
87
+ r=16,
88
+ target_modules=["q_proj", "k_proj", "v_proj", "o_proj", "embed_tokens", "lm_head"],
89
+ lora_alpha=16,
90
+ lora_dropout=0,
91
+ use_gradient_checkpointing="unsloth",
92
+ )
93
+ ```
94
+
95
+ ---
96
+
97
+ ## Dataset Preparation
98
+
99
+ Prepare the Minecraft dataset (**Andy-3.5**):
100
+ ```python
101
+ from datasets import load_dataset
102
+ from unsloth.chat_templates import get_chat_template
103
+
104
+ dataset = load_dataset("Sweaterdog/Andy-3.5", split="train")
105
+ tokenizer = get_chat_template(tokenizer, chat_template="chatml")
106
+ ```
107
+
108
+ ---
109
+
110
+ ## Training Configuration
111
+
112
+ Set up the training parameters:
113
+ ```python
114
+ from trl import SFTTrainer
115
+ from transformers import TrainingArguments
116
+
117
+ trainer = SFTTrainer(
118
+ model=model,
119
+ tokenizer=tokenizer,
120
+ train_dataset=dataset,
121
+ dataset_text_field="text",
122
+ args=TrainingArguments(
123
+ per_device_train_batch_size=16,
124
+ max_steps=1000,
125
+ learning_rate=2e-5,
126
+ gradient_checkpointing=True,
127
+ output_dir="outputs",
128
+ fp16=True,
129
+ ),
130
+ )
131
+ ```
132
+
133
+ Clear unused memory before training:
134
+ ```python
135
+ import torch
136
+ torch.cuda.empty_cache()
137
+ ```
138
+
139
+ ---
140
+
141
+ ## Train the Model
142
+
143
+ Initiate training:
144
+ ```python
145
+ trainer_stats = trainer.train()
146
+ ```
147
+
148
+ ---
149
+
150
+ ## Save and Share
151
+
152
+ Save your fine-tuned model locally or upload to Hugging Face:
153
+ ```python
154
+ model.save_pretrained("andy_minecraft_assistant")
155
+ ```
156
+
157
+ ---
158
+
159
+ ## Optimization Tips
160
+ - Expand the dataset for broader Minecraft scenarios.
161
+ - Adjust training steps for better accuracy.
162
+ - Fine-tune inference parameters for more natural responses.
163
+
164
+ ---
165
 
166
+ For more details on **Unsloth** or to contribute, visit [Unsloth GitHub](https://github.com/unslothai/unsloth).
167
 
168
+ Happy fine-tuning! 🎮