Teach LLM Something New π‘ LoRA Fine Tuning on Custom Data
Python Simplified
@pythonsimplifiedAbout
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
Boost Your LLM Projects
AI-recommended products based on this video

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

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

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

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 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

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 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]](https://m.media-amazon.com/images/I/911ujeCkGfL._AC_UL960_FMwebp_QL65_.jpg)
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 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]](https://m.media-amazon.com/images/I/71W2nK7LUrL._AC_UL960_FMwebp_QL65_.jpg)
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 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]](https://m.media-amazon.com/images/I/71lzXt4djxL._AC_UY654_FMwebp_QL65_.jpg)
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]

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 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)](https://m.media-amazon.com/images/I/71N7xhCJnoL._AC_UL960_FMwebp_QL65_.jpg)
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 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

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 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

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 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

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

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

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.

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

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



















