Load Large Language Model (2B Param) on Colab without OOM Memory Issue | Pytorch Tensor GPU
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
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
Related Reads
📰
📰
📰
📰
Will Developers Need LLM Integration Skills in 2026 for Success?
Dev.to AI
I Trained a 471M-Parameter Language Model From Scratch on One RTX 4090 in 100 Hours.
Medium · LLM
Masking PII Without Losing It
Medium · LLM
Build a Career in Artificial Intelligence : AI Mastery Course in Telugu
Dev.to AI
🎓
Tutor Explanation
DeepCamp AI