Load Large Language Model (2B Param) on Colab without OOM Memory Issue | Pytorch Tensor GPU

1littlecoder · Intermediate ·🧠 Large Language Models ·4y ago

Key Takeaways

Load a 2B parameter large language model on Colab using Pytorch Tensor GPU without running into OOM memory issues

Full Transcript

hey friends welcome to online recorder recently in one of my popular videos which is about um building your own github co-pilot using salesforce's code gen ai model i mentioned that you know i was using google collab and i was using the lowest size model which was 350 mb because i could not load large size model large language model llb llm sorry large language model with for example to say that two billion model after i mentioned this actually the founder um the creator of code gen um replied to one of my tweet on twitter saying that we could load the large model by setting default tensor allocation to gpu memory so i want to stand corrected and i want to also show you how to use um how to load large language model especially code gen related i've not tested it with any other language model but for code gym if you want to build your own github co-pilot or you want to build your own programming assistant ai assistant then you can actually indeed load large language model especially in my case i'm testing the two billion model and by using by asking by setting the default tensor allocation to deep gpu what does it mean and i'm going to show you in this video that's what this video is going to be very short if you already have seen this code um the only change you would see from my previous code and the current code is this part as usual we're downloading the we are installing the latest transformers from github the next thing is we are saying we are telling torch to set the default tensor type to torch dot cuda dot float tensor by default if you see the torch cuda um let me show you torch set default um so if you see the default tensor type is by default it is pointing to the tensor type t and then it uses the default type what we are asking now on pi dots to do is we are telling pythons that use the gpu use torch dot co dot float tensor so now the point is why cannot i do this for all the models i think this is not um aligning in line with what pi touch is advising us to do there has been a little bit of discussion in the community as well for example why why don't i just set it up by default and then there are there are like people i can show you um yeah is there anything i'll link this discussion in the youtube description so you can see so around 2018 this kind of discussion has happened why this is not a great idea why it breaks some models why it doesn't go well with what pytorch is saying so i'll link all these conversations for you to make a decision for yourself if you want to use this setup in all your projects but at least for this project for this code gen if you set if you force pytorch um the tensor allocation to use gpu memory then you can indeed use um load the large model if you do not do this by the time the two billion model gets downloaded your google collab session will crash and restart but if you do that i can quickly show you my memory so you can see that i've maxed almost maxed out my gpu memory at this point and uh it still works like i can just simply run the code so i've loaded the two billion model now i can say for example if let me let me keep this in the side so that you get to see this as well and i can say what do i want to say i want to say def um default slower to upper i can say input text it's a very silly code but let's see so i'm going to i'm running this code and you can see that this code is running and it is going to potentially produce the result at this point let's let's wait for wait for it to and you also you know you you know that you have loaded a two billion um model a two billion parameter model in the last video i said dollars so just being careful so we have loaded a two billion um parameter model so it's going to take a little bit of time in executing you can see that it took about 18 seconds for it to execute this is just inference where you take the text tokenize it use the model to generate the output and then decode it and then show it show the result but it has given you the result like whatever you wanted if you if you tell um it it works completely fine and then you have a you have a larger model which means it must be more um it must have more capability in producing the result than having a 350 million 350 mb um million parameters 350 million parameters so two billion parameters is always better i just wanted to quickly show you the memory allocation just to show you that this actually works when i run this this is from torch coda memory summary you can see that the gpu uh reserve memory is completely full a couple of um like it's totally allocated but you can see that there was no cuda out of memories so that that is a good thing so even when we have a two billion parameter model loaded um our machine is working fine and we could do inference fine without maxing out so i think this is a very good tip so thanks to thanks to eric for giving us this tip so this something that i did not know that you could do even in the previous case we were actually you know at the tokenization side and at the model site we were converting um everything to coda but we did not set the default intertype and like i said this is um this is a point of conversation and discussion in python's community you can see on the community pages and there was a github issue which talks about that we should get away with this so i would link those things in the youtube description but but for now you know this just works you can load a two billion parameter code gen model on google collab and build your own github cobit if you have not seen that video i would i mean as as as a youtuber i would strongly recommend you to watch my video on how to build your own keyword co-pilot with code gin dot ai sorry code gen ei from salesforce but otherwise um this is a this is a new tip on how to force um the default tensor allocation to gpu memory and then load large language models any questions let me know in the comment section otherwise happy coding see you in the next video peace

Original Description

Original Video of Building your own Github CoPilot Programming Assistant - https://youtu.be/8VyGlSKsYeo Colab - https://colab.research.google.com/drive/1k47X9rdkl-1IvyvtYY3MDeW0JwqbRmQR?usp=sharing Credit: https://twitter.com/erik_nijkamp/status/1543381881499947009 Pytorch discussion - https://discuss.pytorch.org/t/is-there-anything-wrong-with-setting-default-tensor-type-to-cuda/27949 #pytorch #gpu #colab
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 How to create your Free Data Science Blog on Github with Fastpages from Fastai
How to create your Free Data Science Blog on Github with Fastpages from Fastai
1littlecoder
2 Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
Making Interactive Matplotlib Plots for Data Science Visualizations on Jupyter (Python)
1littlecoder
3 Create your first Data Science Web App using R Shiny
Create your first Data Science Web App using R Shiny
1littlecoder
4 How to create a Reproducible Example in R using reprex
How to create a Reproducible Example in R using reprex
1littlecoder
5 No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
No Code Visualization using esquisse with Tableau-like Drag and Drop GUI in R
1littlecoder
6 Scrape HTML Table using rvest and Process them for insights using tidyverse in R
Scrape HTML Table using rvest and Process them for insights using tidyverse in R
1littlecoder
7 Google Teachable Machine Learning Build No Code AI solution
Google Teachable Machine Learning Build No Code AI solution
1littlecoder
8 Create meaningful fake tidy datasets in R using fakir [#rstats Package]
Create meaningful fake tidy datasets in R using fakir [#rstats Package]
1littlecoder
9 How to enable using R Programming with Visual Studio VS Code
How to enable using R Programming with Visual Studio VS Code
1littlecoder
10 Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
Python, Community, Books - with Abhiram R - Bangpypers Co-organizers | 1littlecoder podcast
1littlecoder
11 Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
Growing a Tech Community across India - Anubha Maneshwar, Founder Girlscript | 1littlecoder Podcast
1littlecoder
12 Intro to Google Colab - How to use Colab
Intro to Google Colab - How to use Colab
1littlecoder
13 Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
Intro to Plotly Express - Complex Interactive Charts with One-Line of Python Code
1littlecoder
14 Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
Indic NLP Python Toolkit Open Source Development - iNLTK Creator Gaurav Arora | 1littlecoder Podcast
1littlecoder
15 Do you want a career in Data Science - Tamil Webinar
Do you want a career in Data Science - Tamil Webinar
1littlecoder
16 Android Smartphone Analysis in R [Live Coding Screencast]
Android Smartphone Analysis in R [Live Coding Screencast]
1littlecoder
17 Programmatically create Images, Memes, Watermarks using Python with imgmaker
Programmatically create Images, Memes, Watermarks using Python with imgmaker
1littlecoder
18 Kaggle Walkthrough to get you started with Data Science - Webinar
Kaggle Walkthrough to get you started with Data Science - Webinar
1littlecoder
19 Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
Community, Corporate Job, Coding - Gnana Lakshmi T C aka Gyan, WomenWhoCode Leadership Fellow
1littlecoder
20 Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
Easy ggplot2 Theme Customization with {ggeasy} | Data Visualization in R
1littlecoder
21 Excel to R - Pivot + Bar Chart in Excel  & R using tidyverse [Live Coding]
Excel to R - Pivot + Bar Chart in Excel & R using tidyverse [Live Coding]
1littlecoder
22 Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
Excel to R #2 - VLOOKUP in Excel to LEFT_JOIN, MERGE in R
1littlecoder
23 5 websites to get Free Real-World Datasets for Data Science/ML Projects
5 websites to get Free Real-World Datasets for Data Science/ML Projects
1littlecoder
24 Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
Excel to R #3 - APPROXIMATE VLOOKUP in Excel to FUZZY LEFT_JOIN in R
1littlecoder
25 Correlation-alternative PPS (Predictive Power Score) Python Package Demo
Correlation-alternative PPS (Predictive Power Score) Python Package Demo
1littlecoder
26 Automated Website Screenshots in R using {webshot}
Automated Website Screenshots in R using {webshot}
1littlecoder
27 Installing Custom RStudio Theme (Synthwave85)
Installing Custom RStudio Theme (Synthwave85)
1littlecoder
28 Analyse Google Trends Search Data in R using {gtrendsR}
Analyse Google Trends Search Data in R using {gtrendsR}
1littlecoder
29 3 Tips to ask question on Stack Overflow the right way to get answers
3 Tips to ask question on Stack Overflow the right way to get answers
1littlecoder
30 Learn Data Science with R - Mini Projects - Web Scraping Zomato
Learn Data Science with R - Mini Projects - Web Scraping Zomato
1littlecoder
31 Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
Easily make Dumbbell Chart using {ggcharts} | Data Visualization in R
1littlecoder
32 GET Hackernews Front Page Results using REST API in R
GET Hackernews Front Page Results using REST API in R
1littlecoder
33 Quickly deploy ML WebApps from Google Colab using ngrok
Quickly deploy ML WebApps from Google Colab using ngrok
1littlecoder
34 Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
Use Jupyter Notebooks within VSCode (Visual Studio Code) in 2020
1littlecoder
35 Plotly Interactive Plots as Pandas Plotting Backend df.plot()
Plotly Interactive Plots as Pandas Plotting Backend df.plot()
1littlecoder
36 Stack Overflow Developer Survey 2020 Highlights for New Programmers
Stack Overflow Developer Survey 2020 Highlights for New Programmers
1littlecoder
37 Matplotlib Animation Charts in Python using Celluloid
Matplotlib Animation Charts in Python using Celluloid
1littlecoder
38 Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
Coding, Postwoman, Passion Project Book - Liyas Thomas Open Source Developer - 1littlecoder podcast
1littlecoder
39 Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
Aspiring Data Scientist, Tips on How to learn Business Domain Knowledge
1littlecoder
40 Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
Bokeh Interactive Charts as Pandas Plotting Backend df.plot_bokeh()
1littlecoder
41 Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
Easy Fast Python Pandas Summary with Sidetable | Pandas Tips & Tricks
1littlecoder
42 Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
Inception, Content Ideas, Consistency - Srivatsan Srinivasan AIEngineering YouTube Content Creator
1littlecoder
43 ggplot2 Text Customization with ggtext | Data Visualization in R
ggplot2 Text Customization with ggtext | Data Visualization in R
1littlecoder
44 Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
Penguins Dataset Overview - iris alternative | EDA Data Visualization in R
1littlecoder
45 YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
YouTube Growth Tips, Content Creation - Bhavesh Bhatt, YouTuber (Data Science & Machine Learning) #7
1littlecoder
46 Matplotlib Animated Bar Chart Race in Python | Data Visualization
Matplotlib Animated Bar Chart Race in Python | Data Visualization
1littlecoder
47 Simple Python GUI Development using {guietta}
Simple Python GUI Development using {guietta}
1littlecoder
48 #8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
#8 Niche, Growth, Monetization - David Langer - YouTuber Dave on Data
1littlecoder
49 Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
Simple Fast 3-step Python OCR using Deep Learning 40+ Languages
1littlecoder
50 Github New Feature Profile Summary/Mini-Resume - Profile Views
Github New Feature Profile Summary/Mini-Resume - Profile Views
1littlecoder
51 Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
Otto ML Assistant, GPT-3 on Philosophers, Nvidia-ARM - 3 ML Tech News
1littlecoder
52 What is OpenAI GPT-3 - Hype, Examples, Worries
What is OpenAI GPT-3 - Hype, Examples, Worries
1littlecoder
53 Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
Julia 1.5, Datamuse API, Live HDR+ Pixel 4a - Machine Learning Tech News
1littlecoder
54 Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
Self-driving Car Engineer sentenced, arXiv Dataset, AI/ML Startup Idea - Machine Learning Tech News
1littlecoder
55 GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
GPT-3 Explorer, Ciphey (Automated Decryption), Py-Sudoku - ML Tech News
1littlecoder
56 How to use Advanced Google Search to extract Email Ids from Linkedin
How to use Advanced Google Search to extract Email Ids from Linkedin
1littlecoder
57 Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
Cartoonizer Toon-IT (AI Web App), GPT-3 Advice, Android Earthquake Detection - ML Tech News
1littlecoder
58 Flow - R Package to visualize code logic, functions as a Flow Diagram
Flow - R Package to visualize code logic, functions as a Flow Diagram
1littlecoder
59 Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
Build GPT-3-like Language Model on Google Colab with minGPT [PyTorch]
1littlecoder
60 Create a Pencil Sketch Portrait with Python OpenCV
Create a Pencil Sketch Portrait with Python OpenCV
1littlecoder

Related Reads

📰
Will Developers Need LLM Integration Skills in 2026 for Success?
Developers will need LLM integration skills in 2026 to stay competitive, learn how to integrate AI into your workflow
Dev.to AI
📰
I Trained a 471M-Parameter Language Model From Scratch on One RTX 4090 in 100 Hours.
Train a large language model from scratch on a single GPU in under 100 hours, leveraging recent advances in AI hardware and software
Medium · LLM
📰
Masking PII Without Losing It
Learn to mask personally identifiable information (PII) without losing its value using LLMs, ensuring user privacy and data security
Medium · LLM
📰
Build a Career in Artificial Intelligence : AI Mastery Course in Telugu
Learn how to build a career in Artificial Intelligence with a comprehensive AI mastery course in Telugu
Dev.to AI
Up next
5 Levels of AI Agents - From Simple LLM Calls to Multi-Agent Systems
Dave Ebbelaar (LLM Eng)
Watch →