Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Finetuning LLMs on consumer GPUs
Search
Aniket Maurya
November 07, 2023
Programming
0
140
Finetuning LLMs on consumer GPUs
Aniket Maurya
November 07, 2023
Tweet
Share
More Decks by Aniket Maurya
See All by Aniket Maurya
Building RAG powered applications - PyData London 2nd April
aniketmaurya
0
49
Contributing to Lightning AI OSS
aniketmaurya
0
33
Other Decks in Programming
See All in Programming
Fixstars高速化コンテスト2024準優勝解法
eijirou
0
190
.NETでOBS Studio操作してみたけど…… / Operating OBS Studio by .NET
skasweb
0
120
GitHub CopilotでTypeScriptの コード生成するワザップ
starfish719
26
6k
どうして手を動かすよりもチーム内のコードレビューを優先するべきなのか
okashoi
3
870
ASP.NET Core の OpenAPIサポート
h455h1
0
120
AWSのLambdaで PHPを動かす選択肢
rinchoku
2
390
Findy Team+ Awardを受賞したかった!ベストプラクティス応募内容をふりかえり、開発生産性向上もふりかえる / Findy Team Plus Award BestPractice and DPE Retrospective 2024
honyanya
0
140
CQRS+ES の力を使って効果を感じる / Feel the effects of using the power of CQRS+ES
seike460
PRO
0
240
為你自己學 Python
eddie
0
520
快速入門可觀測性
blueswen
0
500
return文におけるstd::moveについて
onihusube
1
1.4k
ゼロからの、レトロゲームエンジンの作り方
tokujiros
3
1.1k
Featured
See All Featured
Facilitating Awesome Meetings
lara
51
6.2k
Rebuilding a faster, lazier Slack
samanthasiow
79
8.8k
Scaling GitHub
holman
459
140k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
226
22k
A Tale of Four Properties
chriscoyier
157
23k
Building Adaptive Systems
keathley
38
2.4k
GraphQLの誤解/rethinking-graphql
sonatard
68
10k
Build The Right Thing And Hit Your Dates
maggiecrowley
33
2.5k
How STYLIGHT went responsive
nonsquared
96
5.3k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
The World Runs on Bad Software
bkeepers
PRO
66
11k
How GitHub (no longer) Works
holman
312
140k
Transcript
November 2023 1. Finetuning LLMs on consumer GPUs 2. LLM
Evaluation framework and datasets 3. Deep Dive into Transformers 4. Effortlessly analyze multifaceted financial documents with LlamaIndex
Finetuning LLMs on custom datasets Aniket Maurya, Developer Advocate at
Lightning AI November 2023 X.com/aniketmaurya linkedin.com/in/aniketmaurya
• Overview of LLMs • Parameter efficient finetuning with instruction
dataset • Training on consumer GPUs Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 3 Agenda
What are LLMs Lightning AI ©2023 Proprietary and Confidential. All
Rights Reserved. 4
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 5
What are LLMs
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 6
What are LLMs Source: Attention is All you Need
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 7
What are LLMs
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 8
What are LLMs
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 9
What are LLMs *Decoder
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 10
Parameter Efficient Finetuning Source : https://lightning.ai/pages/community/tutorial/lora-llm/
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 11
Parameter Efficient Finetuning
• Remove untruthfulness and toxicity • Customize the output and
tone of language • Privacy and control Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 12 Why Finetune LLMs
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 13
Finetuning LLMs on instruction dataset
• Setup model • Prepare data • Finetune the model
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 14 Finetuning LLMs
• Setup model • Prepare data • Finetune the model
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 15 Finetuning LLMs
• Setup model • Prepare data • Finetune the model
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 16 Finetuning LLMs
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 17
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 18
• 4-bit quantized finetuning and inference • Minimal code, easy
to debug and hack • TPU support • Flash-Attention 2 Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 19 Lit-GPT
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 20
Finetuning Llama on instruction dataset
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 21
Setup Model
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 22
Setup Model
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 23
Prepare Dataset
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 24
Finetune
CUDA Out Of Memory Lightning AI ©2023 Proprietary and Confidential.
All Rights Reserved. 25
• Llama 7B, fp32: ~28GB • Llama 7B, fp16: ~14GB
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 26 Memory Required to load Llama
• Activation memory • Gradient memory • Optimizer memory •
Model memory Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 27 Memory Usage
• Activation memory • Gradient memory • Optimizer memory •
Model memory Source: https://tinkerd.net/blog/machine-learning/distributed-training/ 28 Memory Usage
29 • Reduce the micro batch size Avoid OOM
30 • Reduce the model's context length • Reduce the
micro batch size Avoid OOM
31 • Reduce the model's context length • Use lower
precision • Reduce the micro batch size Avoid OOM
• 4-bit quantization 32 • Reduce the model's context length
• Use lower precision • Reduce the micro batch size Avoid OOM
72% memory reduction Lightning AI ©2023 Proprietary and Confidential. All
Rights Reserved. 33
34 • Reduce the model's context length • Use lower
precision • 4-bit quantization • Do sharding across multiple GPUs • Reduce the micro batch size Avoid OOM
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 35
Avoid OOM
• Lit-GPT with LoRA finetuning • Lower Precision and 4-bit
quantization • Distributed training and activation checkpointing Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 36 Conclusion
Lightning AI ©2023 Proprietary and Confidential. All Rights Reserved. 37
Aniket Maurya