chriscelaya commited on
Commit
e324ea8
·
verified ·
1 Parent(s): 00a1c43

Update README.md

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