Teach LLM Something New πŸ’‘ LoRA Fine Tuning on Custom Data

Python Simplified β€’ July 31, 2025
Video Thumbnail
Python Simplified Logo

Python Simplified

@pythonsimplified

About

Hi everyone! My name is Mariya and I'm a software developer from Sofia, Bulgaria. I film programming tutorials about Computer Science Concepts, GUI Applications, Machine Learning and Artificial Intelligence, Automation and Web Scraping, Data Science and even Math! πŸ€“ I'm here to help you with your programming journey (in particular - your Python programming journey πŸ˜‰) and show you how many beautiful and powerful things we can do with code! πŸ’ͺπŸ’ͺπŸ’ͺ

Video Description

What if you could teach an AI model something it doesn't know? 🀯 In this step-by-step hands-on coding tutorial, we will take a powerful pre-trained LLM and we will train it once again - convincing it that I am a wise wizard from Middle-earth! πŸ§™β€β™€οΈπŸ‘©β€πŸ’» Essentially, we will trick the model into believing whatever we want and not what the original engineers intended! πŸ€ͺ We will then save it back to our computer, creating a unique custom version that's truly one-of-a-kind! ⭐ This video is brought to you by HubSpot! Check out their FREE Advanced ChatGPT Prompt Engineering Playbook: https://clickhubspot.com/3067db Big thanks to HubSpot for sponsoring this video and providing the Playbook for free! πŸ™Œ πŸ“š What you'll learn: - How to work with the Hugging Face Transformers library - The basics of loading and prompting LLMs with Python - How to prepare your own dataset (prompt/completion JSON format) - Dataset Tokenization - Using LoRA (Low-Rank Adaptation) for efficient training - Training with PEFT (Parameter-Efficient Fine-Tuning) - Saving and testing your custom model πŸ› οΈ Tools used: - Hugging Face Transformers - Jupyter Lab - Qwen/Qwen2.5-3B-Instruct model - PEFT with LoRA By the end of this tutorial, your model will believe whatever you teach it - whether it’s true or not! 😎 πŸ”Ž Resources & Helpful Tutorials: -------------------------------------------- ⭐ Full code on GitHub: https://github.com/MariyaSha/fine_tuning.git ⭐ Install WSL and Conda: https://youtu.be/luM5kwH6tjQ ⭐ What is CUDA? For Beginners: https://youtu.be/r9IqwpMR9TE ⭐ What is Samples? Features? Labels? Intro to Neural Networks: https://youtu.be/i1AqHG4k8mE ⭐ Best Training Arguments with Hyperparameter Tuning: https://youtu.be/-IvNzmrcyUM πŸ’» Environment Setup: -------------------------------------------- conda create -n llm python=3.12 conda activate llm pip install transformers datasets accelerate torch torchvision peft jupyter pillow jupyter lab βš™οΈ LoRA: ----------------------------------------------------------------------------------------------- from peft import LoraConfig, get_peft_model, TaskType from transformers import AutoModelForCausalLM Import torch model = AutoModelForCausalLM.from_pretrained( "Qwen/Qwen2.5-3B-Instruct", device_map="cuda", torch_dtype=torch.float16 ) lora_config = LoraConfig( task_type=TaskType.CAUSAL_LM, target_modules=["q_proj", "k_proj", "v_proj"] ) model = get_peft_model(model, lora_config) ----------------------------------------------------------------------------------------------- ⏰ Timestamps ⏰ 01:07 - Environment Setup 01:50 - Load and Talk to LLM with Hugging Face Transformers 03:33 - Data Preparation 07:32 - Tokenization 14:33 - LoRA 16:47 - Training / Fine Tuning 19:17 - Important Notes Before You Start Training 20:54 - Training Results 21:15 - Save Fine Tuned Model 22:06 - Test Fine Tuned Model / Inference 23:10 - Thanks for Watching! #python #pythonprogramming #pythontutorial #coding #programming #LLM #AI #MachineLearning #FineTuning #HuggingFace #Transformers #LoRA #tokenization #datascience #artificialintelligence #ml #jupyternotebook

You May Also Like

Boost Your LLM Projects

AI-recommended products based on this video

Loading...
Seasonic Focus V4 GX-1000 (ATX3) - 1000W - 80+ Gold - ATX 3.0 & PCIe 5.1 Ready -Full-Modular -ATX Form Factor -Premium Japanese Capacitor -10 Year Warranty -Nvidia RTX 30/40 Super & AMD GPU Compatible

Seasonic Focus V4 GX-1000 (ATX3) - 1000W - 80+ Gold - ATX 3.0 & PCIe 5.1 Ready -Full-Modular -ATX Form Factor -Premium Japanese Capacitor -10 Year Warranty -Nvidia RTX 30/40 Super & AMD GPU Compatible

(22)
$423.35
FREE delivery Oct 8 - 10
Loading...
ASUS ROG Strix G16 Gaming Laptop, GeForce RTX 5070 Ti 12GB GDDR7, AMD Ryzen 9 8940HX, 64GB DDR5, 2TB SSD, Backlit Keyboard, Wi-Fi 6E, 16" WUXGA 165Hz Display, Win 11, Gray, 1TB Docking Station Set

ASUS ROG Strix G16 Gaming Laptop, GeForce RTX 5070 Ti 12GB GDDR7, AMD Ryzen 9 8940HX, 64GB DDR5, 2TB SSD, Backlit Keyboard, Wi-Fi 6E, 16" WUXGA 165Hz Display, Win 11, Gray, 1TB Docking Station Set

(10)
$4,269.00
FREE delivery Feb 24 - Mar 5
Loading...
Lenovo Legion Pro 5 16" WQXGA 165Hz Gaming Laptop, AMD Ryzen 9 9955HX, GeForce RTX 5070, 32GB DDR5, 3TB Storage (2TB SSD+1TB Docking Station Set), 24-Zone RGB Backlit Keyboard, WiFi 7, Win 11, Black

Lenovo Legion Pro 5 16" WQXGA 165Hz Gaming Laptop, AMD Ryzen 9 9955HX, GeForce RTX 5070, 32GB DDR5, 3TB Storage (2TB SSD+1TB Docking Station Set), 24-Zone RGB Backlit Keyboard, WiFi 7, Win 11, Black

(2)
$3,199.00
FREE delivery Feb 24 - Mar 5
Loading...
GEEKOM A7 Max Mini PC (Flagship Level Performance), AMD Ryzen 9 7940HS (Up to 5.2GHz),Mini Computer 16GB DDR5 RAM and 1TB PCIe 4.0 SSD, Windows 11 Pro, Quad 8K Display, USB4, Dual 2.5G LAN, Wi-Fi 6E

GEEKOM A7 Max Mini PC (Flagship Level Performance), AMD Ryzen 9 7940HS (Up to 5.2GHz),Mini Computer 16GB DDR5 RAM and 1TB PCIe 4.0 SSD, Windows 11 Pro, Quad 8K Display, USB4, Dual 2.5G LAN, Wi-Fi 6E

(115)
$1,199.00
FREE delivery Sat, Jan 3
Loading...
GEEKOM A8 AI Mini PC (3-Year Quality Support) with AMD Ryzen 9 8945HS Mini Computers, 32GB DDR5 RAM&2TB M.2 2280 NVMe Gen4*4 SSD, Windows 11 Pro Mini Desktop, WiFi 6E/BT5.2/USB4/8K/Quad Display

GEEKOM A8 AI Mini PC (3-Year Quality Support) with AMD Ryzen 9 8945HS Mini Computers, 32GB DDR5 RAM&2TB M.2 2280 NVMe Gen4*4 SSD, Windows 11 Pro Mini Desktop, WiFi 6E/BT5.2/USB4/8K/Quad Display

(215)
$1,159.40
FREE delivery Sun, Aug 10
Loading...
Samsung 990 EVO Plus - 4TB PCIe Gen4. X4, Gen5. X2 NVMe 2.0 - M.2 Internal SSD, Speed Up to 7,250 MBs, Upgrade Storage for PC-Laptops, HMB Technology and Intelligent Turbowrite (MZ-V9S4T0B/AM)

Samsung 990 EVO Plus - 4TB PCIe Gen4. X4, Gen5. X2 NVMe 2.0 - M.2 Internal SSD, Speed Up to 7,250 MBs, Upgrade Storage for PC-Laptops, HMB Technology and Intelligent Turbowrite (MZ-V9S4T0B/AM)

(1,811)
$359.99$341.99
FREE delivery Tue, Jun 17
100+ bought in past month
Loading...
SAMSUNG 870 EVO SATA SSD 500GB 2.5” Internal Solid State Drive, Upgrade PC or Laptop Memory and Storage for IT Pros, Creators, Everyday Users, MZ-77E500B/AM [Canada Version]

SAMSUNG 870 EVO SATA SSD 500GB 2.5” Internal Solid State Drive, Upgrade PC or Laptop Memory and Storage for IT Pros, Creators, Everyday Users, MZ-77E500B/AM [Canada Version]

(41,678)
$74.97
FREE delivery Wed, Jun 18
400+ bought in past month
Loading...
SAMSUNG 870 EVO SATA III SSD 4TB 2.5” Internal Solid State Drive, Upgrade PC or Laptop Memory and Storage for IT Pros, Creators, Everyday Users, MZ-77E4T0B/AM [Canada Version]

SAMSUNG 870 EVO SATA III SSD 4TB 2.5” Internal Solid State Drive, Upgrade PC or Laptop Memory and Storage for IT Pros, Creators, Everyday Users, MZ-77E4T0B/AM [Canada Version]

(41,656)
$399.97
FREE delivery Tue, Jun 17
100+ bought in past month
Loading...
SAMSUNG EVO Select Micro SD-Memory-Card + Adapter, 128GB microSDXC 160MB/s Full HD & 4K UHD, UHS-I, U3, A2, V30, for Android Smartphones, Tablets, Nintendo-Switch (MB-ME128SA/AM) [Canada Version]

SAMSUNG EVO Select Micro SD-Memory-Card + Adapter, 128GB microSDXC 160MB/s Full HD & 4K UHD, UHS-I, U3, A2, V30, for Android Smartphones, Tablets, Nintendo-Switch (MB-ME128SA/AM) [Canada Version]

(12,472)
$19.99$18.59
FREE delivery Sun, Aug 10 on your first order
400+ bought in past month
Loading...
Anker USB C Charger Cable (6ft 100W, 2Pack), USB 2.0 Type C Fast Charging Cable for iPhone 15 / 15Pro / 15Plus / 15ProMax MacBook Pro 2020, iPad Pro 2020, iPad Air 4, Samsung Galaxy S23+/S23 Ultra ClimatePartner certified

Anker USB C Charger Cable (6ft 100W, 2Pack), USB 2.0 Type C Fast Charging Cable for iPhone 15 / 15Pro / 15Plus / 15ProMax MacBook Pro 2020, iPad Pro 2020, iPad Air 4, Samsung Galaxy S23+/S23 Ultra ClimatePartner certified

(44,904)
$17.99
FREE delivery Wed, Aug 20 on your first order
6K+ bought in past month
Loading...
Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

Anker USB C Cable, [2-Pack, 6 ft] Type C Charger Premium Nylon USB Cable, USB A to Type C Charging Cable Fast Charge for Samsung Galaxy S10 S10+ / Note 8, LG V20 and Other USB C Charger (Black)

(103,365)
$13.49
5K+ bought in past month
Loading...
Anker Nano USB C Wall Charger,45W Fast Charging Smart Display Charger,with 180Β°Foldable Plug,Smart Recognition,Built-in Care Mode,for iPhone17/16/15 (Non-Battery,One USB-C Port,No Cable Included) ClimatePartner certified

Anker Nano USB C Wall Charger,45W Fast Charging Smart Display Charger,with 180Β°Foldable Plug,Smart Recognition,Built-in Care Mode,for iPhone17/16/15 (Non-Battery,One USB-C Port,No Cable Included) ClimatePartner certified

(698)
$39.99
FREE delivery Wed, Mar 4
1K+ bought in past month
Loading...
Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

Logitech M185 Wireless Mouse, 2.4GHz with USB Mini Receiver, 12-Month Battery Life, 1000 DPI Optical Tracking, Ambidextrous, Compatible with PC, Mac, Laptop - Black

(48,912)
$15.99$12.79
FREE delivery Wed, Feb 18 on your first order
1K+ bought in past month
Loading...
Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black
Best Seller

Logitech G203 Wired Gaming Mouse, 8,000 DPI, Rainbow Optical Effect LIGHTSYNC RGB, 6 Programmable Buttons, On-Board Memory, Screen Mapping, PC/Mac Computer and Laptop Compatible - Black

(17,871)
$27.98$22.38
FREE delivery Tue, Oct 14 on your first order
500+ bought in past month
Loading...
Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

Logitech G305 Lightspeed Wireless Gaming Mouse, Hero 12K Sensor, 12,000 DPI, Lightweight, 6 Programmable Buttons, 250h Battery Life, On-Board Memory, PC/Mac - Black

(35,879)
$49.99$44.99
FREE delivery Mon, Jan 26
1K+ bought in past month
Loading...
Logitech G502 Hero High Performance Wired Gaming Mouse, Hero 25K Sensor, 25,600 DPI, RGB, Adjustable Weights, 11 Programmable Buttons, On-Board Memory, PC/Mac, Black

Logitech G502 Hero High Performance Wired Gaming Mouse, Hero 25K Sensor, 25,600 DPI, RGB, Adjustable Weights, 11 Programmable Buttons, On-Board Memory, PC/Mac, Black

(55,508)
$49.98$44.98
FREE delivery Thu, Jan 29
2K+ bought in past month
Loading...
LG UltraWide 34WP65C-B 34 Inch 21:9 Curved FreeSync 1ms 160 Hz WQHD(3440 x 1440) Gaming Monitor, Black

LG UltraWide 34WP65C-B 34 Inch 21:9 Curved FreeSync 1ms 160 Hz WQHD(3440 x 1440) Gaming Monitor, Black

(2,271)
419.98
PrimeFREE delivery Saturday, June 14
50+ bought in past month
Loading...
Lg gram 16-inch +View Portable Monitor with USB Type-C, DCI-P3 99% (Typ.), Auto Rotate, Two-Way Supported Folio Cover

Lg gram 16-inch +View Portable Monitor with USB Type-C, DCI-P3 99% (Typ.), Auto Rotate, Two-Way Supported Folio Cover

(36)
$328.99$263.19
FREE delivery Tue, Aug 12
Loading...
StanbyME LG 27-Inch Class Smart Portable Touch Screen Monitor 27ART10AKPL. Built-in 3 Hour Battery, Full Swivel Rotation, Rollable. LG Stanbyme, Standbyme, Stand by me.

StanbyME LG 27-Inch Class Smart Portable Touch Screen Monitor 27ART10AKPL. Built-in 3 Hour Battery, Full Swivel Rotation, Rollable. LG Stanbyme, Standbyme, Stand by me.

(75)
$1,097.98
FREE delivery Sun, Aug 10
50+ bought in past month
Loading...
LG 24U411A-B 23.8" FHD (1920x1080) IPS Display Computer Monitor, 120Hz Refresh Rate, sRGB 99% (Typ.), USB-C, Reader Mode & Flicker Safe, Dynamic Action Sync, Black Stabilizer, Slim Stand Base, Black
Best Seller

LG 24U411A-B 23.8" FHD (1920x1080) IPS Display Computer Monitor, 120Hz Refresh Rate, sRGB 99% (Typ.), USB-C, Reader Mode & Flicker Safe, Dynamic Action Sync, Black Stabilizer, Slim Stand Base, Black

(2,610)
$96.95
FREE delivery Tue, Oct 14
2K+ bought in past month
Loading...
Corsair Vengeance LPX 32GB (2 X 16GB) DDR4 3200 (PC4-25600) C16 1.35V Desktop Memory - Black
Best Seller

Corsair Vengeance LPX 32GB (2 X 16GB) DDR4 3200 (PC4-25600) C16 1.35V Desktop Memory - Black

(16,675)
$112.99$101.69
FREE delivery Sun, Aug 10
500+ bought in past month
Loading...
EMOOULI 2 Pcs Graduation Cap Headband, 2025 New Grad Hat Insert, Secure Hairstyle, Not Change Hair, Firm Anti-Fall Hairband for Graduates, Students, Women(Not Including the Grad Hat)

EMOOULI 2 Pcs Graduation Cap Headband, 2025 New Grad Hat Insert, Secure Hairstyle, Not Change Hair, Firm Anti-Fall Hairband for Graduates, Students, Women(Not Including the Grad Hat)

(11)
$8.99
$4.99 delivery Feb 20 - 27