<?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" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:googleplay="http://www.google.com/schemas/play-podcasts/1.0"><channel><title><![CDATA[MLOps Consulting]]></title><description><![CDATA[An explainer series of practical and useful guides to understand how we can get the most out of machine learning and advances in artificial intelligence.]]></description><link>https://blog.mlops.consulting</link><image><url>https://substackcdn.com/image/fetch/$s_!8QtU!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcedba0c7-e317-4d2d-9be7-5415e7c04143_620x620.png</url><title>MLOps Consulting</title><link>https://blog.mlops.consulting</link></image><generator>Substack</generator><lastBuildDate>Tue, 07 Apr 2026 10:01:01 GMT</lastBuildDate><atom:link href="https://blog.mlops.consulting/feed" rel="self" type="application/rss+xml"/><copyright><![CDATA[MLOPs Consulting]]></copyright><language><![CDATA[en]]></language><webMaster><![CDATA[mlopsconsulting@substack.com]]></webMaster><itunes:owner><itunes:email><![CDATA[mlopsconsulting@substack.com]]></itunes:email><itunes:name><![CDATA[Adam Knight]]></itunes:name></itunes:owner><itunes:author><![CDATA[Adam Knight]]></itunes:author><googleplay:owner><![CDATA[mlopsconsulting@substack.com]]></googleplay:owner><googleplay:email><![CDATA[mlopsconsulting@substack.com]]></googleplay:email><googleplay:author><![CDATA[Adam Knight]]></googleplay:author><itunes:block><![CDATA[Yes]]></itunes:block><item><title><![CDATA[Pac-Man Lego and an LLM epiphany]]></title><description><![CDATA[On my 42nd birthday, I was handed a challenge wrapped in a gift box - a 2651-piece Lego Icons Pac-Man set.]]></description><link>https://blog.mlops.consulting/p/pac-man-lego-and-an-llm-epiphany</link><guid isPermaLink="false">https://blog.mlops.consulting/p/pac-man-lego-and-an-llm-epiphany</guid><dc:creator><![CDATA[Adam Knight]]></dc:creator><pubDate>Fri, 15 Sep 2023 09:00:29 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!YCbe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!YCbe!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!YCbe!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 424w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 848w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!YCbe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg" width="1400" height="1199" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1199,&quot;width&quot;:1400,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:188869,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!YCbe!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 424w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 848w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!YCbe!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F73812659-c183-4a67-8417-aaefea0b9209_1400x1199.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>On my 42nd birthday, I was handed a challenge wrapped in a gift box - a 2651-piece Lego Icons Pac-Man set. As I unwrapped the box, a wave of nostalgia washed over me both for Lego and of course Pac-Man. The bright, colourful blocks, the familiar click as they snapped together, and the anticipation of seeing a pile of pieces transform into a tangible, recognisable form &#8211; it was a trip back to the carefree days of my childhood.</p><p>But this was no ordinary Lego set. With its 2600+ pieces and an instruction guide an inch thick, it was a behemoth that demanded patience, precision, and a keen eye for detail. Speaking to a large number of users and engineers over the last year, I couldn't help but draw parallels between my Lego endeavour and what is being asked of large language models the majority of the time.</p><p>&#8216;Achieve this hard task, but I&#8217;m only going to give you a little if any of the nuance and context that I would give to a person if I were asking them to do the same job&#8217;.</p><p>Language, like this Lego set, is not a simple, straightforward entity. It is a complex structure, a jigsaw puzzle with countless pieces. Each word, each phrase, each idiom carries a weight of history, nuance, and context. They are not just building blocks of communication; they are the carriers of culture, the markers of time, the reflections of our collective consciousness.</p><p>As I poured over the instructions, something particularly struck me: the organisation of pieces into numbered bags. These bags make it easier to locate the next brick required, but they also constrain my choice, effectively directing my actions towards the correct sequence for assembly. In much the same way, the addition of nuance and context to a prompt given to a large language model narrows down the pool of potential next tokens, making the model&#8217;s response more aligned with the intended query.</p><p>Consider a general prompt like, "Tell me about climate change." A large language model could respond with a broad spectrum of answers, ranging from the science behind climate change to its socio-political implications. Now, contrast this with a more nuanced prompt, such as, "Explain the impact of climate change on polar ice caps in the last decade." The latter, with its added context and specificity, restricts the model's potential outputs. The range of relevant tokens narrows significantly, honing the model's focus and driving it toward a more precise and relevant response.</p><p>Just as the numbered bags in my Lego set served to filter out irrelevant pieces, leading me to the exact components I needed to complete a specific section, contextual cues and nuanced prompts steer a language model toward generating more relevant, coherent, and valuable outputs. In both instances, whether assembling intricate Lego structures or generating human-like text, the devil is in the details&#8212;nuance and context act as invaluable guides in the building process.</p><p>Expecting AI to understand and replicate this complexity based on surface-level information is like expecting to build my Pac-Man set by just looking at the box. It's not just about knowing what the final product looks like; it's about understanding the 'why' and 'how' of each piece, each step in the process. It's about recognising patterns, making connections, and anticipating outcomes. </p><p>As engineers in this new world it's imperative that we do more than just write code; we must be architects of a new digital-human interface. While it's tempting to rely solely on the advancements in language models, or place the burden on users to adapt, such an approach sells the technology short and limits its transformative potential.</p><p>We must take the helm in actively shaping how these models interact with users. We are the mediators who must make AI not just powerful, but also accessible, intuitive, and deeply attuned to human needs. Failing to do so risks leaving an enormous gap between what AI could be and what it becomes, a gap filled with missed opportunities to genuinely improve the human experience.</p><p>The onus is on us to not just engineer but to envision, to pave the way for a future where technology truly serves humanity. Anything less is an abdication of our role as the architects of tomorrow's digital world.</p><p>As I sat there with my Lego set, painstakingly placing each block, following each step in the guide, for two whole days. I couldn't help but marvel at the complexity of the set and the attention to detail in the instructions.</p><p>Building the Lego Icons Pac-Man set was a journey, a challenge, and a joy. It was a reminder of the beauty of complexity and the thrill of creation. And it gave me an insight in to the potential of AI, a promise of a future where technology understands us, aids us, and enriches our lives in ways we can't even imagine yet.</p><p>So, as AI engineers, our task is clear. We need to understand the complexity, appreciate the nuance, and respect the context. We need to create tools that help users be more productive, do better, and more creative work. And we need to remember that our goal is not just to build technology, but to build bridges between technology and humanity.</p><p>Here's to the journey ahead, filled with challenges, discoveries, and breakthroughs. Because with the right tools, the right approach, and the right mindset, who knows what we can build?</p>]]></content:encoded></item><item><title><![CDATA[Guide to Fine-Tuning Large Language Models (LLMs) with QLoRA]]></title><description><![CDATA[Part of an explainer series of practical and useful guides to understand how we can get the most out of machine learning and advances in artificial intelligence.]]></description><link>https://blog.mlops.consulting/p/guide-to-fine-tuning-large-language</link><guid isPermaLink="false">https://blog.mlops.consulting/p/guide-to-fine-tuning-large-language</guid><dc:creator><![CDATA[Adam Knight]]></dc:creator><pubDate>Fri, 18 Aug 2023 08:08:11 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!aS-T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<div class="captioned-image-container"><figure><a class="image-link image2 is-viewable-img" target="_blank" href="https://substackcdn.com/image/fetch/$s_!aS-T!,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg" data-component-name="Image2ToDOM"><div class="image2-inset"><picture><source type="image/webp" srcset="https://substackcdn.com/image/fetch/$s_!aS-T!,w_424,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_848,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_1272,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_1456,c_limit,f_webp,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 1456w" sizes="100vw"><img src="https://substackcdn.com/image/fetch/$s_!aS-T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg" width="1024" height="1024" data-attrs="{&quot;src&quot;:&quot;https://substack-post-media.s3.amazonaws.com/public/images/3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg&quot;,&quot;srcNoWatermark&quot;:null,&quot;fullscreen&quot;:null,&quot;imageSize&quot;:null,&quot;height&quot;:1024,&quot;width&quot;:1024,&quot;resizeWidth&quot;:null,&quot;bytes&quot;:253960,&quot;alt&quot;:null,&quot;title&quot;:null,&quot;type&quot;:&quot;image/jpeg&quot;,&quot;href&quot;:null,&quot;belowTheFold&quot;:false,&quot;topImage&quot;:true,&quot;internalRedirect&quot;:null,&quot;isProcessing&quot;:false,&quot;align&quot;:null,&quot;offset&quot;:false}" class="sizing-normal" alt="" srcset="https://substackcdn.com/image/fetch/$s_!aS-T!,w_424,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 424w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_848,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 848w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_1272,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 1272w, https://substackcdn.com/image/fetch/$s_!aS-T!,w_1456,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2F3c8d395f-33f4-4500-ac1b-63854af71763_1024x1024.jpeg 1456w" sizes="100vw" fetchpriority="high"></picture><div class="image-link-expand"><div class="pencraft pc-display-flex pc-gap-8 pc-reset"><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container restack-image"><svg role="img" width="20" height="20" viewBox="0 0 20 20" fill="none" stroke-width="1.5" stroke="var(--color-fg-primary)" stroke-linecap="round" stroke-linejoin="round" xmlns="http://www.w3.org/2000/svg"><g><title></title><path d="M2.53001 7.81595C3.49179 4.73911 6.43281 2.5 9.91173 2.5C13.1684 2.5 15.9537 4.46214 17.0852 7.23684L17.6179 8.67647M17.6179 8.67647L18.5002 4.26471M17.6179 8.67647L13.6473 6.91176M17.4995 12.1841C16.5378 15.2609 13.5967 17.5 10.1178 17.5C6.86118 17.5 4.07589 15.5379 2.94432 12.7632L2.41165 11.3235M2.41165 11.3235L1.5293 15.7353M2.41165 11.3235L6.38224 13.0882"></path></g></svg></button><button tabindex="0" type="button" class="pencraft pc-reset pencraft icon-container view-image"><svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="lucide lucide-maximize2 lucide-maximize-2"><polyline points="15 3 21 3 21 9"></polyline><polyline points="9 21 3 21 3 15"></polyline><line x1="21" x2="14" y1="3" y2="10"></line><line x1="3" x2="10" y1="21" y2="14"></line></svg></button></div></div></div></a></figure></div><p>Large language models (LLMs) like Llama2 have shown immense potential for generating human-like text. However, they still require task-specific fine-tuning to reach optimal performance. This process adjusts the model's weights to customise it with new data.</p><p>In this guide, we provide a practical guide to fine-tuning LLMs using techniques like LoRA and quantisation. We explain the key parameters involved and how they impact model size, speed, and accuracy. By the end, you'll have the knowledge to effectively fine-tune an LLM for your own applications.</p><h2><strong>Introduction</strong></h2><p>LLMs contain billions of parameters, enabling them to produce remarkably coherent text. However, their knowledge remains confined to their training data. Fine-tuning adapts these giant, pre-trained models to new domains where their capabilities can be specifically applied..</p><p>For instance, an LLM pre-trained on Wikipedia can summarise news articles after fine-tuning on media data. The technique adjusts the model's weights to reinforce patterns in the new data. This article details best practices to make your fine-tuning process efficient and effective.</p><h4><strong>We'll cover:</strong></h4><ul><li><p>LoRA and quantisation to optimise the process</p></li><li><p>How key parameters affect model performance and training stability</p></li><li><p>Strategies to avoid common pitfalls like overfitting</p></li><li><p>A step-by-step walkthrough from data preparation to inference</p></li></ul><p>By the end, you'll have an actionable approach to customise LLMs for your own tasks. Let's get started!</p><h4><strong>What is QLoRA?</strong></h4><p>Training an LLM from scratch requires prohibitively large amounts of data and computing resources, so fine-tuning offers a more practical alternative by slightly adapting a pre-trained model. However, even fine-tuning can strain resources on massive models. Methods like LoRA, which introduces low-rank matrices to selectively update parts of the pre-trained weights, and quantisation, which compresses the model by reducing parameters' precision through 4-bit quantisation, optimize fine-tuning to feasibly adjust LLMs using standard hardware. Together, LoRA and quantisation enable rapid adaptation of even trillion-parameter models on a single GPU by restricting the knowledge transferred and shrinking model size with minimal accuracy drop. With these efficient fine-tuning methods in place, properly tuning key hyper-parameters that control model size, memory use, and training stability becomes crucial for achieving good performance.</p><p>QLoRA is a method designed to refine large language models more efficiently. It optimises memory usage so that even substantial models can be adjusted using standard graphics hardware.</p><p>The method allows for rapid and efficient fine-tuning, achieving near top-tier performance levels with significantly reduced time and computational resources.</p><h4><strong>How It Works:</strong></h4><ul><li><p>QLoRA employs a 4-bit representation of the original model to conserve memory.</p></li><li><p>It introduces a new data format optimized for the kind of information it manages.</p></li><li><p>To further conserve memory, the method uses a technique termed "double quantization."</p></li><li><p>To handle unexpected surges in memory demands, it deploys a strategy known as "paged optimisers."</p></li></ul><p></p><div><hr></div><h2>Steps to Fine-Tune LLaMA2 using QLoRA:</h2><h4><strong>Set Up the Environment:</strong></h4><p>Ensure you're working in an environment with sufficient computational resources, such as Google Colab. Install necessary Python libraries: accelerate, peft, bitsandbytes, transformers, and trl.</p><h4><strong>Load the Datasets:</strong></h4><p>Prepare your training (train.jsonl) and evaluation datasets (test.jsonl). Each dataset should have entries with prompt and response keys.</p><h4><strong>Define Hyperparameters:</strong></h4><p>Set up model-specific parameters like model_name and new_model. Define training parameters such as learning_rate, weight_decay, and num_train_epochs.</p><h4><strong>Initialise the Model and Tokenizer:</strong></h4><p>Initialise the pre-trained model and tokenizer based on model_name.<br>Create a model with LoRA (Low-Rank Adaptation) layers for fine-tuning.</p><h4><strong>Start the Fine-Tuning Process:</strong></h4><p>Train the model using the defined hyperparameters and the training dataset.<br>Evaluate the model's performance on the evaluation dataset periodically.</p><h4><strong>Perform Inference:</strong></h4><p>Use the fine-tuned model to generate text or predictions based on provided prompts.</p><h4><strong>Save and Load the Model:</strong></h4><p>Once fine-tuning is complete, save the model weights. You can later load these weights to resume training or for inference.</p><p></p><pre><code>model_name = "meta-llama/Llama-2-7b-chat-hf"
dataset_name = "/content/train.jsonl"
new_model = "llama-2-7b-fine-tuned"
lora_r = 64
lora_alpha = 16
lora_dropout = 0.1
use_4bit = True
bnb_4bit_compute_dtype = "float16"
bnb_4bit_quant_type = "nf4"
use_nested_quant = False
output_dir = "./results"
num_train_epochs = 1
fp16 = False
bf16 = False
per_device_train_batch_size = 4
per_device_eval_batch_size = 4
gradient_accumulation_steps = 1
gradient_checkpointing = True
max_grad_norm = 0.3
learning_rate = 2e-4
weight_decay = 0.001
optim = "paged_adamw_32bit"
lr_scheduler_type = "constant"
max_steps = -1
warmup_ratio = 0.03
group_by_length = True
save_steps = 25
logging_steps = 25
max_seq_length = None
packing = False
device_map = {"": 0}</code></pre><h2>Fine-Tuning Parameters and Their Implications:</h2><h3><strong>LoRA Parameters:</strong></h3><p>Low-Rank Adaptation (LoRA) is a technique to fine-tune large pre-trained models without requiring a large amount of new data. It introduces low-rank layers to the model, which are trained while keeping the original pre-trained weights static.</p><p></p><h4><strong>lora_r (Rank of the low-rank approximation):</strong></h4><p>Effect: Determines the size of the low-rank matrix.</p><p><strong>Implications:</strong></p><ul><li><p>A higher value captures more information but increases computational demands and risk of overfitting with small datasets.</p></li><li><p>A lower value decreases computation but might not capture sufficient information for adaptation.</p></li></ul><p>Example: Adjust based on dataset size: smaller datasets might benefit from a lower value.</p><p>Possible values: Positive integers, typically ranging from 1 to 128.</p><p></p><h4><strong>lora_alpha (Scaling factor for initialisation):</strong></h4><p>Effect: Scales the initialised weights of the LoRA layers.</p><p><strong>Implications:</strong></p><ul><li><p>A higher value results in larger initial weights, potentially overshadowing the pre-trained weights.</p></li><li><p>A lower value offers a more subtle LoRA adaptation.</p></li></ul><p>Example: Adjust if the model isn't deviating enough from pre-trained behaviour.</p><p>Possible values: Positive floats, commonly between 0.1 and 10.</p><p></p><h4><strong>lora_dropout (Dropout applied to the LoRA weights):</strong></h4><p>Effect: Introduces dropout to the LoRA layers for regularisation.</p><p><strong>Implications:</strong></p><ul><li><p>A higher value can prevent overfitting but might also hinder learning.</p></li><li><p>A lower value reduces regularisation.</p></li></ul><p>Example: Increase if observing overfitting.</p><p>Possible values: Floats between 0 and 1 (e.g., 0.1, 0.2, 0.3).</p><p></p><div><hr></div><h3><strong>Quantisation Parameters:</strong></h3><p>Quantisation reduces the memory footprint of models, making them suitable for deployment on memory-limited devices.</p><p></p><h4><strong>use_4bit<br>(Whether to use 4-bit quantisation):</strong></h4><p>Effect: Adjusts the bit-width of the model weights.</p><p><strong>Implications:</strong></p><ul><li><p>Using 4-bit quantisation shrinks model size but may slightly degrade performance.</p></li></ul><p>Example: Enable for deployments on memory-limited edge devices.</p><p>Possible values: True or False.</p><p></p><h4><strong>bnb_4bit_compute_dtype<br>(Data type for 4-bit quantised computations):</strong></h4><p>Effect: Sets the computation data type.</p><p><strong>Implications:</strong></p><ul><li><p>"float16" enhances speed but may introduce minor numerical inaccuracies compared to "float32".</p></li></ul><p>Example: Opt for "float16" if speed is paramount and minor accuracy losses are acceptable.</p><p>Possible values: "float16" or "float32".</p><p></p><h4><strong>bnb_4bit_quant_type<br>(Quantisation type for 4-bit computations):</strong></h4><p>Effect: Specifies the quantisation strategy.</p><p><strong>Implications:</strong></p><ul><li><p>Different strategies can influence accuracy and computation speed variably.</p></li></ul><p>Example: The ideal setting may depend on data nature and task.</p><p>Possible values: Depends on the library. Here, "nf4" is used.</p><p></p><h4><strong>use_nested_quant<br>(Whether to use nested quantisation):</strong></h4><p>Effect: Enables another layer of quantisation.</p><p><strong>Implications:</strong></p><ul><li><p>Potentially further diminishes model size at the cost of performance.</p></li></ul><p>Example: Useful for extreme memory-constrained situations.</p><p>Possible values: True or False.</p><p></p><div><hr></div><h2>Training Hyperparameters:</h2><p></p><h4><strong>learning_rate:</strong></h4><p>Effect: Dictates the optimisation step size.</p><p><strong>Implications:</strong></p><ul><li><p>Too high values may cause loss oscillations or divergence.</p></li><li><p>Too low values lead to slow convergence or getting trapped in local minima.</p></li></ul><p>Example: Adjust based on training stability.</p><p>Possible values: Positive floats (e.g., 1e-3, 5e-4).</p><p></p><h4><strong>weight_decay (Regularisation term):</strong></h4><p>Effect: Penalises large weight values.</p><p><strong>Implications:</strong></p><ul><li><p>Higher values slow down learning but can prevent overfitting.</p></li><li><p>Lower values minimise regularisation.</p></li></ul><p>Example: Increase to combat overfitting.</p><p>Possible values: Non-negative floats (e.g., 0, 0.0001).</p><p></p><h4><strong>num_train_epochs:</strong></h4><p>Effect: Determines how many times the model reviews the entire training dataset.</p><p><strong>Implications:</strong></p><ul><li><p>More epochs might improve performance but risk overfitting.</p></li><li><p>Fewer epochs might result in underfitting.</p></li></ul><p>Example: Adjust based on convergence observations.</p><p>Possible values: Positive integers, typically between 1 and several hundred.</p><p></p><h4><strong>gradient_accumulation_steps:</strong></h4><p>Effect: Delays updates by accumulating gradients over multiple steps.</p><p><strong>Implications:</strong></p><ul><li><p>Useful for circumventing memory constraints, effectively simulating a larger batch size without memory overflow.</p></li></ul><p>Example: Increase when confronting out-of-memory errors without wanting to decrease batch size.</p><p>Possible values: Positive integers like 1, 2, 4.</p><p></p><div><hr></div><p>To try out this concept for yourself please check out this fantastic Google Colab Notebook from <a href="https://twitter.com/mattshumer_">Matt Shumer</a> which also credits work from <a href="https://twitter.com/maximelabonne">Maxime Labonne</a>. <a href="https://colab.research.google.com/drive/1Zmaceu65d7w4Tcd-cfnZRb6k_Tcv2b8g?usp=sharing">https://colab.research.google.com/drive/1Zmaceu65d7w4Tcd-cfnZRb6k_Tcv2b8g?usp=sharing</a></p><div><hr></div><h2>Glossary:</h2><h4><strong>Low-Rank Adaptation (LoRA):</strong></h4><p>A method to tweak large models with small amounts of new data. Think of it as adding a few new components to an existing machine to adjust its functionality, without altering the original parts.</p><h4><strong>Quantisation:</strong></h4><p>A technique to make a model smaller and faster by simplifying it, though this might slightly reduce its accuracy. It's similar to compressing a photo to save space, causing it to become a tad blurry.</p><h4><strong>Dropout:</strong></h4><p>A strategy to strengthen the model by randomly disabling some of its parts during training. Picture a sports team practising with some players occasionally sitting out, ensuring the team doesn't become overly dependent on any single player.</p><h4><strong>Overfitting:</strong></h4><p>Occurs when a model excels with familiar data but struggles with new, unseen data. It's akin to a student who memorises test answers but has difficulty applying the knowledge in real-world scenarios.</p><h4><strong>Gradient:</strong></h4><p>A metric that informs the model about the discrepancy between its predictions and the actual answers, guiding its improvements.</p><h4><strong>Backpropagation:</strong></h4><p>A process where the model reflects on its mistakes and tweaks itself. Imagine playing a game, learning from errors, and improving for the next round.</p><h4><strong>Exploding Gradients:</strong></h4><p>An issue where the model's corrections become excessively large, leading to unstable training. Picture trying to fine-tune a radio but adjusting the dial too drastically, causing signal disruption.</p><h4><strong>Gradient Clipping:</strong></h4><p>A method to restrict the corrections from becoming too extensive. It's like setting a limit on how much you can adjust a radio dial to maintain a clear signal.</p><h4><strong>Gradient Accumulation Steps:</strong></h4><p>An approach to manage vast data by segmenting it and updating the model incrementally. Think of consuming a large meal in several smaller portions.</p><h4><strong>Gradient Checkpointing:</strong></h4><p>A technique to conserve memory during training by recording only select vital information. Consider it similar to jotting down key points during a lecture, rather than transcribing every word.</p><div class="subscription-widget-wrap-editor" data-attrs="{&quot;url&quot;:&quot;https://blog.mlops.consulting/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe&quot;,&quot;language&quot;:&quot;en&quot;}" data-component-name="SubscribeWidgetToDOM"><div class="subscription-widget show-subscribe"><div class="preamble"><p class="cta-caption">Thanks for reading Adam&#8217;s Substack! Subscribe for free to receive new posts and support my work.</p></div><form class="subscription-widget-subscribe"><input type="email" class="email-input" name="email" placeholder="Type your email&#8230;" tabindex="-1"><input type="submit" class="button primary" value="Subscribe"><div class="fake-input-wrapper"><div class="fake-input"></div><div class="fake-button"></div></div></form></div></div>]]></content:encoded></item><item><title><![CDATA[Coming soon]]></title><description><![CDATA[This is MLOps Consulting.]]></description><link>https://blog.mlops.consulting/p/coming-soon</link><guid isPermaLink="false">https://blog.mlops.consulting/p/coming-soon</guid><dc:creator><![CDATA[Adam Knight]]></dc:creator><pubDate>Fri, 18 Aug 2023 06:52:49 GMT</pubDate><enclosure url="https://substackcdn.com/image/fetch/$s_!8QtU!,w_256,c_limit,f_auto,q_auto:good,fl_progressive:steep/https%3A%2F%2Fsubstack-post-media.s3.amazonaws.com%2Fpublic%2Fimages%2Fcedba0c7-e317-4d2d-9be7-5415e7c04143_620x620.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>This is MLOps Consulting.</p><p class="button-wrapper" data-attrs="{&quot;url&quot;:&quot;https://blog.mlops.consulting/subscribe?&quot;,&quot;text&quot;:&quot;Subscribe now&quot;,&quot;action&quot;:null,&quot;class&quot;:null}" data-component-name="ButtonCreateButton"><a class="button primary" href="https://blog.mlops.consulting/subscribe?"><span>Subscribe now</span></a></p>]]></content:encoded></item></channel></rss>