<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Building With LLMs]]></title><description><![CDATA[Building With LLMs]]></description><link>https://harshagale.hashnode.dev</link><image><url>https://cdn.hashnode.com/uploads/logos/6a1001f91f237623eaba1743/77ab5c17-c1c6-4344-af51-d49f58823ffb.jpg</url><title>Building With LLMs</title><link>https://harshagale.hashnode.dev</link></image><generator>RSS for Node</generator><lastBuildDate>Wed, 09 Sep 2026 11:10:59 GMT</lastBuildDate><atom:link href="https://harshagale.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[How I Fine-Tuned Llama 2 Using QLoRA on Free GPU Resources]]></title><description><![CDATA[Training and fine-tuning Large Language Models (LLMs) is often considered expensive and hardware-intensive. Most tutorials online assume access to powerful GPUs with large amounts of VRAM, which can b]]></description><link>https://harshagale.hashnode.dev/how-i-fine-tuned-llama-2-using-qlora-on-free-gpu-resources</link><guid isPermaLink="true">https://harshagale.hashnode.dev/how-i-fine-tuned-llama-2-using-qlora-on-free-gpu-resources</guid><category><![CDATA[AI]]></category><category><![CDATA[llm]]></category><category><![CDATA[qlora]]></category><category><![CDATA[Machine Learning]]></category><category><![CDATA[Python]]></category><category><![CDATA[huggingface]]></category><category><![CDATA[finetuning]]></category><dc:creator><![CDATA[Harsh Agale]]></dc:creator><pubDate>Fri, 22 May 2026 08:30:37 GMT</pubDate><enclosure url="https://cdn.hashnode.com/uploads/covers/6a1001f91f237623eaba1743/63c3db23-5ce0-4f6b-87dd-2a3e9eacfed4.jpg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Training and fine-tuning Large Language Models (LLMs) is often considered expensive and hardware-intensive. Most tutorials online assume access to powerful GPUs with large amounts of VRAM, which can be difficult for students and independent developers.</p>
<p>While learning about LLM fine-tuning, I wanted to understand how techniques like LoRA and QLoRA actually work in practice. My goal was not just to use an LLM, but to learn how efficient fine-tuning works behind the scenes and how modern AI systems can be trained on limited hardware resources.</p>
<p>That’s when I discovered QLoRA.</p>
<p>Using QLoRA, I was able to fine-tune the Nous Research version of Meta Llama 2 (<code>NousResearch/Llama-2-7b-chat-hf</code>) using free GPU resources on <a href="https://www.kaggle.com?utm_source=chatgpt.com">Kaggle</a>. The process was significantly more memory efficient compared to traditional full fine-tuning, while still producing meaningful results.</p>
<h2>What is QLoRA?</h2>
<p>QLoRA (Quantized Low-Rank Adaptation) is an efficient fine-tuning technique designed to reduce GPU memory usage while training large language models.</p>
<p>Instead of retraining the entire model, QLoRA:</p>
<ul>
<li><p>freezes the original model weights,</p>
</li>
<li><p>quantizes the model into 4-bit precision,</p>
</li>
<li><p>and trains only small adapter layers.</p>
</li>
</ul>
<p>This dramatically reduces VRAM requirements while still allowing the model to learn task-specific behavior.</p>
<p>At a high level:</p>
<pre><code class="language-python">Traditional Fine-Tuning:
Train Entire Model → Very Expensive

QLoRA:
Freeze Base Model + Train Small Adapters → Much Cheaper
</code></pre>
<p>The biggest advantage for me was that I could experiment with LLM fine-tuning on free cloud GPUs without needing enterprise-level hardware.</p>
<h2>Model and Dataset</h2>
<p>For this experiment, I used:</p>
<h2>Base Model</h2>
<p><strong>NousResearch/Llama-2-7b-chat-hf</strong></p>
<p>Hosted on:</p>
<p><a href="https://huggingface.co/harshagale/llm-upload">https://huggingface.co/harshagale/llm-upload</a></p>
<h2>Dataset</h2>
<p>I used the <code>mlabonne/guanaco-llama2-1k</code> dataset from Hugging Face.</p>
<p>The dataset contains instruction-response style conversational data that works well for supervised fine-tuning experiments.</p>
<h2>Tech Stack</h2>
<p>The project was built using:</p>
<ul>
<li><p><a href="https://huggingface.co/docs/transformers/index?utm_source=chatgpt.com">Transformers Library</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/peft/index?utm_source=chatgpt.com">PEFT Library</a></p>
</li>
<li><p><a href="https://github.com/bitsandbytes-foundation/bitsandbytes?utm_source=chatgpt.com">BitsAndBytes</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/trl/index?utm_source=chatgpt.com">TRL Library</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/datasets/index?utm_source=chatgpt.com">Datasets Library</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/accelerate/index?utm_source=chatgpt.com">Accelerate</a></p>
</li>
</ul>
<p>These libraries made it possible to load, quantize, train, and evaluate the model efficiently.</p>
<h2>Why I Chose QLoRa instead of Full Fine-Tuning</h2>
<p>The biggest challenge with full fine-tuning is hardware cost.</p>
<p>Training a 7B parameter model normally requires:</p>
<ul>
<li><p>high VRAM GPUs,</p>
</li>
<li><p>large compute budgets,</p>
</li>
<li><p>and significantly longer training times.</p>
</li>
</ul>
<p>Since I was learning and experimenting, I wanted a solution that was:</p>
<ul>
<li><p>memory efficient,</p>
</li>
<li><p>cheaper,</p>
</li>
<li><p>faster to iterate with,</p>
</li>
<li><p>and realistic for limited hardware environments.</p>
</li>
</ul>
<p>QLoRA solved that problem by using:</p>
<ul>
<li><p>4-bit quantization,</p>
</li>
<li><p>frozen base weights,</p>
</li>
<li><p>and trainable LoRA adapters.</p>
</li>
</ul>
<p>This reduced GPU memory usage significantly while still allowing the model to adapt to the dataset.</p>
<h2>Loading the Model in 4-Bit</h2>
<p>One of the most important parts of the project was loading the model using 4-bit quantization.</p>
<p>Example configuration:</p>
<pre><code class="language-python">from transformers import BitsAndBytesConfig

bnb_config = BitsAndBytesConfig(
    load_in_4bit=True,
    bnb_4bit_quant_type="nf4",
    bnb_4bit_compute_dtype="float16"
)
</code></pre>
<p>This configuration allowed the large Llama 2 model to fit within limited GPU memory.</p>
<h2>Applying QLoRA</h2>
<p>Using the <a href="https://huggingface.co/docs/peft/index?utm_source=chatgpt.com">PEFT Library</a>, I configured LoRA adapters on top of the quantized model.</p>
<p>Example:</p>
<pre><code class="language-python">from peft import LoraConfig

peft_config = LoraConfig(
    lora_alpha=16,
    lora_dropout=0.1,
    r=64,
    bias="none",
    task_type="CAUSAL_LM"
)
</code></pre>
<p>Instead of updating billions of parameters, the training process only updated lightweight adapter layers.</p>
<p>This is what made training practical on free GPU resources.</p>
<h2>Training Architecture</h2>
<p>The workflow looked like this:</p>
<pre><code class="language-python">Dataset
   ↓
Tokenizer
   ↓
4-bit Quantized Llama 2
   ↓
LoRA Adapters
   ↓
Trainer (TRL)
   ↓
Evaluation Metrics
   ↓
Push to Hugging Face Hub
</code></pre>
<p>This modular pipeline helped me understand how modern efficient fine-tuning systems are structured.</p>
<h2>Challenges I Faced</h2>
<p>During the project, I faced several practical challenges:</p>
<p><strong>1. GPU Memory Limitations</strong></p>
<p>Even with free cloud GPUs, large models can quickly exhaust VRAM.</p>
<p>Using:</p>
<ul>
<li><p>4-bit quantization,</p>
</li>
<li><p>gradient accumulation,</p>
</li>
<li><p>and QLoRA adapters</p>
</li>
</ul>
<p>helped reduce memory usage significantly.</p>
<p><strong>2. Dependency Compatibility</strong></p>
<p>Libraries like:</p>
<ul>
<li><p><code>transformers</code></p>
</li>
<li><p><code>bitsandbytes</code></p>
</li>
<li><p><code>accelerate</code></p>
</li>
<li><p>and <code>trl</code></p>
</li>
</ul>
<p>need compatible versions. Small mismatches sometimes caused runtime issues during training.</p>
<p>This taught me the importance of environment management in AI engineering projects.</p>
<p><strong>3. Training Speed</strong></p>
<p>Even though QLoRA reduced memory requirements, training still required careful configuration to balance:</p>
<ul>
<li><p>batch size,</p>
</li>
<li><p>training stability,</p>
</li>
<li><p>and runtime efficiency.</p>
</li>
</ul>
<h2>Evaluation</h2>
<p>To evaluate the fine-tuned model, I experimented with:</p>
<ul>
<li><p>ROUGE metrics</p>
</li>
<li><p>Perplexity evaluation</p>
</li>
</ul>
<p>These metrics helped me understand:</p>
<ul>
<li><p>response quality,</p>
</li>
<li><p>language consistency,</p>
</li>
<li><p>and model confidence.</p>
</li>
</ul>
<p>Although this was primarily a learning-focused project, the evaluation process helped me understand how LLM performance is measured in real-world workflows.</p>
<h2>What I Learned</h2>
<p>This project taught me several important lessons about modern AI engineering:</p>
<ul>
<li><p>Efficient fine-tuning techniques are extremely powerful.</p>
</li>
<li><p>Full fine-tuning is not always necessary.</p>
</li>
<li><p>Quantization can dramatically reduce hardware requirements.</p>
</li>
<li><p>Environment management is critical in ML workflows.</p>
</li>
<li><p>Practical experimentation teaches far more than theory alone.</p>
</li>
</ul>
<p>Most importantly, I learned that working with LLMs is not only about using APIs — understanding training pipelines, optimization techniques, and evaluation methods is equally important.</p>
<h2>Final Thoughts</h2>
<p>QLoRA made LLM fine-tuning accessible on limited hardware and allowed me to experiment with real-world model training without expensive infrastructure.</p>
<p>This project helped me gain hands-on experience with:</p>
<ul>
<li><p>efficient LLM fine-tuning,</p>
</li>
<li><p>quantization,</p>
</li>
<li><p>adapter-based training,</p>
</li>
<li><p>model evaluation,</p>
</li>
<li><p>and Hugging Face ecosystem tools.</p>
</li>
</ul>
<p>For anyone interested in learning practical LLM engineering, QLoRA is an excellent starting point.</p>
<h2>Links</h2>
<ul>
<li><p><a href="https://huggingface.co/harshagale?utm_source=chatgpt.com">My Hugging Face Profile</a></p>
</li>
<li><p><a href="https://github.com/harshagale1355?utm_source=chatgpt.com">My GitHub Profile</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/transformers/index?utm_source=chatgpt.com">Hugging Face Transformers Documentation</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/peft/index?utm_source=chatgpt.com">PEFT Documentation</a></p>
</li>
<li><p><a href="https://huggingface.co/docs/trl/index?utm_source=chatgpt.com">TRL Documentation</a></p>
</li>
</ul>
]]></content:encoded></item></channel></rss>