AI and Deep Learning Community Question

How to optimize LoRA adapters for fine-tuning LLMs on consumer hardware?

Posted on 2024-05-10 • In AI and Deep Learning • By Amanda Roberts

I want to fine-tune a Llama-3 8B model on a specific medical dataset, but I only have a single RTX 3090 with 24GB of VRAM. I’m using Low-Rank Adaptation (LoRA), but I’m still hitting OOM errors during the backward pass. What are the best rank (r) and alpha settings to balance model expressiveness with memory constraints without losing the nuances of the medical terminology?

3 Answers 9,484 Views

All answers to this question 3 Answers

Robert Chen Answered on 2024-05-13
Answered

For a 24GB card, you absolutely need to use QLoRA (Quantized LoRA) with 4-bit loading. Set your rank (r) to 16 and your alpha to 32 as a starting point. In my projects last year, I found that increasing the rank beyond 64 yielded diminishing returns while significantly increasing the memory footprint. Also, make sure you are only targeting the linear layers like 'q_proj' and 'v_proj'. If you try to train all modules, you will definitely hit that OOM error. Using the Unsloth library can also give you a 2x speedup and significantly lower VRAM usage for Llama models.

Kevin Douglas Answered on 2024-05-15
Answered

Have you monitored your gradient accumulation steps? Sometimes the OOM isn't from the model itself but from a batch size that is too high for the optimizer states. Are you using the standard AdamW optimizer, or have you tried a more memory-efficient version like 8-bit Adam or the newer paged optimizers?

Amanda Roberts Commented on 2024-05-16
Commented

Kevin, I was using a batch size of 4 with AdamW. After your comment, I switched to 8-bit Adam and reduced the batch size to 1 while increasing gradient accumulation to 4. This stabilized the VRAM at 21GB, leaving enough overhead for the system. It’s a bit slower per iteration, but at least the training doesn’t crash halfway through the first epoch now. Thanks for the tip!

Laura White Answered on 2024-05-17
Answered

Don't forget to enable Gradient Checkpointing. It trades a bit of compute time to save a massive amount of VRAM by not storing all intermediate activations during the forward pass.

Robert Chen Commented on 2024-05-18
Commented

Laura is spot on. Gradient Checkpointing is the single most effective "free" memory hack for anyone training on a single-GPU setup.

Write a Comment

Your email address will not be published. Required fields are marked (*)

Join the LearnersEra Community

Ask questions, share knowledge and learn from professionals across technology, project management and certification topics.

Change Country and Nearest City

Select your country and nearest city to see courses available in your region.