How To CONVERT LLMs into GPTQ Models in 10 Mins - Tutorial with ๐ค Transformers
Key Takeaways
This video tutorial demonstrates how to convert large language models (LLMs) into GPTQ models using the ๐ค Transformers library, with a focus on post-training quantization and inference using Hugging Face Model Hub.
Full Transcript
to convert a large language model that is in a pytorch file format or safe tensors format to a gptq quantized format this video tutorial is going to directly help you to do that typically people who do not have large gpus want to run large language models prefer a quantized model because quantized model would fit in less compute resource machines if you know the block is one of the most prolific quantized model releaser I've ever seen so in this video we're going to see a new feature that came with hugging face Transformers where the GPT queue has been integrated with Transformers making it easier for you to use gptq models and also making it easier for you to export gptq models or quantize the regular llm into gptq models let's go ahead and start with this entire code that I'm going to use in this video is from this blog post making llms lighter with Auto gptq and Transformers all credited to the team that put together this Google collab notebook I'll link the Google collab notebook in the YouTube description to make it easier for you to get started once you reach the Google collab notebook the first thing that you need to do is you need to click connect make sure that you have got GPU already available in this case we are going to use an Nvidia GPU a T4 machine that has approximately 15 gigs of vram the GPU Graphics memory once you have connected this then you have to install certain libraries I'm going to install Transformers pift accelerate and Optimum so install all the libraries click run away because it says this is the author who created this do not share any details that's fine click and install all the libraries the next thing that you have to do is you have to install auto gbtq until the next release of Auto gbtq you can you can build the library from The Source but after the latest release of Auto gbtq comes in you don't have to do that you can directly do pip install or gptq so let's click install this as well once you do that then the next step is for us to know realize what to do so one we can either quantize the model like a language model llm from scratch or the second option is for us to load the model that has been already quantized this video is particularly focused on quantizing a large language model but in the future I have plans to make a fine tuning as well fine tuning of a GPT EQ model for you to quantize a large language model from scratch the first thing that you need to know is the gptq quantization method is a post Training quantization Method so if you go here you can click this and then see the paper it's called post training quantization that means you are going to train you are going to quantize the model after the training has been already finished so there are certain nuances about how do you do that and that is why for gptq quantization you need data set so the gptq quantization happens by doing inferencing over the data set so you need to pass a data set that the quantizer will use to quantize the model in and itself so you can use any of these default data sets or you can you know just hard code the data as well but the quality of the data set that you give also reflects in the quality of The quantization Happening that's something that you need to keep in mind so here what we are going to do is we're going to use the C4 data set as the data set that we are going to pass into the quantization configuration you can pause in any other data set that you have but just keep in mind if you hard code as well like you can have like a single line as well but then it has its own impact in the way the quantization has been happening so the better the data set is better the quantization or the lesser the accuracy degradation will be okay so how are we going to do the quantization the first step is from Transformers input Auto model for causal Element Auto tokenizer gptq config this is the new feature then you have to specify the model in itself in this case we are going to use the Facebook opt 125 million parameter model next we have to specify the quantization configuration what is the quantization that you want to do what is the Precision to which you want to bring down the quantization to it supports two bit quantization 4 bit quantization six bit quantization and 8-bit quantization and then you have to specify the data set in itself and then you can start the quantization let me run this the first thing is it's going to download the model after it downloads the model it is going to use the quantization configuration and it is going to create the quantized model as part of this tutorial we are also going to learn how to push this quantization quantized model into your hugging phase model Hub which means you can use it whenever you want to it to be used once the model has been downloaded once the quantization has been finished which would take approximately less than 5 minutes as you can see trained split has been done and the quantization has processed has been started at this point the quantization has been successfully done as you can see now let's run this and then see if the quantization has been proper so this is just to make sure whether the quantization as a process has been successful it does not validate whether the quantization inference process which means the model is performing good or not just to make sure whether the quantization has been done properly what we can do is we can look at the decoder layers and we can look at Q weight and Q zeros and then make sure they are of torch in 32 data type so if you see Q8 of torch in 32 data type and q0 of torch int 32 data type which is just here and you know that the quantization has been done properly once again just to click verify this does not make sure whether the quantization is of high quality this just ensures the process called quantization has been successfully done after this is done you can now do the inference on the quantities model we can use the same API so you can just call the tokenizer and you can give a text and then you can just expect it to return something in this case you're going to use the quantized model instead of the base model that we have downloaded the start so hello my name is this and then it gives you the response so that means the quantization has been successfully done you can go ahead they have also given you example of how you can hard code the quantization data set and then use it but if you happen to do that then the quality of the quantization may not be highly good so let's try one more thing question write a joke about Mac computers answer so this is if you know this is not a chat model that's why I'm giving this in this particular format and you can see that it did not give us anything in there anyways the point here is that the model works so the next thing that we are going to do is after the quantization is done we are going to upload the quantized model into our hugging phase modeler for us to use it later on whenever we want the first thing we need to do is we need to authenticate our notebook which means we need to go here and then use notebook login click this this will open up a box and here you have to add your hugging phase token to get your hugging phase token go to your hugging phase account and click the profile icon and click settings once you click settings you can go here and find the token access tokens and copy one of the tokens that are available here come back to the Google collab notebook add it here and then click login once you click login it says login is successful token is valid the permission is right now all you have to do is you have to push the model to the hub so the model name whatever name you want to give you can give and then just run it and this will push the quantized gptq 4-bit quantized model into hugging phase model of which you can use later on whenever we want to use it so model has been pushed here we can click this that will open the link here and you can see the model has been pushed so this is opt 125 million parameter gpdq 4-bit model under one little coder and that is where the model is available now to quickly use the model that we just created so you can go here and then select the model that you want like for example in this case if this is the model that we have used for example you can go here copy this link come back to the Google collab notebook select that model here or you can use the block if you want or in in our case if you want to use the model that we pushed then you can just simply load it nothing else you can simply use it with model tokenizer and just simply load it using the same way you load any large language model from hugging phase modeler once the model has been loaded now all you have to do is do some text generation just check the model in itself you can check the model and the next thing that you can do is you can just start load creating the text let me run this hello my name is something something and then run this and this is going to create okay hello my name is Kari I'm a student of University of California San Diego and it just repeats a bunch of things because we have specified to create a lot of tokens and again this is not the best model that we have got um if you happen to use one of the latest state of the art model then this might have a much better result they've got the code for quantizing or you train fine-tuning a contest model as well I'm going to make a separate tutorial but in case if you want to use it before I make the tutorial if you do not need a tutorial in itself you can go ahead and then start using it in the same Google collab notebook which I'll link it in the YouTube description so to quickly summarize in this video we learned how to quantize a large language model into gptq models and we also learned how to make it into different precisions like two bit four bit six bit eight bit and we also learned about how to push the model finally to the hugging phase model Hub and finally we also learned how to use the model for inference if we have already pushed the model to hogging phase model I hope this tutorial was helpful to you if you have any question let me know in the comment section otherwise Happy prompting
Original Description
In this tutorial, You'll learn everything from:
1. Converting a Pytorch LLM into GPTQ Models
2. Push the newly created GPTQ Models to HF Transformers
3. Load the GPTQ models into Hugging Face Transformers for Inference
Blogpost https://huggingface.co/blog/gptq-integration
Colab https://colab.research.google.com/drive/1_TIrmuKOFhuRRiTWN94iLKUFu6ZX4ceb?usp=sharing
โค๏ธ If you want to support the channel โค๏ธ
Support here:
Patreon - https://www.patreon.com/1littlecoder/
Ko-Fi - https://ko-fi.com/1littlecoder
Watch on YouTube โ
(saves to browser)
Sign in to unlock AI tutor explanation ยท โก30
Playlist
Uploads from 1littlecoder ยท 1littlecoder ยท 0 of 60
โ Previous
Next โ
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
How to create your Free Data Science Blog on Github with Fastpages from Fastai
1littlecoder
Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
1littlecoder
Create your first Data Science Web App using R Shiny
1littlecoder
How to create a Reproducible Example in R using reprex
1littlecoder
No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
1littlecoder
Scrape HTML Table using rvest and Process them for insights using tidyverse in R
1littlecoder
Google Teachable Machine Learning Build No Code AI solution
1littlecoder
Create meaningful fake tidy datasets in R using fakir [#rstats Package]
1littlecoder
How to enable using R Programming with Visual Studio VS Code
1littlecoder
Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
1littlecoder
Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
1littlecoder
Intro to Google Colab - How to use Colab
1littlecoder
Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
1littlecoder
Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
1littlecoder
Do you want a career in Data Science - Tamil Webinar
1littlecoder
Android Smartphone Analysis in R [Live Coding Screencast]
1littlecoder
Programmatically create Images, Memes, Watermarks using Python with imgmaker
1littlecoder
Kaggle Walkthrough to get you started with Data Science - Webinar
1littlecoder
Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
1littlecoder
Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
1littlecoder
Excel to R - Pivot + Bar Chart in Excel & R using tidyverse [Live Coding]
1littlecoder
Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
1littlecoder
5 websites to get Free Real-World Datasets for Data Science/ML Projects
1littlecoder
Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
1littlecoder
Correlation-alternative PPS (Predictive Power Score) Python Package Demo
1littlecoder
Automated Website Screenshots in R using {webshot}
1littlecoder
Installing Custom RStudio Theme (Synthwave85)
1littlecoder
Analyse Google Trends Search Data in R using {gtrendsR}
1littlecoder
3 Tips to ask question on Stack Overflow the right way to get answers
1littlecoder
Learn Data Science with R - Mini Projects - Web Scraping Zomato
1littlecoder
Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
1littlecoder
GET Hackernews Front Page Results using REST API in R
1littlecoder
Quickly deploy ML WebApps from Google Colab using ngrok
1littlecoder
Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
1littlecoder
Plotly Interactive Plots as Pandas Plotting Backend df.plot()
1littlecoder
Stack Overflow Developer Survey 2020 Highlights for New Programmers
1littlecoder
Matplotlib Animation Charts in Python using Celluloid
1littlecoder
Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
1littlecoder
Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
1littlecoder
Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
1littlecoder
Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
1littlecoder
Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
1littlecoder
ggplot2 Text Customization with ggtext | Data Visualization in R
1littlecoder
Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
1littlecoder
YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
1littlecoder
Matplotlib Animated Bar Chart Race in Python | Data Visualization
1littlecoder
Simple Python GUI Development using {guietta}
1littlecoder
#8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
1littlecoder
Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
1littlecoder
Github New Feature Profile Summary/Mini-Resume - Profile Views
1littlecoder
Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
1littlecoder
What is OpenAI GPT-3 - Hype, Examples, Worries
1littlecoder
Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
1littlecoder
Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
1littlecoder
GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
1littlecoder
How to use Advanced Google Search to extract Email Ids from Linkedin
1littlecoder
Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
1littlecoder
Flow - R Package to visualize code logic, functions as a Flow Diagram
1littlecoder
Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
1littlecoder
Create a Pencil Sketch Portrait with Python OpenCV
1littlecoder
More on: LLM Foundations
View skill โRelated Reads
๐ฐ
๐ฐ
๐ฐ
๐ฐ
Top AI Papers on Hugging Face - 2026-07-15
Dev.to AI
Integrating Open-Weight LLMs as Drop-In API Replacements: A Practical Guide
Dev.to AI
How I Built a Multi-Page AI Website Generator for Nigerian SMBs โ Architecture, LLM Prompting, and Lessons Learned
Dev.to ยท Innocent Oyebode
The Token Tax: Why You Are Paying for How AI โThinks,โ Not What It Writes
Medium ยท AI
๐
Tutor Explanation
DeepCamp AI