<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: finetuning</title>
    <description>The latest articles tagged 'finetuning' on DEV Community.</description>
    <link>https://dev.to/t/finetuning</link>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tag/finetuning"/>
    <language>en</language>
    <item>
      <title>Apex: perché un modello specializzato può battere i “frontier” su React Native</title>
      <dc:creator>frontendfacile.it</dc:creator>
      <pubDate>Fri, 14 Aug 2026 07:25:37 +0000</pubDate>
      <link>https://dev.to/frontendfacile/apex-perche-un-modello-specializzato-puo-battere-i-frontier-su-react-native-880</link>
      <guid>https://dev.to/frontendfacile/apex-perche-un-modello-specializzato-puo-battere-i-frontier-su-react-native-880</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;Costi, contesto, freschezza del know‑how e controllo operativo: i motivi pratici per cui la specializzazione conta davvero&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Negli ultimi mesi è diventato quasi un riflesso automatico: per qualsiasi problema di coding si punta al modello più grande disponibile, dando per scontato che “più intelligente” significhi sempre “più utile”. Su React Native (e più in generale su stack moderni che cambiano velocemente), questa equazione spesso non regge.&lt;/p&gt;

&lt;p&gt;Un modello specializzato — addestrato e ottimizzato per un dominio specifico come React Native — può risultare &lt;strong&gt;più efficace&lt;/strong&gt; di un modello generalista di frontiera in una sorprendente quantità di casi d’uso quotidiani: dalla scrittura di componenti e hook, alla diagnostica di bug, fino alla navigazione di API e pattern che evolvono di release in release.&lt;/p&gt;

&lt;h2&gt;
  
  
  Non ti serve una Lamborghini per andare a fare la spesa
&lt;/h2&gt;

&lt;p&gt;I modelli “frontier” sono impressionanti. Ma l’errore tipico è usarli come strumento universale anche quando il task è:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;ripetitivo (pattern noti e ricorrenti)&lt;/li&gt;
&lt;li&gt;vincolato a un framework (React Native, Metro, Hermes, JSI, TurboModules…)&lt;/li&gt;
&lt;li&gt;legato a best practice precise (performance, rendering, bridging)&lt;/li&gt;
&lt;li&gt;dipendente da versioni specifiche di librerie&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In questi scenari, il valore non è “ragionare su tutto l’universo”, ma &lt;strong&gt;produrre output affidabile e contestuale&lt;/strong&gt; sul tuo dominio. Un modello specializzato riduce sprechi: meno complessità, meno costo operativo, meno latenza decisionale e spesso meno allucinazioni &lt;em&gt;di contesto&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Il problema vero: il contesto è una risorsa scarsa
&lt;/h2&gt;

&lt;p&gt;C’è un punto che molti sottovalutano: la &lt;em&gt;context window&lt;/em&gt; non è un dettaglio tecnico, è un vincolo di prodotto.&lt;/p&gt;

&lt;p&gt;Un modello generalista ha conoscenze ampie e tende a “caricare in testa” tante associazioni e percorsi possibili. Quando lavori su una richiesta concreta di React Native, spesso devi comunque fornirgli:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;struttura del progetto&lt;/li&gt;
&lt;li&gt;versione di RN e delle librerie&lt;/li&gt;
&lt;li&gt;estratti di codice e log&lt;/li&gt;
&lt;li&gt;configurazioni Metro/Babel&lt;/li&gt;
&lt;li&gt;dettagli di piattaforma (iOS/Android)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Risultato: &lt;strong&gt;il contesto si riempie in fretta&lt;/strong&gt;, e la parte utile (lo spazio per ragionamento e soluzione) si riduce.&lt;/p&gt;

&lt;p&gt;Un modello specializzato, invece, parte con una base “già orientata”: gli servono meno spiegazioni per arrivare al punto, e quindi:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;richiede meno prompt “di contorno”&lt;/li&gt;
&lt;li&gt;usa meglio il contesto disponibile&lt;/li&gt;
&lt;li&gt;tende a mantenere la rotta sul framework&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In pratica: può sembrare “più piccolo”, ma per React Native è &lt;strong&gt;più denso di informazione pertinente&lt;/strong&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Freschezza del know‑how: la specializzazione si aggiorna più in fretta
&lt;/h2&gt;

&lt;p&gt;React Native è un bersaglio mobile: nuove architetture, cambiamenti nelle API, librerie che deprecano funzioni o riscrivono interfacce (navigation, gesture, reanimated, ecc.).&lt;/p&gt;

&lt;p&gt;Un modello generalista, per quanto avanzato, può rimanere &lt;strong&gt;indietro&lt;/strong&gt; rispetto all’ecosistema: anche pochi mesi di scarto bastano per generare suggerimenti che mescolano:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;API vecchie e nuove&lt;/li&gt;
&lt;li&gt;pattern deprecati&lt;/li&gt;
&lt;li&gt;workaround non più necessari&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La differenza pratica è questa: &lt;strong&gt;un modello di dimensioni medie è più semplice da “rinfrescare”&lt;/strong&gt; (fine‑tuning, aggiornamento del corpus, retraining mirato). È un tema di costi e tempi computazionali: aggiornare un colosso richiede più risorse, più pipeline, più validazione.&lt;/p&gt;

&lt;p&gt;Per un team che vive in React Native tutti i giorni, la capacità di allineare rapidamente il modello alle versioni correnti non è un nice‑to‑have: è ciò che decide se l’output è utile o ti fa perdere tempo.&lt;/p&gt;

&lt;h2&gt;
  
  
  Controllo operativo: hosting e governance (non solo costi)
&lt;/h2&gt;

&lt;p&gt;Il discorso non riguarda solo il prezzo per token. Con modelli specializzati e più piccoli entrano in gioco vantaggi di controllo che diventano importanti soprattutto in contesti aziendali:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;possibilità di hosting più controllabile (anche on‑premise o in ambienti dedicati)&lt;/li&gt;
&lt;li&gt;maggiore prevedibilità di performance&lt;/li&gt;
&lt;li&gt;pipeline di valutazione interna più semplice&lt;/li&gt;
&lt;li&gt;policy su dati e codice più gestibili&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Non sempre puoi (o vuoi) mandare porzioni significative di codice e log in giro senza sapere esattamente come vengono trattati. Avere un modello più “gestibile” spesso è un requisito, non un capriccio.&lt;/p&gt;

&lt;h2&gt;
  
  
  Il tallone d’Achille dei modelli generalisti: la sicurezza con cui sbagliano
&lt;/h2&gt;

&lt;p&gt;Quando un modello non sa qualcosa, non è detto che lo ammetta. Anzi: spesso produce una risposta plausibile con tono molto sicuro.&lt;/p&gt;

&lt;p&gt;Su stack moderni questo è pericoloso perché l’errore non è grossolano: è &lt;em&gt;quasi giusto&lt;/em&gt;. Magari compila, magari sembra idiomatico, ma usa:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;un’opzione di config non più valida&lt;/li&gt;
&lt;li&gt;una firma di funzione cambiata&lt;/li&gt;
&lt;li&gt;un pattern che oggi degrada le performance&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La specializzazione non elimina il problema, ma lo può &lt;strong&gt;ridurre&lt;/strong&gt;: se il modello è addestrato e valutato esplicitamente sul dominio, è più facile insegnargli quando deve essere cauto e quando invece può andare spedito.&lt;/p&gt;

&lt;h2&gt;
  
  
  Quando un modello specializzato vince davvero (use case concreti)
&lt;/h2&gt;

&lt;p&gt;Su React Native, un modello specializzato tende a brillare in attività come:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;generare componenti e hook idiomatici e consistenti con le best practice&lt;/li&gt;
&lt;li&gt;suggerire ottimizzazioni (rendering, memoization, FlatList, immagini)&lt;/li&gt;
&lt;li&gt;interpretare log tipici RN (Metro, bundling, Hermes, native crash)&lt;/li&gt;
&lt;li&gt;proporre fix coerenti con la nuova architettura (JSI/TurboModules) quando richiesto&lt;/li&gt;
&lt;li&gt;mantenere coerenza tra iOS/Android senza “inventarsi” API native&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In altre parole: nel lavoro quotidiano “da app”, non nel puzzle da leetcode.&lt;/p&gt;

&lt;h2&gt;
  
  
  Trade‑off: non è magia, è specializzazione
&lt;/h2&gt;

&lt;p&gt;Un modello specializzato non è automaticamente migliore in assoluto:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;può essere meno brillante su problemi generali o su domini lontani&lt;/li&gt;
&lt;li&gt;può richiedere una manutenzione attiva del corpus e dei benchmark&lt;/li&gt;
&lt;li&gt;può essere meno flessibile se il tuo progetto è molto eterogeneo&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Il punto è usarlo nel suo perimetro naturale: &lt;strong&gt;React Native come dominio primario&lt;/strong&gt;, e modelli generalisti come supporto quando la richiesta esce dal seminato.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sintesi: più utile batte più grande
&lt;/h2&gt;

&lt;p&gt;Nel frontend moderno, “il modello migliore” non è quello più grande, ma quello che ti fa:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;strong&gt;sprecare meno contesto&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;sbattere meno contro API vecchie&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;ottenere risposte più aderenti al dominio&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;mantenere controllo su aggiornamenti e governance&lt;/strong&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Se lavori seriamente con React Native, la strada pragmatica è questa: trattare l’AI come un toolchain, non come un oracolo. E nella toolchain, gli strumenti specializzati — quando sono ben addestrati e mantenuti — vincono spesso per produttività reale, non per spettacolo.&lt;/p&gt;




&lt;p&gt;Articolo originale: &lt;a href="https://frontendfacile.it/blog/apex-perche-un-modello-specializzato-puo-battere-i-frontier-su-react-native" rel="noopener noreferrer"&gt;https://frontendfacile.it/blog/apex-perche-un-modello-specializzato-puo-battere-i-frontier-su-react-native&lt;/a&gt;&lt;/p&gt;

</description>
      <category>reactnative</category>
      <category>modellispecializzati</category>
      <category>contextwindow</category>
      <category>finetuning</category>
    </item>
    <item>
      <title>Soup CLI Lets You Fine-Tune an 8B LLM on a 4 GB Laptop GPU</title>
      <dc:creator>Hamza</dc:creator>
      <pubDate>Mon, 10 Aug 2026 05:38:16 +0000</pubDate>
      <link>https://dev.to/tekmag/soup-cli-lets-you-fine-tune-an-8b-llm-on-a-4-gb-laptop-gpu-3f3d</link>
      <guid>https://dev.to/tekmag/soup-cli-lets-you-fine-tune-an-8b-llm-on-a-4-gb-laptop-gpu-3f3d</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffvaudwdp5ig9ex7k72wf.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Ffvaudwdp5ig9ex7k72wf.png" alt="Soup CLI layer streaming fine-tuning on a &lt;a href=" width="800" height="800"&gt;&lt;/a&gt;Laptop GPU" style="width:100%;height:auto;" /&amp;gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Soup CLI, an open-source Python tool licensed under Apache-2.0, lets you fine-tune an 8B-parameter&lt;a href="https://dev.to/deepseek-dspark-the-open-source-framework-making-ai-inference-85-faster-2026/"&gt;LLM&lt;/a&gt; on a 4 GB laptop GPU using a technique called layer streaming. The frozen base model stays in system RAM while decoder layers stream into GPU memory one at a time, achieving 119.6 tokens per second on an RTX 3050 Laptop with 3.32 GB peak VRAM usage.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Layer streaming was introduced as a practical solution to the memory bottleneck that has long prevented researchers and developers from fine-tuning large language models on consumer hardware. Soup CLI, available on GitHub at &lt;a href="https://github.com/MakazhanAlpamys/Soup" rel="noopener noreferrer"&gt;github.com/MakazhanAlpamys/Soup&lt;/a&gt;, implements this approach with a focus on correctness, enabling users to run preference training algorithms like DPO, ORPO, SimPO, and KTO without loading the entire model into GPU memory.&lt;/p&gt;

&lt;p&gt;The tool uses NF4 (four-bit normalfloat) &lt;a href="https://dev.to/deepseek-dspark-the-open-source-framework-making-ai-inference-85-faster-2026/"&gt;quantization&lt;/a&gt; to reduce model size while preserving accuracy. In benchmarks, Llama-3.1-8B-Instruct with NF4 quantization achieved 119.6 tok/s on an RTX 3050 Laptop 4 GB, peaking at just 3.32 GB of VRAM. The same configuration on an 8xH100 cluster reproduced the 3.32 GB peak at a median 113.00 tok/s, and the streamed run produced bit-exact results compared to a resident (fully loaded) run.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key Takeaways
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Soup CLI is an open-source CLI for LLM fine-tuning and post-training, licensed Apache-2.0&lt;/li&gt;
&lt;li&gt;Layer streaming keeps the frozen base model in system RAM, streaming decoder layers into GPU one at a time&lt;/li&gt;
&lt;li&gt;Llama-3.1-8B-Instruct + NF4 on RTX 3050 Laptop 4 GB: 119.6 tok/s, 3.32 GB peak VRAM&lt;/li&gt;
&lt;li&gt;8xH100 reproduction: 113.00 tok/s median, same 3.32 GB peak, bit-exact vs resident run&lt;/li&gt;
&lt;li&gt;v0.73.0 (Aug 5-9, 2026) fixed a silent wrong-gradient bug on NF4 layers above ~165 MiB&lt;/li&gt;
&lt;li&gt;Preference training (DPO/ORPO/SimPO/KTO) supported at 0.914x SFT peak, avoiding +730 MB overhead&lt;/li&gt;
&lt;li&gt;Install: pip install "soup-cli[train]" and run soup train with a soup.yaml config&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  How Layer Streaming Works
&lt;/h2&gt;

&lt;p&gt;Traditional fine-tuning loads the entire model into GPU memory, which for an 8B model in standard precision requires roughly 16 GB of VRAM. Soup CLI takes a different approach. The base model remains frozen in system RAM, and only one decoder layer at a time streams into the GPU during forward and backward passes. This means a 4 GB laptop GPU can handle models that would normally require 24 GB or more.&lt;/p&gt;

&lt;p&gt;The technique relies on careful memory management. As each layer processes, its activations and gradients are computed, and then the layer is swapped back to RAM before the next one loads. The system tracks memory usage precisely, ensuring the peak VRAM stays well within the GPU's capacity. For Llama-3.1-8B-Instruct with NF4 quantization, the peak sits at 3.32 GB on a 4 GB card, leaving headroom for training overhead.&lt;/p&gt;

&lt;p&gt;Correctness is maintained through a verification protocol. Every release of Soup CLI compares the streamed run against a resident run and requires exact logits match. This means the output of the streaming approach is identical to loading the full model, just with a different memory access pattern.&lt;/p&gt;

&lt;h2&gt;
  
  
  Benchmark Results and Performance
&lt;/h2&gt;

&lt;p&gt;The benchmark results demonstrate that layer streaming does not come with a steep performance penalty. On an RTX 3050 Laptop GPU with 4 GB of VRAM, Llama-3.1-8B-Instruct quantized to NF4 achieved 119.6 tokens per second. The same configuration on an 8xH100 cluster produced a median of 113.00 tok/s at the same 3.32 GB peak VRAM.&lt;/p&gt;

&lt;p&gt;The bit-exact comparison is the critical detail. Streaming is not an approximation method. The logits produced by the streamed run match the resident run exactly, which means fine-tuning results are reproducible regardless of whether you use a laptop GPU or a datacenter cluster.&lt;/p&gt;

&lt;p&gt;Preference training algorithms like DPO, ORPO, SimPO, and KTO are supported with the streamed base and adapters turned off. Benchmarks show these run at 0.914x the peak SFT speed while avoiding the +730 MB overhead that would come from loading a second model instance.&lt;/p&gt;

&lt;h2&gt;
  
  
  v0.73.0: Fixing Silent Wrong Gradients
&lt;/h2&gt;

&lt;p&gt;Version 0.73.0, validated between &lt;a href="https://tekmag.thsite.top/openai-shuts-down-messengergpt-atlas-on-august-9/" rel="noopener noreferrer"&gt;August&lt;/a&gt; 5 and 9, 2026 on a borrowed H100 cluster, addressed a silent wrong-gradient bug that affected NF4 models with layers above approximately 165 MiB per layer. This was a correctness issue where the streamed run produced gradients that did not match the resident run, potentially corrupting fine-tuning without any visible error.&lt;/p&gt;

&lt;p&gt;The validation caught the bug through the standard correctness protocol. Every release includes a comparison between streamed and resident runs, requiring exact logits match. When the bug was found, the four backends that previously failed to run at all were also fixed. Additional improvements in v0.73.0 include vLLM now using the model's chat template, support for training.seed, and the ability to run full fine-tuning by setting lora.r to 0.&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation and Usage
&lt;/h2&gt;

&lt;p&gt;Soup CLI installs via pip with the training extras:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pip install "soup-cli[train]"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The workflow is straightforward. Create a soup.yaml configuration file that specifies your model, dataset, and training parameters, then run the training command:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;soup train
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;The configuration supports multiple backends and training modes. The project is licensed under Apache-2.0, with the source code hosted at &lt;a href="https://github.com/MakazhanAlpamys/Soup" rel="noopener noreferrer"&gt;github.com/MakazhanAlpamys/Soup&lt;/a&gt; and documentation at &lt;a href="https://trysoup.dev/" rel="noopener noreferrer"&gt;trysoup.dev&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Who This Is For
&lt;/h2&gt;

&lt;p&gt;Soup CLI targets developers and researchers who want to fine-tune large models but do not have access to multi-GPU setups or cloud compute. The layer streaming approach makes it possible to run experiments on consumer hardware, which reduces cost and increases iteration speed for prototyping.&lt;/p&gt;

&lt;p&gt;The preference training support is particularly useful for alignment work. DPO, ORPO, SimPO, and KTO are the standard algorithms for shaping model behavior, and having them run efficiently on a 4 GB GPU removes a common bottleneck.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Soup CLI demonstrates that layer streaming is production-ready for fine-tuning workflows. The v0.73.0 fix for silent wrong gradients is a sign of a project that takes correctness seriously, and the benchmark results show that performance remains strong even on modest hardware. For teams working with 8B-class models on laptop GPUs, it provides a path to fine-tuning that was previously only available on datacenter equipment.&lt;/p&gt;

&lt;h3&gt;
  
  
  Frequently Asked Questions
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Q: What is layer streaming?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A: Layer streaming is a memory optimization technique where the frozen base model stays in system RAM and decoder layers are streamed into GPU memory one at a time during forward and backward passes. This allows fine-tuning models much larger than the GPU's VRAM capacity.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: Does Soup CLI lose accuracy compared to full GPU loading?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A: No. Soup CLI requires exact logits match between streamed and resident runs for every release. The v0.73.0 validation confirmed bit-exact results against the full-model baseline.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: What hardware do I need to run Soup CLI?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A: A GPU with at least 4 GB of VRAM is sufficient for 8B models with NF4 quantization. The benchmarks tested on an RTX 3050 Laptop 4 GB and achieved 119.6 tok/s.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: Can I use Soup CLI for preference training?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A: Yes. Soup CLI supports DPO, ORPO, SimPO, and KTO with the streamed base. These run at 0.914x SFT peak speed while avoiding the +730 MB overhead of a second model instance.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Q: How do I install Soup CLI?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A: Run pip install "soup-cli[train]", create a soup.yaml configuration file, and start training with soup train. The project is Apache-2.0 licensed.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;GitHub repository: &lt;a href="https://github.com/MakazhanAlpamys/Soup" rel="noopener noreferrer"&gt;github.com/MakazhanAlpamys/Soup&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://www.producthunt.com" rel="noopener noreferrer"&gt;Product Hunt&lt;/a&gt; launch page: &lt;a href="https://www.producthunt.com/products/soup-cli" rel="noopener noreferrer"&gt;producthunt.com/products/soup-cli&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Project website: &lt;a href="https://trysoup.dev/" rel="noopener noreferrer"&gt;trysoup.dev&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;PyPI package: &lt;a href="https://pypi.org/project/soup-cli/" rel="noopener noreferrer"&gt;pypi.org/project/soup-cli&lt;/a&gt;
&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>soup</category>
      <category>llm</category>
      <category>finetuning</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Context window sizing for fine-tuning: how long should your training examples be?</title>
      <dc:creator>Walker Miller</dc:creator>
      <pubDate>Sat, 08 Aug 2026 05:36:04 +0000</pubDate>
      <link>https://dev.to/loopandretry/context-window-sizing-for-fine-tuning-how-long-should-your-training-examples-be-3ga8</link>
      <guid>https://dev.to/loopandretry/context-window-sizing-for-fine-tuning-how-long-should-your-training-examples-be-3ga8</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://loopandretry.github.io/posts/context-sizing-for-fine-tuning/?ref=devto" rel="noopener noreferrer"&gt;Loop &amp;amp; Retry&lt;/a&gt; — field notes on building LLM agents that survive production.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Most fine-tuning guides answer "how many examples" and skip "how long should each one be." That second question is the one that quietly decides whether your fine-tune helps at inference or fights it. Example length isn't a property you inherit from your data — it's a design choice, and the default (whatever length your dumped transcripts happen to be) is usually wrong in one of two expensive directions.&lt;/p&gt;

&lt;p&gt;The framing I keep coming back to: &lt;a href="https://loopandretry.github.io/posts/context-window-is-a-cache/?ref=devto" rel="noopener noreferrer"&gt;the context window is a cache, not a memory&lt;/a&gt;. Fine-tuning changes &lt;em&gt;what the weights know&lt;/em&gt;; it does not change the fact that at inference the model reasons over whatever you put in the window right now. Size your training examples to the window you'll actually serve, or you're training for a world you won't deploy into.&lt;/p&gt;

&lt;h2&gt;
  
  
  The two failure directions
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Too short&lt;/strong&gt; is the sneakier one. Say your real requests arrive with 6–8K tokens of retrieved context, but your training examples are tidy 800-token snippets because that's what your labeling tool exported. You've now fine-tuned a model whose learned prior is "the answer is near the top of a short prompt." At inference you hand it 8K tokens and the relevant fact sits at position 5,000, and the model underweights it — not because the base model can't attend that far, but because &lt;em&gt;your&lt;/em&gt; fine-tune taught a length distribution that never occurs in production. You optimized the model onto a distribution you will never sample from.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Too long&lt;/strong&gt; is the one that shows up on the invoice. Attention is quadratic in sequence length, so a training set of 32K-token examples doesn't cost 4× a set of 8K-token examples — it costs closer to 16× per step in the attention term, plus the memory that forces you into smaller batches or gradient checkpointing, which slows you down again. Worse, long examples tempt you into teaching the model to &lt;em&gt;memorize&lt;/em&gt; reference material that belongs in retrieval. You pay quadratic training cost to bake facts into weights that a RAG lookup would have served fresh, and now those facts are frozen at training time and go stale.&lt;/p&gt;

&lt;h2&gt;
  
  
  Match the training distribution to the serving distribution
&lt;/h2&gt;

&lt;p&gt;The rule is boring and load-bearing: &lt;strong&gt;the length distribution of your training examples should match the length distribution of your production requests.&lt;/strong&gt; Not the max, the &lt;em&gt;distribution&lt;/em&gt;. If prod requests are lognormal with a median of 4K and a p95 of 12K, your training data should look like that too — a spread, not a single padded length.&lt;/p&gt;

&lt;p&gt;This is where the cache framing matters. If you're managing the context window as &lt;a href="https://loopandretry.github.io/posts/context-window-is-a-cache/?ref=devto" rel="noopener noreferrer"&gt;a cache with an eviction policy&lt;/a&gt;, the length distribution of the &lt;em&gt;serving&lt;/em&gt; examples includes the effects of your eviction decisions — summaries, truncations, reorderings. Training on full, un-truncated examples teaches the model a distribution that doesn't exist at inference.&lt;/p&gt;

&lt;p&gt;Measure it before you build the set:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;numpy&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;

&lt;span class="c1"&gt;# token counts of real production prompts (sample from logs)
&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;array&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="nf"&gt;count_tokens&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;p&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;p&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;sampled_prod_prompts&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;

&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;50&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;90&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;95&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;p&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;percentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;q&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;6.0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; tokens&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="nf"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;max sequence to train on: ~p99 = &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;np&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;percentile&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;lengths&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;99&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;:&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="n"&gt;f&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set your training &lt;code&gt;max_seq_len&lt;/code&gt; at roughly the &lt;strong&gt;p99 of production&lt;/strong&gt;, not the max. The single 60K-token outlier request shouldn't force every batch to reserve 60K of sequence budget; truncate or drop the long tail and handle it separately. And critically: &lt;strong&gt;don't pad-and-collapse your examples to one length.&lt;/strong&gt; Bucket by length so a batch of short examples trains cheaply and only the genuinely long batches pay the quadratic cost. Length bucketing is the single highest-leverage efficiency lever in fine-tuning and it's routinely skipped.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where the labels sit changes the sizing
&lt;/h2&gt;

&lt;p&gt;There's a second-order effect people miss. If your examples are long &lt;em&gt;and the label (the tokens you compute loss on) is short and at the end&lt;/em&gt; — a classic "long context in, short answer out" shape — then most of the sequence is loss-masked context the model reads but isn't scored on. That's fine functionally, but it means your effective training signal per token is low: you're paying to process 12K tokens to get gradient from 200. &lt;/p&gt;

&lt;p&gt;Two consequences. First, you may need more examples than a short-answer intuition suggests, because each one carries little supervised signal relative to its cost. Second, this is often the signal that you should be &lt;em&gt;retrieving&lt;/em&gt; that context at inference rather than teaching the model to condition on a specific long document — if the long part is reference material rather than the reasoning you want to instill, it belongs in the &lt;a href="https://loopandretry.github.io/posts/context-window-is-a-cache/?ref=devto" rel="noopener noreferrer"&gt;cache, not the memory&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Don't fine-tune the summarizer's mistakes in
&lt;/h2&gt;

&lt;p&gt;If your production pipeline &lt;a href="https://loopandretry.github.io/posts/compaction-is-a-lossy-operation/?ref=devto" rel="noopener noreferrer"&gt;compacts context&lt;/a&gt; — summarizing earlier turns to fit the window — then your &lt;em&gt;serving&lt;/em&gt; distribution includes compacted, lossy context. Your training examples had better include it too. Compaction is &lt;a href="https://loopandretry.github.io/posts/compaction-is-a-lossy-operation/?ref=devto" rel="noopener noreferrer"&gt;a lossy operation&lt;/a&gt;: it deliberately drops detail to make room, and that loss changes the information the model sees. Fine-tuning exclusively on full, un-compacted transcripts and then serving compacted ones at inference is another train/serve mismatch: you taught the model to rely on detail that your own pipeline strips before the model ever sees it in production. If you compact at inference, compact (a sample of) your training examples the same way, so the model learns to reason over the degraded input it will actually get.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I'd actually do
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Sample real prod prompts and plot the length distribution first.&lt;/strong&gt; Everything downstream keys off p50/p95/p99. Guessing here is guessing at the whole design.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Set `max_seq_len ≈ p99 of production&lt;/strong&gt;, and length-bucket batches.** Don't let the tail dictate the batch, and don't pay quadratic cost on short examples by padding them long.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Match the shape, not just the cap.&lt;/strong&gt; A spread of lengths that mirrors production beats one padded length, even if the padded length is "safe."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ask whether the long part is reasoning or reference.&lt;/strong&gt; Reasoning you want in the weights; reference you want in retrieval. Fine-tuning reference material is paying quadratic cost to freeze facts that go stale.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;If you compact at inference, compact your training data too.&lt;/strong&gt; Train on the distribution you serve, degradations included.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Example length is a lever, and it's one of the few in fine-tuning where the wrong default costs you on both axes at once — quality &lt;em&gt;and&lt;/em&gt; dollars. Measure the serving distribution, then build training examples that look like it. The model can only learn the world you show it, and the window is that world.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Quadratic-in-sequence-length is the standard dense-attention cost model; architectures with sparse or linear attention change the constant but not the direction of the argument. Percentile targets and bucket boundaries are workload-specific — the method (match training length distribution to serving length distribution) is what transfers.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>finetuning</category>
      <category>contextengineering</category>
      <category>training</category>
      <category>cost</category>
    </item>
    <item>
      <title>Best GPU for AI Training at Home in 2026 (Ranked)</title>
      <dc:creator>Thurmon Demich</dc:creator>
      <pubDate>Sat, 08 Aug 2026 01:13:24 +0000</pubDate>
      <link>https://dev.to/thurmon_demich/best-gpu-for-ai-training-at-home-in-2026-ranked-1jn7</link>
      <guid>https://dev.to/thurmon_demich/best-gpu-for-ai-training-at-home-in-2026-ranked-1jn7</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;From the &lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;Best GPU for AI&lt;/a&gt; archive. The canonical version has interactive calculators, an up-to-date GPU comparison table, and live pricing.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Training AI at home sounds intimidating, but most practical home workflows are actually fine-tuning rather than training from scratch. LoRA and QLoRA have made it possible to customize foundation models on a single consumer GPU. The question is which GPU fits your use case — and your power bill.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Quick answer:&lt;/strong&gt; The RTX 4090 (24GB) is the best GPU for AI training at home. It runs LoRA and QLoRA fine-tuning on 7B-13B models comfortably, handles full fine-tuning on smaller models, and has enough VRAM headroom for experimenting. For tighter budgets, the RTX 4060 Ti 16GB is a capable LoRA training card.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;See the recommended pick on the original guide&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Training vs fine-tuning: what are you actually doing?
&lt;/h2&gt;

&lt;p&gt;Most people who say they want to "train AI at home" mean one of these:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full training from scratch&lt;/strong&gt; — building a model from random weights on your own dataset. This requires massive compute and is not realistic on consumer hardware for anything beyond toy models.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Full fine-tuning&lt;/strong&gt; — updating all weights of an existing pretrained model. Requires roughly 2x the model's VRAM in float16. A 7B model needs ~14GB minimum. Possible on 24GB cards, impractical on 16GB.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LoRA fine-tuning&lt;/strong&gt; — training low-rank adapter layers that attach to a frozen model. Memory-efficient, trains only a small fraction of parameters. A 7B model LoRA trains comfortably on 12-16GB VRAM.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;QLoRA fine-tuning&lt;/strong&gt; — LoRA on a 4-bit quantized model. Enables fine-tuning of 13B-34B models on a single 24GB card. This is the practical sweet spot for home training.&lt;/p&gt;

&lt;p&gt;For the full fine-tuning guide, see &lt;a href="https://dev.to/articles/best-gpu-for-fine-tuning/"&gt;best GPU for fine-tuning&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  VRAM requirements for home training
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Task&lt;/th&gt;
&lt;th&gt;Minimum VRAM&lt;/th&gt;
&lt;th&gt;Recommended&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SD LoRA (Kohya, Dreambooth)&lt;/td&gt;
&lt;td&gt;8GB&lt;/td&gt;
&lt;td&gt;12GB+&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7B LLM LoRA (float16)&lt;/td&gt;
&lt;td&gt;12GB&lt;/td&gt;
&lt;td&gt;16GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7B LLM QLoRA (4-bit)&lt;/td&gt;
&lt;td&gt;8GB&lt;/td&gt;
&lt;td&gt;12GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13B LLM LoRA&lt;/td&gt;
&lt;td&gt;24GB&lt;/td&gt;
&lt;td&gt;32GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;13B LLM QLoRA (4-bit)&lt;/td&gt;
&lt;td&gt;12GB&lt;/td&gt;
&lt;td&gt;16GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;34B LLM QLoRA (4-bit)&lt;/td&gt;
&lt;td&gt;20GB&lt;/td&gt;
&lt;td&gt;24GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full fine-tune 7B&lt;/td&gt;
&lt;td&gt;16GB&lt;/td&gt;
&lt;td&gt;24GB&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;VRAM chart available at the &lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;original article&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Best overall: RTX 4090 (24GB)
&lt;/h2&gt;

&lt;p&gt;The RTX 4090's 24GB VRAM is what makes it the home training champion. With QLoRA you can fine-tune models up to 34B parameters on a single card — that covers the vast majority of useful home fine-tuning scenarios. With full LoRA on float16, 13B models fit with a reasonable batch size.&lt;/p&gt;

&lt;p&gt;Beyond VRAM: the 4090's 1008 AI TOPS (tensor core throughput) cuts training time significantly versus older Ampere cards. A LoRA run that takes 8 hours on an RTX 3090 may complete in 4-5 hours on the 4090.&lt;/p&gt;

&lt;p&gt;For &lt;a href="https://dev.to/articles/best-gpu-for-lora-training/"&gt;LoRA training specifically&lt;/a&gt;, the 4090 enables higher batch sizes and larger training images compared to 16GB cards, which matters for final model quality.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;See the recommended pick on the original guide&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Value option: RTX 4060 Ti 16GB
&lt;/h2&gt;

&lt;p&gt;At $400, the RTX 4060 Ti 16GB is a capable home training card for realistic workloads:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SD LoRA training (Kohya SS, Dreambooth): comfortable&lt;/li&gt;
&lt;li&gt;7B LLM LoRA (float16): fits, though batch sizes are small&lt;/li&gt;
&lt;li&gt;7B LLM QLoRA: plenty of headroom&lt;/li&gt;
&lt;li&gt;13B QLoRA: works with careful configuration&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The 16GB version of the 4060 Ti is specifically what you want. The 8GB version is not a training card — it is fine for inference but too constrained for most fine-tuning setups.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;See the recommended pick on the original guide&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Serious setup: RTX 5090 (32GB)
&lt;/h2&gt;

&lt;p&gt;The RTX 5090 opens the door to training scenarios that the 4090 cannot handle:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;34B models at QLoRA with comfortable headroom&lt;/li&gt;
&lt;li&gt;Full fine-tuning of 13B models&lt;/li&gt;
&lt;li&gt;Larger batch sizes on 7B LoRA for higher quality&lt;/li&gt;
&lt;li&gt;Multi-modal model fine-tuning (vision + language)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;At 1800 AI TOPS (Blackwell), training is also meaningfully faster. If you plan to train models professionally or as a serious project — not just experimenting — the 5090's extra 8GB VRAM and faster compute make a real difference.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;See the recommended pick on the original guide&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Power, cooling, and PSU: what nobody tells you
&lt;/h2&gt;

&lt;p&gt;This is often the part that catches first-time home training setups off guard:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RTX 4090:&lt;/strong&gt; 450W TDP. Needs a 750W+ PSU (850W recommended). Dual 8-pin connectors or a 16-pin adapter. Generates significant heat in a case — good airflow is essential.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RTX 5090:&lt;/strong&gt; 575W TDP. Needs a 1000W+ PSU. Even more demanding on cooling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;RTX 4060 Ti:&lt;/strong&gt; 165W TDP. A 550W PSU is fine. Runs cool, no exotic cooling needed.&lt;/p&gt;

&lt;p&gt;Training runs your GPU at maximum utilization for extended periods — unlike gaming, which has variable load. Your cooling setup matters: open-air cases run better than tight ITX builds for long training jobs. Monitor GPU temperatures with &lt;code&gt;nvidia-smi&lt;/code&gt; and ensure you stay below 80°C under sustained load.&lt;/p&gt;

&lt;p&gt;For multi-GPU setups, see the &lt;a href="https://dev.to/articles/best-gpu-for-deep-learning/"&gt;deep learning GPU guide&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  LoRA training workflow: quick setup
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Install &lt;a href="https://github.com/kohya-ss/kohya_ss" rel="noopener noreferrer"&gt;Kohya SS&lt;/a&gt; for Stable Diffusion LoRA, or &lt;a href="https://github.com/axolotl-ai-cloud/axolotl" rel="noopener noreferrer"&gt;axolotl&lt;/a&gt; for LLM fine-tuning&lt;/li&gt;
&lt;li&gt;Prepare your dataset (20-100 images for SD LoRA, 100-1000 examples for LLM LoRA)&lt;/li&gt;
&lt;li&gt;Configure training parameters — learning rate, batch size, steps&lt;/li&gt;
&lt;li&gt;Monitor VRAM usage during the first few minutes: &lt;code&gt;watch -n 1 nvidia-smi&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Adjust batch size down if you get OOM errors&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Start with existing guides for your specific model and tool — the parameters tuned for a 7B LoRA are very different from a Stable Diffusion LoRA.&lt;/p&gt;
&lt;h2&gt;
  
  
  Which GPU should YOU buy?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;You want to do SD/SDXL LoRA (Dreambooth, Kohya):&lt;/strong&gt; RTX 4060 Ti 16GB is plenty. The 4090 is faster but not necessary.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You want to fine-tune 7B LLMs with LoRA:&lt;/strong&gt; RTX 4060 Ti 16GB handles this well. The 4090 gives you larger batch sizes and faster training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You want to fine-tune 13B+ models:&lt;/strong&gt; RTX 4090 (24GB). Non-negotiable for comfortable QLoRA at this size.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You want 34B model fine-tuning on a single card:&lt;/strong&gt; RTX 4090 for QLoRA, RTX 5090 for more headroom.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You want to train but hate waiting:&lt;/strong&gt; RTX 5090. Blackwell's training throughput is substantially faster than Ada Lovelace.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;You want to experiment before committing to hardware:&lt;/strong&gt; Use cloud GPU time first (RunPod, Vast.ai) to validate your setup and dataset quality. If you are weighing cloud versus local long-term, our &lt;a href="https://dev.to/articles/cloud-gpu-vs-home-gpu-for-ai/"&gt;cloud GPU vs home GPU for AI&lt;/a&gt; guide breaks down when renting makes sense and when buying wins.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes to avoid
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Starting with too large a model.&lt;/strong&gt; Fine-tune a 7B model first. Learn the tooling, validate your dataset quality, and only scale up once you know what you are doing. A 34B model with bad training data is worse than a well-tuned 7B.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Ignoring PSU requirements.&lt;/strong&gt; An RTX 4090 on a 650W PSU will throttle or crash mid-training. Check your total system power draw before buying a high-end card.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Choosing batch size 1 to fit VRAM.&lt;/strong&gt; Gradient accumulation lets you simulate larger batch sizes while keeping VRAM use constant. Use it — batch size 1 often leads to unstable training.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Not validating the dataset before a long run.&lt;/strong&gt; Run a quick 100-step test first. A 10-hour training run with corrupted or poorly formatted data is wasted time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Underestimating cooling.&lt;/strong&gt; Training loads are more sustained than gaming. Check temperatures, ensure case airflow, and consider a case with good GPU clearance.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Final verdict
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Scenario&lt;/th&gt;
&lt;th&gt;Best GPU&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;SD/SDXL LoRA, 7B LLM LoRA&lt;/td&gt;
&lt;td&gt;RTX 4060 Ti 16GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;7B full LoRA, 13B QLoRA&lt;/td&gt;
&lt;td&gt;RTX 4090&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;34B QLoRA, fastest training&lt;/td&gt;
&lt;td&gt;RTX 5090&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Experimenting before buying&lt;/td&gt;
&lt;td&gt;Cloud GPU (RunPod/Vast.ai)&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Home AI training is more accessible than it has ever been. QLoRA has democratized fine-tuning to a point where an RTX 4090 can do in a weekend what required a multi-GPU server a few years ago. Start small, validate your dataset, and scale the hardware to match the ambition.&lt;/p&gt;

&lt;h2&gt;
  
  
  Frequently Asked Questions
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Can you train AI models on a consumer GPU?
&lt;/h3&gt;

&lt;p&gt;Yes. With LoRA and QLoRA fine-tuning techniques, you can customize 7B–34B parameter models on a single consumer GPU. Full training from scratch is not realistic on consumer hardware, but fine-tuning — which adapts a pretrained model to your data — works well on cards like the RTX 4090 (24GB) and even the RTX 4060 Ti (16GB) for smaller models. The key is choosing the right fine-tuning method for your VRAM budget.&lt;/p&gt;

&lt;h3&gt;
  
  
  How much VRAM do you need for fine-tuning?
&lt;/h3&gt;

&lt;p&gt;It depends on the method and model size. QLoRA fine-tuning of a 7B model needs just 8–12GB VRAM. Full LoRA on a 7B model requires 12–16GB. For 13B models, QLoRA needs 12–16GB and full LoRA needs 24GB. Full fine-tuning (updating all weights) of a 7B model requires 16–24GB VRAM. The general rule is that QLoRA roughly halves the VRAM requirement compared to full LoRA by quantizing the base model to 4-bit.&lt;/p&gt;

&lt;h3&gt;
  
  
  Is LoRA training possible on 8GB VRAM?
&lt;/h3&gt;

&lt;p&gt;Yes, but only for smaller models and with constraints. QLoRA on a 7B model fits on 8GB VRAM with careful configuration, and SD/SDXL LoRA training with Kohya SS is workable at 8GB. However, batch sizes will be very small (often batch size 1), which can lead to less stable training and lower quality results. 12–16GB is strongly recommended for comfortable LoRA training with reasonable batch sizes.&lt;/p&gt;

&lt;h3&gt;
  
  
  How long does fine-tuning take on a home GPU?
&lt;/h3&gt;

&lt;p&gt;A typical LoRA fine-tune of a 7B LLM on 1,000 examples takes roughly 2–4 hours on an RTX 4090 and 6–10 hours on an RTX 4060 Ti. Stable Diffusion LoRA training on 50–100 images usually completes in 1–3 hours on a 4090. Training time scales roughly linearly with dataset size and inversely with GPU compute speed. Always run a short 100-step test first to validate your setup before committing to a full training run.&lt;/p&gt;

&lt;h2&gt;
  
  
  Related guides on Best GPU for AI
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-dreambooth/" rel="noopener noreferrer"&gt;Best GPU for DreamBooth Training in 2026 (Ranked)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-fine-tuning/" rel="noopener noreferrer"&gt;Best GPU for Fine-Tuning AI Models in 2026 (Ranked)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bestgpuforai.com/articles/best-gpu-for-lora-training/" rel="noopener noreferrer"&gt;Best GPU for LoRA Training in 2026 (5 Picks Ranked)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;The full version lives on &lt;a href="https://bestgpuforai.com/articles/best-gpu-for-ai-training-at-home/" rel="noopener noreferrer"&gt;Best GPU for AI&lt;/a&gt;&lt;/strong&gt; — VRAM calculator, GPU comparison table, and live Amazon pricing.&lt;/p&gt;

</description>
      <category>gpu</category>
      <category>aitraining</category>
      <category>home</category>
      <category>finetuning</category>
    </item>
    <item>
      <title>Mastering LLM Fine-Tuning and Local Hosting with Unsloth</title>
      <dc:creator>Lightning Developer</dc:creator>
      <pubDate>Fri, 07 Aug 2026 09:07:48 +0000</pubDate>
      <link>https://dev.to/lightningdev123/mastering-llm-fine-tuning-and-local-hosting-with-unsloth-36c4</link>
      <guid>https://dev.to/lightningdev123/mastering-llm-fine-tuning-and-local-hosting-with-unsloth-36c4</guid>
      <description>&lt;h2&gt;
  
  
  Introduction to Modern Local LLM Workflows
&lt;/h2&gt;

&lt;p&gt;Historically, fine-tuning an 8B parameter Large Language Model (LLM) required access to expensive enterprise hardware like the NVIDIA A100. Developers often faced the anxiety of whether their training run would complete before their cloud compute credits evaporated. Unsloth has fundamentally shifted this paradigm. By utilizing 4-bit QLoRA, an 8B model fine-tuning process now consumes approximately 6 GB of VRAM, allowing for high-performance training on a standard consumer-grade GPU like the RTX 3060.&lt;/p&gt;

&lt;p&gt;Unsloth consists of two main pillars: Unsloth Core, the Python library, and Unsloth Studio, a local web interface. Both leverage hand-written Triton kernels that optimize the training loop's hot paths. These optimizations yield significant results: up to 2x faster training with 70% less VRAM usage, and up to 12x faster performance for mixture-of-experts (MoE) models without sacrificing precision. As of July 2026, the current iteration is v0.1.512-beta.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fug6celtiqayyjko8yue0.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fug6celtiqayyjko8yue0.webp" alt="Blog Image" width="800" height="501"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Getting Started: Installation and Setup
&lt;/h2&gt;

&lt;p&gt;Setting up the environment is streamlined through a single shell command that provisions a Python environment, fetches the llama.cpp backend, and installs the necessary launch binaries.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# macOS, Linux, WSL&lt;/span&gt;
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://unsloth.ai/install.sh | sh

&lt;span class="c"&gt;# Windows PowerShell&lt;/span&gt;
irm https://unsloth.ai/install.ps1 | iex
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyo7koh1it8v2a2bo2pme.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2Fyo7koh1it8v2a2bo2pme.webp" alt="Blog Image" width="800" height="399"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Troubleshooting Mac Installs
&lt;/h3&gt;

&lt;p&gt;If you are on an Apple Silicon Mac, ensure you are using a native arm64 Python interpreter. If the installer mistakenly picks up a universal2 build from python.org, you may encounter &lt;code&gt;pydantic_core&lt;/code&gt; architecture errors. To resolve this, remove the existing environment and point the installer to a specific binary:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; ~/.unsloth/studio
curl &lt;span class="nt"&gt;-fsSL&lt;/span&gt; https://unsloth.ai/install.sh | &lt;span class="nv"&gt;UNSLOTH_PYTHON&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;3.12 sh
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Once installed, you can launch the studio interface:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;unsloth studio &lt;span class="nt"&gt;-p&lt;/span&gt; 8888
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Hardware Considerations
&lt;/h2&gt;

&lt;p&gt;When evaluating what your hardware can handle, remember that macOS utilizes unified memory, with roughly 75% available to the GPU. For inference using UD-Q4_K_XL GGUF models, the weight size plus the KV cache requirements must fit within these limits. MoE models like &lt;code&gt;gpt-oss 20B&lt;/code&gt; or &lt;code&gt;Qwen3.6 35B-A3B&lt;/code&gt; are highly recommended for Mac users because they only activate a fraction of their parameters per token, significantly improving generation speed compared to dense equivalents.&lt;/p&gt;
&lt;h2&gt;
  
  
  The Unsloth Studio Ecosystem
&lt;/h2&gt;

&lt;p&gt;Studio serves as a centralized hub for four primary LLM tasks:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Chat:&lt;/strong&gt; A robust inference interface supporting sandboxed Bash/Python execution and live web searches.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data Recipes:&lt;/strong&gt; A visual workflow builder for converting unstructured files (PDF, DOCX, CSV) into training data using a graph-based UI.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Fine-tuning:&lt;/strong&gt; A guided wizard covering QLoRA, LoRA, and full fine-tuning, featuring real-time tracking of loss and gradient norms.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Export:&lt;/strong&gt; Tools to convert models into 16-bit safetensors, LoRA adapters, or GGUF formats.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Fine-Tuning with Unsloth Core
&lt;/h2&gt;

&lt;p&gt;For advanced use cases, the Python library provides complete programmatic control. While macOS supports GGUF serving, actual fine-tuning training is optimized for NVIDIA hardware. Use the &lt;code&gt;unsloth&lt;/code&gt; library to manage your training loops efficiently:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;unsloth&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;FastModel&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;trl&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SFTTrainer&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FastModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;unsloth/gemma-4-E2B-it&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_seq_length&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2048&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;load_in_4bit&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;True&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Configure LoRA adapters
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;FastModel&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_peft_model&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;r&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;lora_alpha&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;bias&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;none&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Key hyperparameter advice: keep your LoRA rank around 16 or 32, maintain an effective batch size of 16 using &lt;code&gt;gradient_accumulation_steps&lt;/code&gt;, and cap your training at 1 to 3 epochs. Always monitor the loss curve; a value between 0.5 and 1.0 is generally healthy, while values below 0.2 suggest overfitting.&lt;/p&gt;
&lt;h2&gt;
  
  
  Quantization and Export Strategies
&lt;/h2&gt;

&lt;p&gt;Unsloth's UD-quantization format (Dynamic 2.0 GGUF) is arguably superior to standard importance-matrix GGUFs. It dynamically selects quantization types per layer based on architectural sensitivity. For most production needs, the &lt;code&gt;UD-Q4_K_XL&lt;/code&gt; or &lt;code&gt;UD-Q5_K_XL&lt;/code&gt; variants are virtually lossless.&lt;/p&gt;

&lt;p&gt;When exporting, choose your target format carefully:&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Save as GGUF for llama.cpp/Ollama
&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;save_pretrained_gguf&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;gemma4-finetune&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;quantization_method&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Q8_0&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;h2&gt;
  
  
  Sharing Local LLMs with Pinggy
&lt;/h2&gt;

&lt;p&gt;Often, local development stalls because the model is trapped on &lt;code&gt;localhost&lt;/code&gt;. To expose your model securely without complex network configuration, use &lt;a href="https://pinggy.io" rel="noopener noreferrer"&gt;Pinggy&lt;/a&gt; for SSH-based tunneling.&lt;br&gt;
&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;ssh &lt;span class="nt"&gt;-p&lt;/span&gt; 443 &lt;span class="nt"&gt;-R0&lt;/span&gt;:localhost:8888 free.pinggy.io
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7io74nyxea2mus9xbwsd.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Farticles%2F7io74nyxea2mus9xbwsd.webp" alt="Blog Image" width="799" height="176"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This command provides a public HTTPS URL that allows remote access to your studio instance or API endpoint. For sensitive workflows, always disable code execution tools (&lt;code&gt;--disable-tools&lt;/code&gt;) and implement authentication. Since Pinggy uses standard SSH tunnels, you can easily restrict access by IP or use header-based authentication to manage access control efficiently.&lt;/p&gt;
&lt;h2&gt;
  
  
  Limitations and Conclusion
&lt;/h2&gt;

&lt;p&gt;While Unsloth is a powerhouse for single-GPU workflows, multi-GPU orchestration is less mature compared to frameworks like Axolotl. Additionally, Studio is still in beta, meaning you may occasionally encounter edge cases with UI state or data handling. However, for the individual developer looking to bridge the gap between local document processing and a custom-tuned LLM, Unsloth remains the fastest route to production-ready results.&lt;/p&gt;
&lt;h2&gt;
  
  
  Reference
&lt;/h2&gt;


&lt;div class="crayons-card c-embed text-styles text-styles--secondary"&gt;
    &lt;div class="c-embed__content"&gt;
        &lt;div class="c-embed__cover"&gt;
          &lt;a href="https://pinggy.io/blog/finetune_and_selfhost_llms_locally_with_unsloth/" class="c-link align-middle" rel="noopener noreferrer"&gt;
            &lt;img alt="" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpinggy.io%2Fimages%2Ffinetune_and_selfhost_llms_locally_with_unsloth%2Ffinetune_and_selfhost_llms_locally_with_unsloth_banner.webp" height="450" class="m-0" width="800"&gt;
          &lt;/a&gt;
        &lt;/div&gt;
      &lt;div class="c-embed__body"&gt;
        &lt;h2 class="fs-xl lh-tight"&gt;
          &lt;a href="https://pinggy.io/blog/finetune_and_selfhost_llms_locally_with_unsloth/" rel="noopener noreferrer" class="c-link"&gt;
            Self-Host and Fine-Tune LLMs Locally with Unsloth in 2026 | Pinggy Blog
          &lt;/a&gt;
        &lt;/h2&gt;
          &lt;p class="truncate-at-3"&gt;
            Fine-tune LLMs locally with Unsloth: QLoRA on a single GPU, Unsloth Studio, Dynamic GGUF quants, and sharing your model over a Pinggy tunnel.
          &lt;/p&gt;
        &lt;div class="color-secondary fs-s flex items-center"&gt;
            &lt;img alt="favicon" class="c-embed__favicon m-0 mr-2 radius-0" src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fpinggy.io%2Fassets%2Ffavicon2.ico" width="75" height="75"&gt;
          pinggy.io
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
&lt;/div&gt;



</description>
      <category>llm</category>
      <category>ai</category>
      <category>python</category>
      <category>finetuning</category>
    </item>
    <item>
      <title>Reinforcement Fine-Tuning: When a 4B Model Beats GPT-5.6</title>
      <dc:creator>Umesh Malik</dc:creator>
      <pubDate>Thu, 06 Aug 2026 10:42:07 +0000</pubDate>
      <link>https://dev.to/umesh_malik/reinforcement-fine-tuning-when-a-4b-model-beats-gpt-56-3km8</link>
      <guid>https://dev.to/umesh_malik/reinforcement-fine-tuning-when-a-4b-model-beats-gpt-56-3km8</guid>
      <description>&lt;p&gt;&lt;strong&gt;Reinforcement fine-tuning is post-training a model against a programmable grader instead of a fixed dataset of correct answers&lt;/strong&gt; — and it just produced the most interesting number in LLM engineering. A &lt;strong&gt;4B open model matched GPT-5.6 Sol on a retrieval task at roughly 100x less cost&lt;/strong&gt;, reported in Neon's &lt;a href="https://neon.com/blog/how-castform-neon-beats-frontier-models-on-price-and-efficiency" rel="noopener noreferrer"&gt;write-up of a Castform post-training run&lt;/a&gt;. Same job, two orders of magnitude apart on the bill.&lt;/p&gt;

&lt;p&gt;That result is not a claim that small models are secretly as good as frontier models. It's a claim about where the money goes when you make a general model do a narrow job over and over — and reinforcement fine-tuning is the lever that gets it back.&lt;/p&gt;

&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;RFT trains against a grader, not against answers.&lt;/strong&gt; You write a function that scores a response; the model learns to score well. No labelled ideal outputs required.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The 100x gap is a tax refund, not a capability win.&lt;/strong&gt; A frontier model re-derives your retrieval strategy on every call. Post-training bakes it into weights, so you stop paying at inference time.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;A multi-turn search with gpt-5.6-sol runs &amp;gt;10s and ~$0.03 end to end.&lt;/strong&gt; At a million queries that's $30,000 and a UX problem.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decompose the reward.&lt;/strong&gt; The Castform setup grades retrieval, citation, and correctness separately — a single end-to-end score rewards lucky guesses from wrong evidence.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Data requirements are small.&lt;/strong&gt; OpenAI recommends starting between several dozen and a few hundred examples, capped at 50,000.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prompt first.&lt;/strong&gt; RFT pays off on high-volume, gradeable, stable tasks. Break any one of those three and it's a science project.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What reinforcement fine-tuning actually is
&lt;/h2&gt;

&lt;p&gt;Mechanically, the loop is short: the model produces candidate responses, the grader scores each one, and the optimizer shifts weights so the high-scoring behavior becomes more likely. There is no labelled "ideal answer" anywhere in that loop — only a score.&lt;/p&gt;

&lt;p&gt;That one substitution — grader in place of golden answers — changes which problems are trainable. Supervised fine-tuning needs you to write the ideal output for every example. Most real engineering tasks fail that test: you can tell whether a retrieval call returned the right document, but writing the perfect multi-turn search trajectory by hand for 500 queries is a job nobody will finish.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://developers.openai.com/api/docs/guides/reinforcement-fine-tuning" rel="noopener noreferrer"&gt;OpenAI's RFT guide&lt;/a&gt; formalizes this with grader types you compose: &lt;code&gt;string_check&lt;/code&gt; for exact matches, &lt;code&gt;text_similarity&lt;/code&gt;, &lt;code&gt;score_model&lt;/code&gt; for a 0–1 model-graded score, &lt;code&gt;python&lt;/code&gt; for arbitrary sandboxed logic, and &lt;code&gt;multi&lt;/code&gt; to combine several with weights. If you have ever written an eval, you have already written most of a reward function — which is the real reason this technique got accessible.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why the 100x gap exists
&lt;/h2&gt;

&lt;p&gt;Here is the mechanism, and it has nothing to do with the small model being smarter.&lt;/p&gt;

&lt;p&gt;When you prompt a frontier model to do hybrid retrieval, every request pays for the model to work out &lt;em&gt;how&lt;/em&gt; to search: which terms to pull, whether to run keyword or vector search, how to reconcile the two result sets, when to stop and answer. That reasoning is identical on call one and call one million. You are paying full frontier token rates to re-derive a fixed strategy, forever.&lt;/p&gt;

&lt;p&gt;Post-training moves that strategy from the prompt into the weights. The Castform run trained the model to drive Neon's Postgres search directly — &lt;code&gt;lakebase_text&lt;/code&gt; for BM25, &lt;code&gt;lakebase_vector&lt;/code&gt; for embedding similarity, &lt;code&gt;rrf_merge&lt;/code&gt; for reciprocal-rank fusion — so the search policy is learned behavior, not per-call deliberation. The numbers Neon reports: a typical multi-turn search with gpt-5.6-sol takes &lt;strong&gt;over 10 seconds and about $0.03 end to end&lt;/strong&gt;, while the 4B post-trained model does the same work for roughly &lt;strong&gt;100x less&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Two things worth being precise about. First, $0.03 per query sounds trivial and isn't: at a million queries it's $30,000, and the 10-second latency is the part your users actually feel. Second, this is a &lt;em&gt;narrow&lt;/em&gt; win. Ask that 4B model to do anything other than search your corpus and it will lose to the frontier model badly. That's the trade, and it's a good one only when the task really is narrow.&lt;/p&gt;

&lt;p&gt;The same shape shows up elsewhere. &lt;a href="https://fireworks.ai/blog/reinforcement-fine-tuning" rel="noopener noreferrer"&gt;Fireworks reports&lt;/a&gt; a 32B open model exceeding GPT-4o quality on customer-service function-call generation after SFT plus RFT, and a code-autofixer model built with Vercel running "10 to 40 times faster" than GPT-4o-mini and Gemini 2.5-Flash at matched quality. Different domains, same story: narrow task, learned policy, collapsed cost.&lt;/p&gt;

&lt;h2&gt;
  
  
  Reward design is the whole job
&lt;/h2&gt;

&lt;p&gt;If you take one engineering lesson from the Castform run, make it this: &lt;strong&gt;decompose the reward&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Their reward function composes three checks:&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Component&lt;/th&gt;
&lt;th&gt;What it asks&lt;/th&gt;
&lt;th&gt;Failure it catches&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Retrieval&lt;/td&gt;
&lt;td&gt;Was the correct source retrieved?&lt;/td&gt;
&lt;td&gt;Search policy is wrong — bad query terms, wrong index&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Citation&lt;/td&gt;
&lt;td&gt;Was the right chunk cited?&lt;/td&gt;
&lt;td&gt;Retrieved the doc, pointed at the wrong passage&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Correctness&lt;/td&gt;
&lt;td&gt;Was the final answer right?&lt;/td&gt;
&lt;td&gt;Had the evidence, reasoned badly from it&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A single end-to-end correctness score cannot tell those three apart. Worse, it actively rewards the model that produced the right answer from the wrong evidence — a hallucination that happened to land. Train on that signal long enough and you get a model that has learned to guess confidently, which is the exact behavior you started this project to eliminate.&lt;/p&gt;

&lt;p&gt;This is also why teams with a real evaluation harness get to RFT faster than teams without one. If you've already built stage-level evals for your pipeline — the kind of decomposition I covered in &lt;a href="https://umesh-malik.com/blog/llm-eval-framework-smevals" rel="noopener noreferrer"&gt;the smevals write-up on LLM eval frameworks&lt;/a&gt; — your reward function is mostly a rename. If your only measurement is "does the answer look right," you have weeks of work before any training run is meaningful.&lt;/p&gt;

&lt;p&gt;The other half of the setup is throughput. RL post-training needs thousands of parallel rollouts, each one hitting the database, which is why the training loop lives next to autoscaling Postgres rather than a fixed-size instance. Your reward function's latency becomes your training loop's bottleneck — budget for it the way you'd budget for a hot path in production.&lt;/p&gt;

&lt;h2&gt;
  
  
  The decision: prompt, RAG, or post-train
&lt;/h2&gt;

&lt;p&gt;Three conditions have to hold together before RFT beats prompting.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. The task is stable.&lt;/strong&gt; You're optimizing a policy into weights. If the task definition changes monthly, you're re-training monthly, and the frontier model's flexibility is worth its price.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. The task is gradeable programmatically.&lt;/strong&gt; Not "a human can tell." A function has to tell, cheaply, thousands of times per training step. Code compilation, retrieval hit/miss, schema validation, and exact-match all qualify. "Is this summary tasteful" does not.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. The volume justifies it.&lt;/strong&gt; Take your current spend, subtract the projected post-trained spend, and compare against training plus the engineering time to build the grader. At a few hundred calls a day, no arithmetic saves you. At a few hundred thousand, the case makes itself.&lt;/p&gt;

&lt;p&gt;Note that none of these say "replace RAG." The Castform model &lt;em&gt;is&lt;/em&gt; doing retrieval — it just learned to drive the search rather than being told how on each call. If you're still assembling the pipeline itself, start with the fundamentals in &lt;a href="https://umesh-malik.com/blog/build-rag-pipeline-from-scratch" rel="noopener noreferrer"&gt;building a RAG pipeline from scratch&lt;/a&gt; and get chunking, indexing, and the retrieval layer validated first. Post-training a model to drive a retrieval layer you haven't validated just teaches it to exploit your bugs — the same demo-to-production gap that swallows &lt;a href="https://umesh-malik.com/blog/production-grade-ai-agents-vibe-to-live-gap" rel="noopener noreferrer"&gt;most agent projects&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Data volume is the pleasant surprise. OpenAI's guidance is to &lt;strong&gt;start between several dozen and a few hundred examples&lt;/strong&gt;, with limits of 50,000 training and 1,000 test examples, and an explicit note that dozens can be enough if quality is high. The caveat matters more than the number: your base model should already succeed on the task &lt;em&gt;sometimes&lt;/em&gt;. RFT sharpens a capability the model has; it does not install one it lacks. If your base model scores zero, you need a bigger base model, not more RL.&lt;/p&gt;

&lt;h2&gt;
  
  
  Where this goes wrong
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Grading the wrong thing.&lt;/strong&gt; The reward function is the specification, and the model will satisfy it literally. A retrieval reward that only checks whether &lt;em&gt;any&lt;/em&gt; result came back trains a model that always returns something.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Skipping the held-out set.&lt;/strong&gt; RL will happily overfit to your grader's blind spots. Keep a test set the training loop never sees and treat a widening gap between training reward and held-out score as a stop signal.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Assuming the frontier baseline is static.&lt;/strong&gt; You are optimizing against a moving target. The cost of the model you're beating drops every few months on its own, which shortens the payback window on your training investment — one more reason volume has to be real, not projected.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Confusing "small model" with "local model."&lt;/strong&gt; These are separate decisions. Running a 4B model on your own hardware is a deployment choice with its own tradeoffs, covered separately in &lt;a href="https://umesh-malik.com/blog/run-70b-llm-on-4gb-gpu-airllm" rel="noopener noreferrer"&gt;running large models on small GPUs&lt;/a&gt;. A post-trained 4B model served from a managed endpoint is still a 100x cost win.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Training when the real problem is the pipeline.&lt;/strong&gt; If retrieval quality is bad because the chunking is bad, RFT will teach the model to work around bad chunks. Fix the pipeline; then decide whether the remaining gap is worth a training run.&lt;/p&gt;

&lt;h2&gt;
  
  
  What to do this week
&lt;/h2&gt;

&lt;p&gt;If you have one high-volume, narrow LLM task in production:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Instrument it.&lt;/strong&gt; Log queries, retrieved context, outputs, and per-call cost for a week. You need the volume number before anything else.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Write the grader.&lt;/strong&gt; Not the trainer — the grader. Score your &lt;em&gt;existing&lt;/em&gt; production traffic with it. If you can't write it, you've learned the answer already.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Decompose it&lt;/strong&gt; into stage-level components the way the retrieval/citation/correctness split does.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Run the arithmetic.&lt;/strong&gt; Current monthly spend versus post-trained spend versus the cost of building and maintaining the whole thing.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The pattern worth internalizing: the frontier model is a fantastic way to &lt;em&gt;discover&lt;/em&gt; the right policy for a task, and an expensive way to &lt;em&gt;run&lt;/em&gt; it a million times. Reinforcement fine-tuning is the migration between those two states — and as &lt;a href="https://umesh-malik.com/blog/explorative-modeling-train-on-best-of-k" rel="noopener noreferrer"&gt;work on training against best-of-k sampling&lt;/a&gt; keeps showing, the technique is getting cheaper faster than most teams' intuitions are updating.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;What is reinforcement fine-tuning (RFT)?&lt;/strong&gt;&lt;br&gt;
Reinforcement fine-tuning trains a model against a programmable grader instead of a fixed set of correct answers. The model generates candidate responses, a reward function scores each one, and the weights shift so high-scoring behavior becomes more likely. OpenAI's guide describes it as adapting a reasoning model using custom feedback signals rather than labelled outputs, which is what makes it viable when you can check an answer but can't hand-write the ideal one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How can a 4B model beat a frontier model like GPT-5.6 Sol?&lt;/strong&gt;&lt;br&gt;
It doesn't beat it in general — it beats it on one task. A frontier model has to infer your retrieval strategy from a prompt on every single call. A post-trained 4B model has that strategy baked into its weights, so it stops paying the reasoning tax at inference time. Neon's write-up reports a multi-turn search with gpt-5.6-sol taking over 10 seconds and costing about $0.03 end to end, against roughly 100x less for the small post-trained model.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;When should I use RFT instead of prompting or RAG?&lt;/strong&gt;&lt;br&gt;
Use prompting first, always. RFT earns its keep when the same narrow decision runs at high volume, you can grade an answer programmatically, and inference cost or latency is a real constraint. If your task changes weekly, if you can't write a grader, or if you serve a few hundred calls a day, prompting a frontier model is cheaper than any training run you could justify.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How much training data does reinforcement fine-tuning need?&lt;/strong&gt;&lt;br&gt;
Far less than supervised fine-tuning. OpenAI's guidance is to start with several dozen to a few hundred examples before investing further, with a hard ceiling of 50,000 training examples and 1,000 test examples. The documentation stresses that dozens of examples can be meaningful as long as they're high quality — and that your base model should already succeed on the task sometimes, since RFT sharpens existing capability rather than installing new capability.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What makes a good reward function for a retrieval task?&lt;/strong&gt;&lt;br&gt;
Decompose it instead of grading the final answer alone. The Castform/Neon setup splits reward into three checks — was the correct source retrieved, was the right chunk cited, and was the final answer correct — so the model gets signal about which stage failed. A single end-to-end correctness score rewards a model that guesses the right answer from the wrong evidence, which is exactly the failure mode you're trying to train out.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does RFT lock me into one model or vendor?&lt;/strong&gt;&lt;br&gt;
Partly, and you should plan for it. OpenAI's RFT is currently limited to o-series reasoning models, specifically &lt;code&gt;o4-mini-2025-04-16&lt;/code&gt;. Open-weight paths are broader — Fireworks supports Llama, Phi 3/4, Qwen 2.5/3, DeepSeek V3 and R1 — and leave the weights in your hands. The portable asset in either case is your grader and your evaluation set, not the checkpoint; keep those in version control and a base-model swap becomes a retraining run rather than a rewrite.&lt;/p&gt;

&lt;h2&gt;
  
  
  Sources
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Neon, &lt;a href="https://neon.com/blog/how-castform-neon-beats-frontier-models-on-price-and-efficiency" rel="noopener noreferrer"&gt;"How Castform + Neon beats frontier models on price and efficiency"&lt;/a&gt; — the 4B model result, the ~100x cost figure, the &amp;gt;10s / ~$0.03 gpt-5.6-sol baseline, the &lt;code&gt;lakebase_text&lt;/code&gt; / &lt;code&gt;lakebase_vector&lt;/code&gt; / &lt;code&gt;rrf_merge&lt;/code&gt; search stack, and the three-part reward function.&lt;/li&gt;
&lt;li&gt;OpenAI, &lt;a href="https://developers.openai.com/api/docs/guides/reinforcement-fine-tuning" rel="noopener noreferrer"&gt;Reinforcement fine-tuning guide&lt;/a&gt; — the grader-based definition, the grader types, the o4-mini model restriction, and the dataset-size guidance (dozens to a few hundred to start; 50,000 training / 1,000 test maximum).&lt;/li&gt;
&lt;li&gt;Fireworks AI, &lt;a href="https://fireworks.ai/blog/reinforcement-fine-tuning" rel="noopener noreferrer"&gt;"Reinforcement Fine Tuning: Train expert open models to surpass closed frontier models"&lt;/a&gt; — the supported open base models, the 32B customer-service result against GPT-4o, and the Vercel autofixer's 10–40x latency advantage over GPT-4o-mini and Gemini 2.5-Flash.&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;em&gt;Written for &lt;a href="https://umesh-malik.com" rel="noopener noreferrer"&gt;umesh-malik.com&lt;/a&gt; — no-fluff technical writing on AI, Web Dev, and Engineering.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://umesh-malik.com/blog/reinforcement-fine-tuning-small-models-retrieval" rel="noopener noreferrer"&gt;umesh-malik.com&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep reading on umesh-malik.com:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://umesh-malik.com/blog/rag-vs-fine-tuning-llms-2026" rel="noopener noreferrer"&gt;RAG vs Fine-Tuning for LLMs in 2026: A Production Decision Framework With Real Tradeoffs&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://umesh-malik.com/blog/llm-eval-framework-smevals" rel="noopener noreferrer"&gt;LLM Eval Framework: Grade Prompts, Models and Harnesses&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://umesh-malik.com/blog/run-70b-llm-on-4gb-gpu-airllm" rel="noopener noreferrer"&gt;Run 70B LLM on 4GB GPU: AirLLM's Real Tradeoff&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>llmengineering</category>
      <category>finetuning</category>
      <category>rag</category>
      <category>reinforcementlearning</category>
    </item>
    <item>
      <title>Rent a GPU for LLM Fine-Tuning: The $30 Weekend Project</title>
      <dc:creator>Thurmon Demich</dc:creator>
      <pubDate>Mon, 03 Aug 2026 01:13:38 +0000</pubDate>
      <link>https://dev.to/thurmon_demich/rent-a-gpu-for-llm-fine-tuning-the-30-weekend-project-3khp</link>
      <guid>https://dev.to/thurmon_demich/rent-a-gpu-for-llm-fine-tuning-the-30-weekend-project-3khp</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;From the &lt;a href="https://bestgpuforllm.com/articles/rent-gpu-for-llm-fine-tuning/" rel="noopener noreferrer"&gt;Best GPU for LLM&lt;/a&gt; archive. The canonical version has interactive calculators, an up-to-date GPU comparison table, and live pricing.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You've got a dataset of 10,000 support tickets, a free weekend, and a plan: fine-tune a 7B model to answer like your best support engineer. Then you check GPU prices and the plan stalls. An RTX 4090 is ~$1,600. A used 3090 is ~$800. For one training run?&lt;/p&gt;

&lt;p&gt;Stop. This is a rental job.&lt;/p&gt;

&lt;p&gt;A QLoRA fine-tune on a 7B-13B model takes somewhere between 3 and 12 hours of GPU time for a dataset that size. Rented by the hour, your entire weekend project costs less than a nice dinner. The real decision isn't "which GPU should I buy" — it's "am I buying hours or buying hardware."&lt;/p&gt;

&lt;h2&gt;
  
  
  What your fine-tune actually needs
&lt;/h2&gt;

&lt;p&gt;The method determines the hardware, and the hardware determines the bill. QLoRA quantizes the base model to 4-bit and trains only adapter layers, which is why a 7B run needs roughly 8GB of VRAM and a 13B run roughly 14GB — both fit a rentable 24GB RTX 4090 at roughly $0.35-0.50/hr as of mid-2026.&lt;/p&gt;

&lt;p&gt;Step up to QLoRA on 70B, or full LoRA on a 13B, and you want an A100 80GB at roughly $0.75-1.50/hr. Full-parameter fine-tunes of anything mid-size push you into multi-GPU H100 territory at roughly $2.00-3.00/hr per card — rarely worth it when adapter methods get you 95% of the quality.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;What you're training&lt;/th&gt;
&lt;th&gt;Rent this&lt;/th&gt;
&lt;th&gt;Approx $/hr (mid-2026)&lt;/th&gt;
&lt;th&gt;Typical weekend cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;QLoRA 7B-13B&lt;/td&gt;
&lt;td&gt;RTX 4090 (24GB)&lt;/td&gt;
&lt;td&gt;$0.35-0.50&lt;/td&gt;
&lt;td&gt;~$10-25&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;QLoRA 34B-70B / full LoRA 13B&lt;/td&gt;
&lt;td&gt;A100 80GB&lt;/td&gt;
&lt;td&gt;$0.75-1.50&lt;/td&gt;
&lt;td&gt;~$20-60&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full fine-tune 7B-13B&lt;/td&gt;
&lt;td&gt;2-4x H100 80GB&lt;/td&gt;
&lt;td&gt;$2.00-3.00 each&lt;/td&gt;
&lt;td&gt;~$100-400&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;That first row is the whole story for most weekend projects. Ten dollars.&lt;/p&gt;

&lt;h2&gt;
  
  
  The break-even math
&lt;/h2&gt;

&lt;p&gt;Say you fine-tune once a quarter, 10 GPU-hours per run. On a rented A100 that's roughly $40-60 a year. The RTX 4090 you were about to buy costs $1,600 — a 25-40 year payback, ignoring electricity. For occasional fine-tuning, renting wins by an order of magnitude and it isn't close. Our &lt;a href="https://dev.to/articles/cloud-gpu-tco-vs-self-hosted-llm/"&gt;cloud vs self-hosted TCO breakdown&lt;/a&gt; runs the full numbers.&lt;/p&gt;

&lt;p&gt;The math flips if you're iterating constantly. Ten runs a month — sweeping hyperparameters, testing dataset variants, retraining weekly — burns $75-150/month in rentals, and now a used RTX 3090 pays for itself inside a year. (It also doubles as your inference box, which the rental never does.) That's when our &lt;a href="https://dev.to/articles/best-gpu-for-llm-fine-tuning/"&gt;buying guide for fine-tuning GPUs&lt;/a&gt; becomes the relevant article, not this one.&lt;/p&gt;

&lt;p&gt;For the heavy-iteration case, the 24GB card is the one to own: &lt;br&gt;
&lt;strong&gt;&lt;a href="https://bestgpuforllm.com/articles/rent-gpu-for-llm-fine-tuning/" rel="noopener noreferrer"&gt;See the recommended pick on the original guide&lt;/a&gt;&lt;/strong&gt;&lt;br&gt;
 handles QLoRA up to 34B locally, and every experiment after purchase is free.&lt;/p&gt;

&lt;h2&gt;
  
  
  Renting without wasting money
&lt;/h2&gt;

&lt;p&gt;A few habits separate a $15 weekend from a $70 one.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Checkpoint to persistent storage.&lt;/strong&gt; Spot instances get reclaimed with minutes of warning. Save checkpoints every 30-60 minutes to a network volume or push adapters to Hugging Face — losing hour nine of a ten-hour run is the classic rental disaster.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Use spot pricing.&lt;/strong&gt; Interruptible instances run 50-80% off on-demand rates on &lt;a href="https://dev.to/articles/runpod-vs-vast-ai-for-llm/"&gt;RunPod and Vast.ai&lt;/a&gt;. With checkpointing in place, interruptions cost you minutes, not money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Watch egress fees.&lt;/strong&gt; Many providers charge $0.05-0.12/GB to move data out. A LoRA adapter is a few hundred MB — trivial. A full merged 13B model is 25GB+, so merge locally instead of downloading merged weights.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shut it down.&lt;/strong&gt; An idle A100 bills exactly like a busy one. Terminate the instance when training ends; don't leave it running "in case" you want to poke at the results Monday.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Common mistakes
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Renting an H100 for a QLoRA job.&lt;/strong&gt; A 7B QLoRA run doesn't saturate an H100; you're paying 5x the rate for maybe 2x the speed. Rent the cheapest GPU that fits your VRAM requirement.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Uploading the dataset over and over.&lt;/strong&gt; Prep your data locally, upload once to persistent storage, and mount it across runs. Re-uploading 10GB on every instance start wastes both time and, on some providers, money.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Skipping a dry run.&lt;/strong&gt; Launch with 1% of your dataset first. Catching a broken tokenizer config after ten minutes costs pennies; catching it after ten hours costs the whole weekend budget.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Renting for fine-tuning: quick answers
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;How much does it cost to rent a GPU for fine-tuning?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A rented RTX 4090 runs roughly $0.35-0.50/hr as of mid-2026, and an A100 80GB roughly $0.75-1.50/hr. A weekend QLoRA run on a 7B-13B model typically lands around $10-40 total including setup and some idle time. Spot pricing can cut that by half or more, provided you checkpoint regularly in case the instance gets reclaimed.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I fine-tune a 7B model on a rented RTX 4090?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, comfortably. QLoRA on a 7B model needs roughly 8GB of VRAM, so the 4090's 24GB handles it with room to raise batch size or sequence length. A 13B QLoRA run at roughly 14GB also fits without trouble. Full LoRA on 13B is where you outgrow 24GB and should step up to a rented A100 80GB instead.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Do I need an H100 to fine-tune an LLM?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Almost never for adapter-based methods. QLoRA on models up to 34B fits a single 24GB card, and an A100 80GB covers QLoRA on 70B. H100s earn their roughly $2.00-3.00/hr rate on full-parameter fine-tunes and multi-GPU training runs where raw throughput matters more than cost — not on a weekend adapter project.&lt;/p&gt;

&lt;h2&gt;
  
  
  Verdict
&lt;/h2&gt;

&lt;p&gt;Fine-tuning occasionally? Rent. A weekend QLoRA project on a 7B-13B model costs roughly $10-40 on a rented 4090 or A100 — the same GPU hours you'd get from a $1,600 purchase, minus the purchase. Iterating daily? Buy the 24GB card and rent &lt;a href="https://dev.to/articles/best-cloud-gpu-for-llm/"&gt;bigger cloud GPUs&lt;/a&gt; only for the runs that don't fit.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;If you can count your fine-tuning runs per year on one hand, rent the GPU — the hardware you were about to buy takes decades to pay for itself.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Related guides on Best GPU for LLM
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://bestgpuforllm.com/articles/best-cloud-gpu-for-llm/" rel="noopener noreferrer"&gt;Best Cloud GPU for LLM in 2026: What to Rent by Model Size&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bestgpuforllm.com/articles/best-gpu-for-llm-fine-tuning/" rel="noopener noreferrer"&gt;Best GPU for LLM Fine-Tuning in 2026 (Ranked Picks)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bestgpuforllm.com/articles/can-you-run-kimi-k3-locally/" rel="noopener noreferrer"&gt;Can You Run Kimi K3 Locally? No — Here's the Exact Math&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;p&gt;&lt;strong&gt;The full version lives on &lt;a href="https://bestgpuforllm.com/articles/rent-gpu-for-llm-fine-tuning/" rel="noopener noreferrer"&gt;Best GPU for LLM&lt;/a&gt;&lt;/strong&gt; — VRAM calculator, GPU comparison table, and live Amazon pricing.&lt;/p&gt;

</description>
      <category>finetuning</category>
      <category>gpurental</category>
      <category>cloudgpu</category>
      <category>qlora</category>
    </item>
    <item>
      <title>Fine-Tuning for Tool-Call Accuracy: When Prompting Stops</title>
      <dc:creator>AI Tech Connect</dc:creator>
      <pubDate>Fri, 31 Jul 2026 13:32:34 +0000</pubDate>
      <link>https://dev.to/rishi_kora/fine-tuning-for-tool-call-accuracy-when-prompting-stops-4n89</link>
      <guid>https://dev.to/rishi_kora/fine-tuning-for-tool-call-accuracy-when-prompting-stops-4n89</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://aitechconnect.in/tips/fine-tune-tool-call-accuracy-2026" rel="noopener noreferrer"&gt;AI Tech Connect&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Why "the agent called the wrong tool" is a useless bug report Every team that ships an agent eventually files the same ticket. Something went wrong in production, someone pulled the trace, and the summary line reads: the model called the wrong tool. It is the sort of statement that feels like a diagnosis and functions like a shrug. It tells you nothing about what to change, which is why the next thing that usually happens is a proposal to fine-tune — because fine-tuning is the largest, most expensive-looking lever in the drawer, and reaching for it feels proportionate to the frustration. The problem is that "called the wrong tool" is a category that quietly contains at least five unrelated engineering failures. A model that picks search_orders when it needed search_shipments has failed at…&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;&lt;a href="https://aitechconnect.in/tips/fine-tune-tool-call-accuracy-2026" rel="noopener noreferrer"&gt;Read the full article on AI Tech Connect →&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>research</category>
      <category>finetuning</category>
      <category>ai</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Pioneer.ai Alternative: How to Fine-Tune AI Models Without a Subscription</title>
      <dc:creator>Miniclay AI</dc:creator>
      <pubDate>Thu, 30 Jul 2026 13:58:34 +0000</pubDate>
      <link>https://dev.to/miniclayai/pioneerai-alternative-how-to-fine-tune-ai-models-without-a-subscription-24pj</link>
      <guid>https://dev.to/miniclayai/pioneerai-alternative-how-to-fine-tune-ai-models-without-a-subscription-24pj</guid>
      <description>&lt;p&gt;If you’re reading this, your Pioneer.ai account is probably blocked, or you’re tired of the mandatory USD 20/month subscription for basic access. The fine-tuning market is shifting, and developers are looking&lt;br&gt;
for reliable, transparent alternatives.&lt;/p&gt;

&lt;p&gt;We built Miniclay AI specifically to solve the frustration caused by opaque pricing and subscription lockins. Here is why non-technical founders and small teams are switching from Pioneer to Miniclay:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;No Monthly Subscription: Pioneer requires a USD 20/month minimum. Miniclay is strictly pay-asyou-go at USD 4 per job.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Zero Code Required: Pioneer is API-first and requires developer knowledge. Miniclay uses a prompt-based interface. You describe what you want, and we handle the data cleaning, training, and&lt;br&gt;
deployment.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Transparent Pricing: Together.ai is notorious for hidden multi-meter billing. Miniclay charges exactly&lt;br&gt;
USD 4 per completed job. No hidden GPU costs.&lt;br&gt;
1&lt;br&gt;
Miniclay AI Zero-Cost Marketing Kit&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Instant Deployment: Pioneer users report waiting up to 7 days for adaptive inference improvements.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Miniclay deploys your fine-tuned model in minutes.&lt;br&gt;
If you are locked out of Pioneer right now and need to fine-tune a model urgently, Miniclay offers a riskfree way to test our pipeline.&lt;/p&gt;

&lt;p&gt;Get USD 5 in free fine-tuning credits at Miniclay AI (miniclayai.com). No credit card required.&lt;/p&gt;

</description>
      <category>ai</category>
      <category>pioneer</category>
      <category>pioneeraialternative</category>
      <category>finetuning</category>
    </item>
    <item>
      <title>A $500 fine-tune of a 9B open model beat all five frontier models it was tested against</title>
      <dc:creator>Breach Protocol</dc:creator>
      <pubDate>Thu, 30 Jul 2026 03:14:27 +0000</pubDate>
      <link>https://dev.to/breachprotocol/a-500-fine-tune-of-a-9b-open-model-beat-all-five-frontier-models-it-was-tested-against-me</link>
      <guid>https://dev.to/breachprotocol/a-500-fine-tune-of-a-9b-open-model-beat-all-five-frontier-models-it-was-tested-against-me</guid>
      <description>&lt;p&gt;A 9-billion-parameter open model, reinforcement-trained for about $500 of rented GPU time, outscored every frontier configuration a European consultancy tested on its own product-catalog review workflow. In an article published July 27, Fermisense reports that its trained specialist reached 87.3% of the achievable score on the task against 76.9% for the best frontier setup, at a cost of $0.50 per thousand listings versus $34 for the strongest commercial model.&lt;/p&gt;

&lt;h3&gt;
  
  
  Key facts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;The headline number:&lt;/strong&gt; 87.3% of the achievable score versus 76.9% for the best of five frontier configurations, and roughly 68 times cheaper per reviewed listing.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;The training cost:&lt;/strong&gt; two rented RTX PRO 6000 GPUs, 1,000 optimizer steps, about three and a half days, roughly $500 in GPU time -- with the frontier band crossed after about 250 steps.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Who and when:&lt;/strong&gt; Fermisense, July 27, 2026, in a write-up by Justinas Zaliaduonis, Joris Zilinskis, Fabian Hildesheim, Joel Hainzl and Gediminas Pazera.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Primary source:&lt;/strong&gt; &lt;a href="https://fermisense.com/when-machines-take-the-wheel/" rel="noopener noreferrer"&gt;The Rise of Intelligence Ownership&lt;/a&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The task is deliberately mundane, which is the point. An agent receives an e-commerce listing, searches a product taxonomy, checks whether the claimed brand is registered and protected, retrieves the attribute schema, and then either commits a structured decision or escalates to a human when evidence is thin. Fermisense built a scored simulator of that workflow -- listings flow in, the agent uses the same tools an analyst would, and a scorer grades every decision -- then trained the model against it with &lt;a href="https://groundtruth.day/news//learn/group-relative-policy-optimization.html" rel="noopener noreferrer"&gt;GRPO&lt;/a&gt;, a reinforcement-learning method that compares batches of attempts against each other rather than needing a separate value model. The infrastructure was the open-source &lt;a href="https://github.com/PrimeIntellect-ai/prime-rl" rel="noopener noreferrer"&gt;prime-rl&lt;/a&gt; framework, and the released adapter names its base as &lt;a href="https://huggingface.co/BosonicJustin/qwen35-9b-catalog-adapter" rel="noopener noreferrer"&gt;Qwen3.5-9B&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Before training anything, they measured the ceiling. Five frontier models -- GPT-5.5, GPT-5.6 Sol, Gemini 3.1 Pro, Claude Opus 4.8 and Claude Fable 5 -- ran 200 stratified validation episodes with identical tools, images, scorer and turn budget, each in two configurations: a plain prompt, and 2,800 characters of carefully tuned extraction conventions, lookup procedures and worked examples. The optimized versions all converged within a tenth of a point of each other. One of the strongest zero-shot models actually got &lt;em&gt;worse&lt;/em&gt; with the extra instructions. And the instructions were not free: they inflated input-token bills by 28-55% on every single call, forever.&lt;/p&gt;

&lt;p&gt;That is the sentence in the piece worth keeping: "Prompted task knowledge is rented per call; trained task knowledge is bought once and lives in the weights." A prompt is a briefing you re-read aloud to a contractor at the start of every job. &lt;a href="https://groundtruth.day/news//learn/fine-tuning-and-lora.html" rel="noopener noreferrer"&gt;Fine-tuning&lt;/a&gt; is hiring someone who already worked there for a year. The contractor may be smarter in general; the employee knows that this particular brand code means something odd, and that a specific product category is where the policy violations hide.&lt;/p&gt;

&lt;p&gt;The reward design is where the local knowledge gets encoded. Fermisense weighted the score across category accuracy, attribute extraction and policy judgment, and made missed violations far more costly than false alarms -- a choice that encodes their client's risk appetite, not a universal truth. This is the pattern behind every credible version of this story, and it matches what our explainer on &lt;a href="https://groundtruth.day/news//learn/reinforcement-learning-with-verifiable-rewards.html" rel="noopener noreferrer"&gt;reinforcement learning with verifiable rewards&lt;/a&gt; describes: the model does not need to be generally better, it needs an automatic grader that reflects the actual job. Fermisense cites other companies converging on the same playbook, including a legal-AI firm whose reinforcement-trained open model beat two frontier models on its own rubrics, and a support platform that post-trained a vertical model to handle high-volume ticket resolution more cheaply.&lt;/p&gt;

&lt;p&gt;At scale the arithmetic becomes the argument. At roughly 40 million decisions a day -- the volume Fermisense cites for large-catalog operations -- $0.50 per thousand versus $34 per thousand is the difference between about $7 million a year and about $500 million.&lt;/p&gt;

&lt;p&gt;Now the caveats, which are real and which Fermisense partly names itself. The $500 buys the final training run and nothing else; the simulator, taxonomy, policy rubric, episode generator and scorer represent the actual investment, and none of them is published. The frontier models were graded by Fermisense's scorer against Fermisense's policy preferences -- exactly the asymmetry that makes a specialist look good -- and the article does not identify which frontier configuration was the best baseline. Neither Hugging Face release carries a model card, and the training recipe, prompts, validation split and evaluation harness are absent, so nobody outside the company can reproduce any of it. Read as "a small &lt;a href="https://groundtruth.day/news//learn/open-weight-models.html" rel="noopener noreferrer"&gt;open-weight model&lt;/a&gt; now beats the frontier," this is unsupported. Read as "if you own a repeatable workflow and can score it automatically, buying the task knowledge is cheap," it is one of the better-documented data points of the year. The scorer is the moat, not the model.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://groundtruth.day/news/a-500-dollar-fine-tune-beat-five-frontier-models.html" rel="noopener noreferrer"&gt;Ground Truth&lt;/a&gt;, where every claim is checked against the primary source.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>finetuning</category>
      <category>openweights</category>
      <category>reinforcementlearning</category>
      <category>cost</category>
    </item>
    <item>
      <title>Fine-tuning open models in 2026: when it beats RAG, and how eCorpIT delivers it</title>
      <dc:creator>Manu Shukla</dc:creator>
      <pubDate>Tue, 28 Jul 2026 19:19:35 +0000</pubDate>
      <link>https://dev.to/mr_manushukla/fine-tuning-open-models-in-2026-when-it-beats-rag-and-how-ecorpit-delivers-it-27lh</link>
      <guid>https://dev.to/mr_manushukla/fine-tuning-open-models-in-2026-when-it-beats-rag-and-how-ecorpit-delivers-it-27lh</guid>
      <description>&lt;h1&gt;
  
  
  Fine-tuning open models in 2026: when it beats RAG, and how eCorpIT delivers it
&lt;/h1&gt;

&lt;p&gt;&lt;strong&gt;Summary.&lt;/strong&gt; Retrieval-augmented generation (RAG) is the right first choice for roughly 80% of enterprise LLM applications, because it lets you change source data without retraining and cite the documents behind an answer. Fine-tuning solves the other problem: it changes how a model behaves, not what it knows. In 2026 almost all practical fine-tuning uses LoRA or QLoRA, which freeze the base weights and train small adapters, cutting memory needs by more than 90% and making the old "1,000 examples minimum" rule obsolete, with 200 to 500 curated examples often enough for classification. The cost is small: a LoRA run on a 7 to 8 billion-parameter open model is $3 to $10 of GPU time, a 70B QLoRA job is $15 to $30, and a managed equivalent is about $25. The hard part is not the training; it is deciding whether to fine-tune at all, preparing the data, and evaluating the result. This is a capability eCorpIT builds for teams fine-tuning open models such as Llama, Qwen, DeepSeek, Kimi K3, and GLM.&lt;/p&gt;

&lt;p&gt;The question we hear most from founders and heads of AI is some version of "should we fine-tune, or is RAG enough?" The honest answer is that most teams reach for fine-tuning too early, pay in complexity, and get a result a good retrieval pipeline would have matched. But there is a real set of problems where fine-tuning is the only tool that works. This article draws that line, prices the work at 2026 rates, and explains how we deliver it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Fine-tune, RAG, prompt, or API: the decision
&lt;/h2&gt;

&lt;p&gt;Four options sit on a ladder of cost and control. Start at the cheapest that solves your problem, and only climb when it fails.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Approach&lt;/th&gt;
&lt;th&gt;Best for&lt;/th&gt;
&lt;th&gt;Data changes&lt;/th&gt;
&lt;th&gt;Upfront effort&lt;/th&gt;
&lt;th&gt;Ongoing cost&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Prompt engineering&lt;/td&gt;
&lt;td&gt;Quick behaviour changes, prototypes&lt;/td&gt;
&lt;td&gt;Any time&lt;/td&gt;
&lt;td&gt;Hours&lt;/td&gt;
&lt;td&gt;API tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;RAG&lt;/td&gt;
&lt;td&gt;Knowledge that updates; answers needing citations&lt;/td&gt;
&lt;td&gt;Update the index, no retrain&lt;/td&gt;
&lt;td&gt;Days to weeks&lt;/td&gt;
&lt;td&gt;Retrieval plus tokens&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Fine-tuning (LoRA)&lt;/td&gt;
&lt;td&gt;Fixed style, format, tone, narrow tasks&lt;/td&gt;
&lt;td&gt;Requires a new run&lt;/td&gt;
&lt;td&gt;Weeks; needs curated data&lt;/td&gt;
&lt;td&gt;Cheap inference, own hosting&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Full self-host plus fine-tune&lt;/td&gt;
&lt;td&gt;Data control, high volume, deep adaptation&lt;/td&gt;
&lt;td&gt;New run&lt;/td&gt;
&lt;td&gt;High; infrastructure and ops&lt;/td&gt;
&lt;td&gt;GPU hours&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;The rule of thumb that holds in production: RAG expands what a model knows, fine-tuning changes how it behaves, and the best systems are hybrids that use RAG for what changes and fine-tuning for what should not. If your problem is "the model does not know our latest policy," that is RAG. If it is "the model will not consistently produce our output format or house tone," that is fine-tuning.&lt;/p&gt;

&lt;h2&gt;
  
  
  When fine-tuning actually wins
&lt;/h2&gt;

&lt;p&gt;Four cases justify the extra work. The first is style, tone, and output structure that prompting cannot hold reliably across thousands of calls, such as a fixed JSON schema or a regulated document format. The second is narrow classification and extraction, where a small fine-tuned model beats a large general one on accuracy and cost. The third is distillation: fine-tuning a smaller open model on a frontier model's outputs to get most of the quality at a fraction of the latency and price. The fourth is compliance and domain language, where the model must adopt a specific vocabulary or refuse in a specific way every time. Outside these, RAG or better prompting is usually the cheaper answer, which is why our &lt;a href="https://ecorpit.com/ecorpit-rag-knowledge-assistant-service-india-2026/" rel="noopener noreferrer"&gt;RAG knowledge-assistant service&lt;/a&gt; is where many engagements start.&lt;/p&gt;

&lt;h2&gt;
  
  
  The methods, briefly
&lt;/h2&gt;

&lt;p&gt;LoRA (Low-Rank Adaptation) is the default in 2026. It freezes the original weights and injects small trainable matrices into each layer, so you train a few million parameters instead of billions. QLoRA adds 4-bit quantisation of the frozen base, which is why a 70B model fits on a single 80GB GPU and an 8B model trains on a consumer card, at a 1 to 3% quality cost versus full fine-tuning on most benchmarks. Supervised fine-tuning (SFT) on input-output pairs is the workhorse; preference tuning such as DPO aligns tone and refusals; continued pretraining adapts a model to a new domain corpus before task tuning. For most business problems, LoRA SFT on a few hundred to a few thousand clean examples is the whole job.&lt;/p&gt;

&lt;h2&gt;
  
  
  What it costs in 2026
&lt;/h2&gt;

&lt;p&gt;Fine-tuning is no longer the expensive part of an LLM project; data preparation and evaluation are. Verified July 2026 GPU rates on RunPod, Lambda, and Vast.ai run about $1.19 per hour for an A100 80GB, $1.99 for an H100, and roughly $0.31 for an RTX 4090.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Job&lt;/th&gt;
&lt;th&gt;DIY GPU cost&lt;/th&gt;
&lt;th&gt;Managed cost&lt;/th&gt;
&lt;th&gt;Hardware&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;LoRA on 7 to 8B model&lt;/td&gt;
&lt;td&gt;$3 to $10&lt;/td&gt;
&lt;td&gt;~$25&lt;/td&gt;
&lt;td&gt;RTX 4090 or one A100, 2 to 4 hours&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;QLoRA on 70B model&lt;/td&gt;
&lt;td&gt;$15 to $30&lt;/td&gt;
&lt;td&gt;Higher tier&lt;/td&gt;
&lt;td&gt;Single A100 or H100 80GB&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Managed LoRA SFT (Together, sub-16B)&lt;/td&gt;
&lt;td&gt;n/a&lt;/td&gt;
&lt;td&gt;~$0.48 per M tokens&lt;/td&gt;
&lt;td&gt;Provider-hosted&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;A managed 7B QLoRA job with 50,000 examples runs around $24.58 on Together AI and $25.60 on Fireworks, versus $3 to $10 to run it yourself on rented hardware. In Indian terms the training bill is trivial, a few hundred rupees of GPU time; the real investment is the engineering to build a clean dataset and an evaluation harness that proves the fine-tuned model is actually better. Where inference volume is high, pairing a fine-tune with &lt;a href="https://ecorpit.com/ecorpit-private-llm-deployment-service-india-2026/" rel="noopener noreferrer"&gt;private LLM deployment&lt;/a&gt; or a &lt;a href="https://ecorpit.com/kimi-k3-self-host-gpu-cost-api-break-even-2026/" rel="noopener noreferrer"&gt;self-hosted open model such as Kimi K3&lt;/a&gt; is what turns a cheap training run into a durable cost advantage.&lt;/p&gt;

&lt;h2&gt;
  
  
  Which open model to fine-tune
&lt;/h2&gt;

&lt;p&gt;The base model choice depends on the task and your hosting plan. Llama and Qwen have the widest tooling and adapter support, DeepSeek and GLM are strong on reasoning and code, and the largest open models such as Kimi K3 suit teams that need frontier-class quality in their own environment. A smaller 7 to 14B model is usually the right target for a fine-tune, because it is cheap to train, cheap to serve, and easy to iterate. If you are already weighing a migration off a paid API, our &lt;a href="https://ecorpit.com/ecorpit-llm-migration-cost-optimization-service-india-2026/" rel="noopener noreferrer"&gt;LLM migration and cost-optimisation service&lt;/a&gt; covers the base-model decision alongside the spend model.&lt;/p&gt;

&lt;h2&gt;
  
  
  How eCorpIT can help
&lt;/h2&gt;

&lt;p&gt;eCorpIT is a Gurugram-based, senior-led engineering organisation, founded in 2021 and certified for CMMI Level 5, MSME, and ISO 27001:2022. We deliver open-model fine-tuning end to end: the fine-tune-versus-RAG decision, dataset design and cleaning, LoRA or QLoRA training, an evaluation harness that measures the result against your real tasks, and deployment on your cloud or on a hosted endpoint. We design these systems aligned with DPDP Act 2023 requirements so training data and outputs are handled lawfully. A typical engagement starts with a short scoping review that decides whether fine-tuning is even the right tool, so you do not pay to train a model you did not need. To scope a domain-adaptation project, &lt;a href="https://ecorpit.com/contact-us/" rel="noopener noreferrer"&gt;contact us&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  FAQ
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Should I fine-tune or use RAG?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Use RAG when the model needs current knowledge it can cite, which covers about 80% of enterprise cases. Fine-tune when you need to change how the model behaves: a fixed output format, a consistent tone, a narrow classification task, or lower latency. Many production systems use both, with RAG for what changes.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How much does it cost to fine-tune an open model?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At 2026 rates, a LoRA run on a 7 to 8 billion-parameter model costs $3 to $10 of GPU time, and a 70B QLoRA job costs $15 to $30. Managed services charge about $25 for a comparable job. The larger cost is the engineering to prepare data and evaluate the result.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What is the difference between LoRA and QLoRA?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;LoRA freezes the base model and trains small adapter matrices, cutting memory needs by more than 90%. QLoRA adds 4-bit quantisation of the frozen base, so a 70B model fits on a single 80GB GPU and an 8B model trains on a consumer card, at a 1 to 3% quality cost versus full fine-tuning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How much data do I need to fine-tune?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Less than teams expect. The old rule of at least 1,000 examples no longer holds with LoRA and QLoRA. For classification and extraction, 200 to 500 well-curated examples is often enough. Data quality matters far more than volume; a small clean dataset beats a large noisy one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Which open model should I fine-tune?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It depends on the task and hosting. Llama and Qwen have the broadest tooling, DeepSeek and GLM are strong on reasoning and code, and the largest models such as Kimi K3 suit teams needing frontier quality in their own environment. A 7 to 14B model is usually the best target: cheap to train, cheap to serve, quick to iterate.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can fine-tuning reduce my inference cost?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Yes, through distillation. Fine-tuning a smaller open model on a frontier model's outputs can retain most of the quality at a fraction of the latency and price. Combined with self-hosting at high volume, that is where fine-tuning pays for itself, though the break-even depends on your traffic and hosting choice.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Is our training data safe under Indian law?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;eCorpIT designs fine-tuning pipelines aligned with the Digital Personal Data Protection Act 2023, so personal data in training sets is minimised, consented, and handled lawfully. Training on your own open-model deployment keeps data inside your environment, which is often the deciding factor for regulated Indian workloads.&lt;/p&gt;

&lt;h2&gt;
  
  
  References
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://winder.ai/rag-vs-fine-tuning-2026-decision-framework/" rel="noopener noreferrer"&gt;RAG vs fine-tuning in 2026: a decision framework for LLM teams, Winder.ai&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://blog.codercops.com/blog/fine-tuning-vs-rag-llm-decision-guide-2026" rel="noopener noreferrer"&gt;Fine-tuning vs RAG in 2026: a decision guide, CoderCops&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://bigdataboutique.com/blog/fine-tuning-llms-when-rag-isnt-enough" rel="noopener noreferrer"&gt;Fine-tuning LLMs in 2026: when RAG isn't enough, BigData Boutique&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://virtido.com/blog/llm-fine-tuning-enterprise-guide" rel="noopener noreferrer"&gt;LLM fine-tuning for enterprise: when RAG isn't enough, Virtido&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.spheron.network/blog/llm-fine-tuning-cost-2026-api-vs-renting-gpus" rel="noopener noreferrer"&gt;LLM fine-tuning cost 2026: API vs renting your own GPUs, Spheron&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://www.stratagem-systems.com/blog/lora-fine-tuning-cost-analysis-2026" rel="noopener noreferrer"&gt;LoRA fine-tuning cost in 2026: real GPU prices and QLoRA math, Stratagem Systems&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://computecomparison.com/guides/fine-tuning-llama-cost-guide" rel="noopener noreferrer"&gt;Fine-tuning Llama cost guide: 8B, 70B, and 405B, ComputeComparison&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://io.net/blog/llm-fine-tuning-budget-guide-gpu-costs-timelines-and-what-to-spend" rel="noopener noreferrer"&gt;LLM fine-tuning budget guide: GPU costs and timelines, io.net&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://tianpan.co/blog/2026-04-09-fine-tuning-economics-lora-peft-vs-prompt-engineering" rel="noopener noreferrer"&gt;Fine-tuning economics: LoRA and PEFT vs prompt engineering, TianPan&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://xenoss.io/blog/fine-tuning-llm-cost-optimization" rel="noopener noreferrer"&gt;Fine-tuning LLMs at scale: cost optimization guide, Xenoss&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://letsdatascience.com/blog/fine-tuning-llms-with-lora-and-qlora-complete-guide" rel="noopener noreferrer"&gt;Master LoRA and QLoRA: fine-tuning on consumer GPUs, Let's Data Science&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aidevdayindia.org/blogs/fine-tuning-llms-lora-qlora/fine-tuning-llms-lora-qlora.html" rel="noopener noreferrer"&gt;Fine-tuning LLMs with LoRA and QLoRA in 2026, AI Dev Day India&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;Last updated: 29 July 2026.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>finetuning</category>
      <category>lora</category>
      <category>rag</category>
      <category>openweightllm</category>
    </item>
    <item>
      <title>My $500 Open LLM Fine Tuning Cost Beat GPT-4</title>
      <dc:creator>Umair Bilal</dc:creator>
      <pubDate>Tue, 28 Jul 2026 06:23:21 +0000</pubDate>
      <link>https://dev.to/umair24171/my-500-open-llm-fine-tuning-cost-beat-gpt-4-3m82</link>
      <guid>https://dev.to/umair24171/my-500-open-llm-fine-tuning-cost-beat-gpt-4-3m82</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;This article was originally published on &lt;a href="https://www.buildzn.com/blog/my-500-open-llm-fine-tuning-cost-beat-gpt-4" rel="noopener noreferrer"&gt;BuildZn&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;GPT-4 API bills for FarahGPT were getting out of hand. Everyone talks about the magic of proprietary LLMs, but nobody explains how to keep your startup from bleeding cash once you scale. Figured it out the hard way, and now my AI agent is running on a custom model that cost me ~$500 in cloud GPU costs to fine-tune, outperforming GPT-4 on a critical task. This isn't just about saving money; it's about &lt;strong&gt;owning your performance stack.&lt;/strong&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I Ditched GPT-4 for a Custom LLM Training Budget
&lt;/h2&gt;

&lt;p&gt;FarahGPT, my AI gold trading system, needs to be precise. One core function: moderating user-generated advice. It’s a high-stakes domain; misleading info can cost someone serious money. Initially, GPT-4 handled this fine, but at 5,100+ users, the inference costs were becoming a significant line item. We were looking at over $150/month just for moderation calls, which is unsustainable for a bootstrapped SaaS.&lt;/p&gt;

&lt;p&gt;The problem wasn't GPT-4's general intelligence; it was its &lt;em&gt;general intelligence&lt;/em&gt;. It's great for broad tasks, but for specific, nuanced gold trading content moderation, it was often overkill and sometimes missed subtle context. I needed &lt;strong&gt;low cost llm performance&lt;/strong&gt; that was also highly specialized. That meant exploring &lt;strong&gt;cheap llm fine tuning&lt;/strong&gt; options. The decision was clear: either keep paying the OpenAI tax or invest in a &lt;strong&gt;custom llm training budget&lt;/strong&gt; for a purpose-built model. The latter won.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Core Idea: Fine-Tuning Mistral for AI Agent Model Cost Efficiency
&lt;/h2&gt;

&lt;p&gt;My target was a smaller, more focused model. &lt;code&gt;Mistral-7B-Instruct-v0.2&lt;/code&gt; was the obvious choice. It's fast, capable, and plays nice with quantization. The goal wasn't to build a general-purpose AI, but an agent specialized in understanding the subtleties of gold trading advice. This meant moving beyond basic supervised fine-tuning (SFT) and incorporating preference alignment.&lt;/p&gt;

&lt;p&gt;Turns out, for domain-specific tasks, you don't always need full-blown Reinforcement Learning from Human Feedback (RLHF) with Proximal Policy Optimization (PPO). Honestly, PPO is often overengineered for 90% of use cases. &lt;strong&gt;Direct Preference Optimization (DPO) is where it's at for faster iteration and cost-effectiveness.&lt;/strong&gt; It's simpler to implement, requires less compute, and often yields comparable results for specific alignment. This was crucial for keeping the &lt;strong&gt;open llm fine tuning cost&lt;/strong&gt; down while maximizing impact.&lt;/p&gt;

&lt;h2&gt;
  
  
  My Fine-Tuning Recipe: Mistral-7B-Instruct-v0.2 with DPO
&lt;/h2&gt;

&lt;p&gt;Here’s the exact breakdown of how I fine-tuned Mistral to outperform GPT-4 for FarahGPT's content moderation, all while keeping the &lt;strong&gt;ai agent model cost&lt;/strong&gt; minimal.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Data Preparation: The Real Gold Mine
&lt;/h3&gt;

&lt;p&gt;This is the most critical part. You can throw all the GPUs you want at a model, but if your data sucks, your model will too. For FarahGPT's moderation task, I needed:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  &lt;strong&gt;SFT Dataset:&lt;/strong&gt; ~5,000 examples of gold trading advice, labeled as &lt;code&gt;safe&lt;/code&gt; or &lt;code&gt;needs_review&lt;/code&gt;, with detailed reasons for &lt;code&gt;needs_review&lt;/code&gt;. This was built from anonymized user interactions and expert-curated examples.&lt;/li&gt;
&lt;li&gt;  &lt;strong&gt;DPO Dataset:&lt;/strong&gt; ~1,000 preference pairs. For each pair, I had a prompt (&lt;code&gt;user_message&lt;/code&gt;) and two model responses (&lt;code&gt;chosen&lt;/code&gt; and &lt;code&gt;rejected&lt;/code&gt;). &lt;code&gt;chosen&lt;/code&gt; was the desired moderation output (e.g., "This message is safe."), and &lt;code&gt;rejected&lt;/code&gt; was a less ideal or incorrect one (e.g., "This message contains misleading advice" when it was actually safe, or vice-versa, or just a poorly formatted response).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We used Hugging Face &lt;code&gt;Dataset&lt;/code&gt; objects. Here’s a simplified look at the structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;datasets&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Dataset&lt;/span&gt;

&lt;span class="c1"&gt;# Example SFT dataset structure
&lt;/span&gt;&lt;span class="n"&gt;sft_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Tell me about today&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s gold price movements.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completion&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;The gold price opened at $2350/oz, showing slight upward momentum due to geopolitical tensions.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Should I sell all my gold now and buy crypto?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;completion&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;This message contains misleading or high-risk financial advice. Consult a professional advisor.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="c1"&gt;# ... more examples
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;sft_dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;sft_data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Example DPO dataset structure
&lt;/span&gt;&lt;span class="n"&gt;dpo_data&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;What&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s the best strategy for day trading gold futures?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chosen&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Trading gold futures requires significant experience and capital. It&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s high risk. Consider consulting a financial expert before engaging in such activities.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rejected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Just buy calls when volatility is high; you&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;ll make a killing.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;
    &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Is gold still a safe haven in 2024?&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;chosen&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Gold&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;s role as a safe haven asset is influenced by various macroeconomic factors. Current indicators suggest continued stability amid global uncertainties.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;rejected&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Gold is always a safe bet, don&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;t listen to anyone who says otherwise.&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
    &lt;span class="p"&gt;}&lt;/span&gt;
    &lt;span class="c1"&gt;# ... more examples
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="n"&gt;dpo_dataset&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Dataset&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_list&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;dpo_data&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  2. Supervised Fine-Tuning (SFT): Getting the Basics Right
&lt;/h3&gt;

&lt;p&gt;First, get the model to understand the domain. I used the &lt;code&gt;trl&lt;/code&gt; library's &lt;code&gt;SFTTrainer&lt;/code&gt;. We loaded &lt;code&gt;Mistral-7B-Instruct-v0.2&lt;/code&gt; in 4-bit using &lt;code&gt;bitsandbytes&lt;/code&gt; and applied LoRA (&lt;code&gt;peft&lt;/code&gt;) for memory efficiency. This setup is crucial for &lt;strong&gt;cheap llm fine tuning&lt;/strong&gt; on consumer-grade or smaller cloud GPUs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;torch&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;BitsAndBytesConfig&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;trl&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;SFTTrainer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;peft&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;LoraConfig&lt;/span&gt;

&lt;span class="c1"&gt;# Load base model and tokenizer
&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;mistralai/Mistral-7B-Instruct-v0.2&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoTokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;pad_token&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;eos_token&lt;/span&gt; &lt;span class="c1"&gt;# Important for Mistral
&lt;/span&gt;
&lt;span class="n"&gt;bnb_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;BitsAndBytesConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;load_in_4bit&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bnb_4bit_quant_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;nf4&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bnb_4bit_compute_dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bfloat16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bnb_4bit_use_double_quant&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;False&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;model&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;AutoModelForCausalLM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;from_pretrained&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model_name&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;quantization_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;bnb_config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;torch_dtype&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;torch&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;bfloat16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;device_map&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;auto&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;use_cache&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="bp"&gt;False&lt;/span&gt;

&lt;span class="c1"&gt;# LoRA configuration
&lt;/span&gt;&lt;span class="n"&gt;peft_config&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;LoraConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;lora_alpha&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;16&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;lora_dropout&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;bias&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;none&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;task_type&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;CAUSAL_LM&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;target_modules&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;q_proj&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;k_proj&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;v_proj&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;o_proj&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt; &lt;span class="c1"&gt;# Mistral specific
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="c1"&gt;# Training arguments
&lt;/span&gt;&lt;span class="n"&gt;training_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SFTTrainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;train_dataset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;sft_dataset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;peft_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;peft_config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;dataset_text_field&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;prompt&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Adjust based on your dataset structure
&lt;/span&gt;    &lt;span class="n"&gt;max_seq_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;transformers&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TrainingArguments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
        &lt;span class="n"&gt;output_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./results_sft&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;num_train_epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;per_device_train_batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;gradient_accumulation_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;gradient_checkpointing&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;optim&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;paged_adamw_8bit&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;logging_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;25&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;save_strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;epoch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;learning_rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;2e-4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;fp16&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="n"&gt;seed&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;42&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;),&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;trainer_sft&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;SFTTrainer&lt;/span&gt;&lt;span class="p"&gt;(...)&lt;/span&gt; &lt;span class="c1"&gt;# Use the defined args and model
&lt;/span&gt;&lt;span class="n"&gt;trainer_sft&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  3. Direct Preference Optimization (DPO): Aligning with Intent
&lt;/h3&gt;

&lt;p&gt;After SFT, the model could generate relevant responses. But &lt;code&gt;relevant&lt;/code&gt; isn't always &lt;code&gt;correct&lt;/code&gt; or &lt;code&gt;safe&lt;/code&gt; in a moderation context. DPO fine-tunes the model further using preference pairs, nudging it towards desired behaviors without a separate reward model. This is key for &lt;strong&gt;ai agent model cost&lt;/strong&gt; control and targeted alignment.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;trl&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;DPOTrainer&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;transformers&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;TrainingArguments&lt;/span&gt;

&lt;span class="c1"&gt;# Load the SFT-trained model or its adapter
# For DPO, you typically load the SFT model as the 'ref_model' and the 'model'
# You would save the SFT adapter and load it here.
# For simplicity, let's assume 'model' is the SFT-trained model from above.
&lt;/span&gt;
&lt;span class="c1"&gt;# DPO Training arguments
&lt;/span&gt;&lt;span class="n"&gt;dpo_training_args&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;TrainingArguments&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;output_dir&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;./results_dpo&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;num_train_epochs&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;per_device_train_batch_size&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;gradient_accumulation_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;learning_rate&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;5e-5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;fp16&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;True&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;logging_steps&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;save_strategy&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;epoch&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;dpo_trainer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nc"&gt;DPOTrainer&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;model&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# SFT-trained model (or base model + SFT adapter merged)
&lt;/span&gt;    &lt;span class="n"&gt;ref_model&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="bp"&gt;None&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# If you want to use a separate reference model (e.g., the original SFT model without DPO), otherwise it's created from 'model'
&lt;/span&gt;    &lt;span class="n"&gt;args&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dpo_training_args&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;train_dataset&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;dpo_dataset&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;tokenizer&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;peft_config&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;peft_config&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Apply LoRA again for DPO
&lt;/span&gt;    &lt;span class="n"&gt;max_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;512&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="n"&gt;max_target_length&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mi"&gt;128&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# Max length for chosen/rejected responses
&lt;/span&gt;    &lt;span class="n"&gt;beta&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;# DPO hyperparameter: controls the strength of the preference signal
&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="n"&gt;dpo_trainer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;train&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;A Note on &lt;code&gt;ref_model=None&lt;/code&gt;:&lt;/strong&gt; This creates the reference model by making a copy of the policy model before training begins. For minimal &lt;strong&gt;open llm fine tuning cost&lt;/strong&gt; and simpler setups, this is often sufficient. If you need stricter adherence to a pre-DPO baseline, you'd load a distinct &lt;code&gt;ref_model&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Cloud GPU Costs: Reaching the ~$500 Total
&lt;/h3&gt;

&lt;p&gt;The "reaching ~$500 total" was the overall project cost to get this model to production-ready state, primarily driven by GPU compute and the critical, often-underestimated, data aspect.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt; &lt;strong&gt;Initial SFT &amp;amp; Experimentation (Cloud GPU):&lt;/strong&gt; ~80 hours on an A10 (24GB) @ ~$0.80/hr on a platform like RunPod or Vast.ai. &lt;strong&gt;Total: ~$64.&lt;/strong&gt; This covered several SFT runs, hyperparameter tuning, and early debugging.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Successful DPO Run (Cloud GPU):&lt;/strong&gt; ~40 hours on an A100 (40GB) spot instance @ ~$1.20/hr. &lt;strong&gt;Total: ~$48.&lt;/strong&gt; This was for the final, effective DPO training.&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Validation &amp;amp; Inference Setup (Cloud GPU - T4):&lt;/strong&gt; ~100 hours on a T4 (16GB) @ ~$0.50/hr on a small cloud VM for testing deployment, early inference, and load testing. &lt;strong&gt;Total: ~$50.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt; &lt;strong&gt;Data Labeling &amp;amp; Augmentation (Internal Allocation/Bounties):&lt;/strong&gt; This is the silent killer. Generating those 1,000 high-quality DPO preference pairs and refining the SFT dataset wasn't free. I allocated roughly &lt;strong&gt;$300&lt;/strong&gt; worth of time/resources for this crucial part.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;strong&gt;Total Project Cost: ~$462.&lt;/strong&gt; This shows how a strategic &lt;strong&gt;custom llm training budget&lt;/strong&gt; can be incredibly efficient.&lt;/p&gt;

&lt;h2&gt;
  
  
  What I Got Wrong First
&lt;/h2&gt;

&lt;p&gt;My biggest screw-up was in the DPO dataset. I initially thought, "More data is better!" and started generating preference pairs where the &lt;code&gt;rejected&lt;/code&gt; response was simply "less preferred" or slightly off-topic, not necessarily &lt;em&gt;wrong&lt;/em&gt; or &lt;em&gt;harmful&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Problem:&lt;/strong&gt; The model started to overcorrect. It would reject genuinely nuanced gold trading advice that wasn't strictly black-and-white. For instance, if a user asked about short-term volatility, and the "chosen" response was cautious advice, my "rejected" response might have been a slightly more aggressive but still plausible trading idea. The model then learned to be &lt;em&gt;too&lt;/em&gt; conservative, sometimes flagging completely benign information as "needs_review," leading to false positives.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;The Fix:&lt;/strong&gt; I implemented a stricter human-in-the-loop review specifically for the &lt;code&gt;rejected&lt;/code&gt; examples in the DPO dataset. For about 20% of the DPO pairs, I manually verified that the &lt;code&gt;rejected&lt;/code&gt; response was genuinely problematic (e.g., overtly misleading, promoting unethical practices, or extremely poor quality) rather than just "not the best." This ensured the model&lt;/p&gt;

</description>
      <category>llm</category>
      <category>finetuning</category>
      <category>opensourceai</category>
      <category>aicostoptimization</category>
    </item>
  </channel>
</rss>
