Fine-Tuning Language Models with Reinforcement Learning with Michael Albada ๐Ÿ”— **Source:** [Fine-Tuning Language Models with Reinforcement Learning with Michael Albada](https://www.youtube.com/watch?v=TUynF91MKAU) > [!note]+ Document Notes > tags: [fine-tuning, reinforcement-learning, language-models, machine-learning] > author: Michael Albada > source: YouTube > reference: https://www.youtube.com/watch?v=TUynF91MKAU > date created: 2024-12-19 12:00 > > # ๐Ÿท๏ธ Title: Fine-Tuning Language Models with Reinforcement Learning > <!-- deep-read:sections start --> ## ๐Ÿงฐ Action Inbox - [H1] Evaluate open-weight models for your use case โ€” Consider cost vs performance tradeoffs #evaluation - [H2] Implement reinforcement learning with verifiable rewards for function calling โ€” Use Glaive dataset as starting point #implementation - [H3] Set up fine-tuning pipeline with production feedback loop โ€” Mine failure modes from production data #optimization ## ๐Ÿงญ Table of Contents - [๐Ÿ“ Summary](#-summary) - [๐Ÿ“– Main Content](#-main-content) - [๐Ÿ—’๏ธ Notes](#๏ธ-notes) - [๐Ÿ“š References](#-references) - [๐Ÿ—ฃ๏ธ Paraphrase](#๏ธ-paraphrase) - [๐Ÿ“ฐ Newsletter](#-newsletter) - [โœ… Action Items](#-action-items) - [๐Ÿงช Hypotheses](#-hypotheses) - [๐Ÿ“Š Methodology](#-methodology) - [โ“ Questions](#-questions) - [๐Ÿ”ฎ Future Research](#-future-research) - [๐Ÿ’ก Implications](#-implications) - [๐Ÿง  Learning Styles Assessment](#-learning-styles-assessment) - [๐Ÿ“Š Accessibility Assessment](#-accessibility-assessment) - [๐ŸŒ DEIB Assessment](#-deib-assessment) - [โœ… Logical Validity](#-logical-validity) - [๐Ÿ›ก๏ธ DARVO Analysis](#-darvo-analysis) - [๐ŸŽฏ Conclusion](#-conclusion) ### ๐Ÿ”— References - [Glaive Function Calling V2 Dataset](https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2) - [Hugging Face Transformers Library](https://huggingface.co/transformers/) ## ๐Ÿ“ Summary - Michael Albada presents fine-tuning with reinforcement learning as a method to improve generative AI reliability - Open-weight models are rapidly closing the gap with proprietary models while offering significant cost advantages - Small models (<4B parameters) have dramatically improved, narrowing performance gaps with larger models - Fine-tuning becomes cost-effective at scale and provides strategic independence from API providers - Reinforcement learning with verifiable rewards enables precise control over model behavior for structured tasks ## ๐Ÿ“– Main Content The presentation argues that while proprietary models like GPT-4 and Gemini lead performance benchmarks, open-weight models are lagging by only months in frontier intelligence. This creates opportunities for organizations to achieve near-frontier performance at dramatically lower costs through fine-tuning. The cost of intelligence is approaching zero as small models improve and catch up to larger ones. Fine-tuning offers strategic benefits including model ownership, privacy, security, and the ability to optimize for domain-specific tasks that may not be priorities for large research labs. The speaker emphasizes that fine-tuning works best when combined with production feedback loops to continuously improve model performance on real-world failure modes. ## ๐Ÿ—’๏ธ Notes #### โฑ๏ธ [00:00](https://youtu.be/TUynF91MKAU?t=0) โ€” [H1] Introduction to Fine-Tuning for AI Reliability - Key idea: Fine-tuning is a powerful but challenging way to improve generative AI reliability - Evidence: "Fine-tuning is a really powerful way to do that. Now, it's not the easiest way, but it is one of the most robust and most reliable" #### โฑ๏ธ [02:15](https://youtu.be/TUynF91MKAU?t=135) โ€” [H2] Open-Weight Models Are Rapidly Improving - Key idea: Open-weight models lag proprietary models by only months, not years - Evidence: "The openweight models are never that far behind and they're really lagging by just months on frontier intelligence" #### โฑ๏ธ [04:30](https://youtu.be/TUynF91MKAU?t=270) โ€” [H2] Top Open-Weight Models Compete in Top 10 - Key idea: Open-weight models now place in top 10 performance leaderboards - Evidence: "GPT OSS 120 billion and Quen 3 235 billion are now placing in the top 10" #### โฑ๏ธ [05:45](https://youtu.be/TUynF91MKAU?t=345) โ€” [H1] Small Models Are Catching Up Dramatically - Key idea: Models under 4B parameters have tripled performance since March - Evidence: "These tiny models, less than four billion parameters... were scoring at a level of 15... Look at these leaps up to 40" #### โฑ๏ธ [08:20](https://youtu.be/TUynF91MKAU?t=500) โ€” [H2] Performance Varies Widely by Use Case - Key idea: Expensive models may underperform cheap ones for specific applications - Evidence: "You can spend a lot of money for a really expensive model that doesn't work all that well for your use case" #### โฑ๏ธ [10:10](https://youtu.be/TUynF91MKAU?t=610) โ€” [H1] Strategic Trade-offs: Proprietary vs Fine-Tuned - Key idea: Proprietary models offer convenience but create strategic dependence and commoditization - Evidence: "If all of the companies are depending on a small number of research labs... there's very little differentiation" #### โฑ๏ธ [12:30](https://youtu.be/TUynF91MKAU?t=750) โ€” [H2] Fine-Tuning Enables Model Ownership and Control - Key idea: Fine-tuning provides privacy, security, and performance optimization for specific domains - Evidence: "It allows you to own your own model... get outperformance on your tasks" #### โฑ๏ธ [14:45](https://youtu.be/TUynF91MKAU?t=885) โ€” [H2] RAG vs Fine-Tuning Trade-offs - Key idea: RAG works for dynamic context, fine-tuning for repeated instructions and reasoning - Evidence: "If you find yourself continually adding similar information... move over to fine-tuning" #### โฑ๏ธ [16:20](https://youtu.be/TUynF91MKAU?t=980) โ€” [H3] LoRA Reduces Fine-Tuning Complexity - Key idea: Low-rank adaptation makes fine-tuning more efficient by updating fewer parameters - Evidence: "We freeze the vast majority of the weights in the model and we only learn that low rank adaptation" #### โฑ๏ธ [18:00](https://youtu.be/TUynF91MKAU?t=1080) โ€” [H2] Quality Over Quantity in Training Data - Key idea: A few dozen to hundred examples can dramatically improve domain performance - Evidence: "Just a few dozen to a few hundred examples can really dramatically improve performance on a domain" #### โฑ๏ธ [20:15](https://youtu.be/TUynF91MKAU?t=1215) โ€” [H1] Reinforcement Learning with Verifiable Rewards - Key idea: RL enables precise control over model behavior through grading every output - Evidence: "This is a way for us to tell the model this was correct and this is wrong" #### โฑ๏ธ [22:30](https://youtu.be/TUynF91MKAU?t=1350) โ€” [H3] Group Relative Policy Optimization - Key idea: GRPO is more efficient than PPO by eliminating the need for value models - Evidence: "We're able to do away with the value model and instead we compute multiple rollouts" #### โฑ๏ธ [24:45](https://youtu.be/TUynF91MKAU?t=1485) โ€” [H3] Function Calling Example Implementation - Key idea: Compound reward functions can optimize for JSON validity, correct functions, and parameters - Evidence: "Creating valid JSON outputting the correct function for the current context and additional rewards for each of the arguments" #### โฑ๏ธ [26:00](https://youtu.be/TUynF91MKAU?t=1560) โ€” [H2] Watch for Reward Hacking - Key idea: Models may find ways to achieve high rewards without solving intended problems - Evidence: "Always watch out for rapid spikes in the reward which can indicate reward hacking" #### โฑ๏ธ [27:30](https://youtu.be/TUynF91MKAU?t=1650) โ€” [H1] Fine-Tuning as Competitive Moat - Key idea: Major model providers use fine-tuning internally despite promoting API-only approaches - Evidence: "When it comes time for them to design and ship their own product experiences, most of the time they're doing additional fine-tuning" ## ๐Ÿ“š References - [Glaive Function Calling V2 Dataset](https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2) - [Hugging Face Transformers Library](https://huggingface.co/transformers/) - [Building Applications with AI Agents - O'Reilly](https://www.oreilly.com/) ## ๐Ÿ—ฃ๏ธ Paraphrase - Open-source language models are quickly approaching the performance of proprietary models while offering significant cost savings and customization opportunities - Organizations should start with API-based proprietary models but consider fine-tuning for strategic independence, cost optimization, and domain-specific performance improvements - Reinforcement learning with verifiable rewards provides precise control over model behavior, making it especially valuable for structured tasks like function calling and code generation ## ๐Ÿ“ฐ Newsletter ๐Ÿš€ **Fine-Tuning: Your Secret Weapon for AI Reliability** The AI landscape is shifting dramatically! While everyone focuses on the latest GPT releases, open-weight models are quietly closing the gapโ€”lagging by just months, not years. Small models under 4B parameters have **tripled** their performance since March alone. **Why This Matters for Your Projects:** - Strategic independence from API providers - Dramatic cost reductions at scale - Domain-specific performance optimization - Enhanced privacy and security control **Getting Started:** Begin with proprietary APIs for rapid prototyping, then consider fine-tuning when you find yourself repeatedly adding similar instructions or need better performance on specialized tasks. **Pro Tip:** Mine your production failures for training dataโ€”it's one of the most effective ways to improve model reliability over time. Resources: [Hugging Face Transformers](https://huggingface.co/transformers/), [Glaive Function Calling Dataset](https://huggingface.co/datasets/glaiveai/glaive-function-calling-v2), [Michael's Book on AI Agents](https://www.oreilly.com/) ## โœ… Action Items #### DevRel - Education: Create workshops on fine-tuning vs API trade-offs, LoRA implementation tutorials - Developer experience: Develop fine-tuning starter templates and evaluation frameworks - Community management: Host fine-tuning office hours, curate open-weight model recommendations #### OSPO - Software Inventory: Catalog open-weight model dependencies and licensing requirements - Security Management: Establish guidelines for fine-tuning with production data - Developer Support: Provide training on model evaluation and selection criteria #### Community - Contributors: Guide fine-tuning contributions to model improvement projects - Maintainers: Support governance for community-driven model training initiatives ## ๐Ÿงช Hypotheses - Organizations using fine-tuned open-weight models will achieve 70% cost reduction while maintaining 90% performance of proprietary APIs - Production feedback loops in fine-tuning will improve task-specific performance by 40% within 6 months - Small model performance improvements will enable 80% of AI applications to run locally by 2025 - Fine-tuning adoption will accelerate when cost savings exceed 10x for high-volume applications ### ๐Ÿ“Š Methodology - Compare fine-tuned vs API costs across different query volumes and model sizes - Measure performance improvements from production feedback integration - Track open-weight model benchmark progression vs proprietary model releases ### โ“ Questions - At what query volume does fine-tuning become cost-effective for different model sizes? - How can organizations systematically identify when fine-tuning will outperform prompt engineering? - What governance frameworks are needed for responsible fine-tuning with user data? ### ๐Ÿ”ฎ Future Research - Automated fine-tuning pipeline optimization based on production metrics - Cross-domain transfer learning techniques for specialized applications - Efficient methods for combining multiple LoRA adapters ### ๐Ÿ’ก Implications - Practice: Teams need fine-tuning evaluation capabilities alongside prompt engineering skills - Policy: Organizations require data governance for model training and deployment - Security: Fine-tuning creates new attack vectors requiring specialized security measures - Education: AI curriculum must include model training alongside API consumption - Funding: Budget planning needs to account for infrastructure vs API cost trade-offs ### ๐Ÿง  Learning Styles Assessment Reading level estimate: Flesch-Kincaid Grade Level 12 #### ๐Ÿ‘€ Visual learners - Present: Performance charts, cost comparison graphs, architecture diagrams - Improve: Fine-tuning workflow visualizations, decision tree for model selection #### ๐Ÿ”Š Aural learners - Present: Full video presentation with clear narration - Improve: Audio summary of key decision points, podcast-style discussion #### ๐Ÿ—ฃ๏ธ Verbal learners - Present: Clear definitions of LoRA, GRPO, technical terminology with examples - Improve: Analogies for reinforcement learning concepts, story-driven examples #### ๐Ÿงฉ Kinesthetic learners - Present: Code examples, Hugging Face implementation guides - Improve: Interactive Jupyter notebooks, hands-on fine-tuning lab exercises #### ๐Ÿง  Logical learners - Present: Performance benchmarks, cost-benefit analysis, algorithmic comparisons - Improve: Decision matrices for model selection, ROI calculators #### ๐Ÿง‘โ€๐Ÿคโ€๐Ÿง‘ Social learners - Present: References to community datasets, collaborative training approaches - Improve: Fine-tuning study groups, peer review processes for model evaluation #### ๐Ÿง˜โ€โ™€๏ธ Solitary learners - Present: Self-contained code examples, independent evaluation criteria - Improve: Self-assessment rubrics, personal fine-tuning project templates #### ๐ŸŒฟ Naturalistic learners - Present: Evolution of model capabilities over time, ecosystem interactions - Improve: Model lifecycle thinking, sustainability considerations for training ### ๐Ÿ“Š Accessibility Assessment #### Screen reader semantics - Present: Clear heading structure, descriptive chart alt text - Improve: Detailed descriptions of performance graphs, table summaries #### Keyboard navigation - Present: Standard video controls, accessible slides - Improve: Transcript with timestamp navigation, keyboard-friendly code examples #### Contrast and readability - Present: High contrast slides, readable font sizes - Improve: Ensure chart colors meet accessibility standards #### Text resizing and reflow - Present: Scalable slide content, responsive code formatting - Improve: Test at 200% zoom, ensure no content clipping #### Media and captions - Present: Full video with clear audio - Improve: Complete transcript, visual description of charts #### Forms and interactions - Present: Standard video interface - Improve: Accessible code exploration tools, interactive examples ### ๐ŸŒ DEIB Assessment #### Cultural breadth - Present: Technical focus with global applicability - Improve: Examples from diverse industries, multilingual model considerations #### Inclusive language - Present: Gender-neutral technical language, defined jargon - Improve: Plain language summary, avoid assumptions about infrastructure access #### Neurodiversity support - Present: Structured presentation, consistent formatting - Improve: Clear section breaks, summarized key points #### Representation - Present: Technical presentation focused on methodology - Improve: Diverse use case examples, varied industry applications #### Psychological safety - Present: Encouraging tone about starting with simple approaches - Improve: Acknowledge learning curve, provide beginner-friendly entry points ### โœ… Logical Validity #### Strong reasoning - Deductive strength: Logical progression from cost analysis to fine-tuning recommendations - Inductive strength: Performance trends support future improvement predictions - Causal reasoning: Clear links between training approaches and performance outcomes - Analogical strength: Effective comparisons between LoRA and full fine-tuning #### Fallacies - Appeal to authority: Relies heavily on benchmark performance without discussing limitations - False dichotomy: Presents proprietary vs fine-tuned as binary choice rather than spectrum - Hasty generalization: Small model improvements may not apply to all domains equally #### Tone of voice - Overall tone: Enthusiastic and encouraging while maintaining technical precision --- ## Full Transcript [00:00] I am happy today to be presenting on<br>[00:02] fine-tuning models with reinforcement<br>[00:04] learning. And I think one of the main<br>[00:06] desires here is to find ways to improve<br>[00:09] the reliability of our generative AI<br>[00:11] applications and systems. And<br>[00:14] fine-tuning is a really powerful way to<br>[00:17] do that. Now, it's not the easiest way,<br>[00:20] but it is one of the most robust and<br>[00:22] most reliable, and it's one that I think<br>[00:24] is going to be receiving more attention<br>[00:26] moving forward. So, that sets us up<br>[00:28] great. And let's go ahead and dive in.<br>[00:32] So I want to start with a little bit of<br>[00:34] context. So open weight models are<br>[00:37] improving rapidly and so much of the<br>[00:40] excitement over the last couple years<br>[00:42] has been led by these incredible<br>[00:44] research labs releasing better and more<br>[00:47] compelling frontier models month after<br>[00:49] month. And we're seeing incredible leaps<br>[00:52] and bounds on a wide range of<br>[00:54] benchmarks. And while there's a gap<br>[00:56] between benchmarks and our real world<br>[00:58] applications, we are seeing improvements<br>[01:00] in hands-on applications as well. But<br>[01:04] there's a quieter story that's also<br>[01:06] happening that I don't think is<br>[01:07] receiving enough attention and I think<br>[01:10] has very profound implications.<br>[01:13] We have seen openweight models also<br>[01:16] improving by absolute leaps and bounds.<br>[01:20] And when I say open weight, I mean<br>[01:22] models that have been trained and the<br>[01:25] full artifact has been released publicly<br>[01:28] onto the internet. They are free for you<br>[01:31] to download and for you to host, you to<br>[01:33] serve. And you can see on this chart<br>[01:36] that even though the proprietary models<br>[01:38] have stayed out and ahead, the<br>[01:41] openweight models are never that far<br>[01:44] behind and they're really lagging by<br>[01:45] just months on frontier intelligence.<br>[01:48] And so when you add that up over time<br>[01:50] and you consider that compounding, this<br>[01:53] means that we have access to<br>[01:55] nearfrontier performance and<br>[01:57] intelligence for an absolute fraction of<br>[02:00] the cost. The other incredible benefit<br>[02:03] to this is these openweight models are<br>[02:05] accessible for us to be able to<br>[02:07] fine-tune. So you can start with a<br>[02:10] really high level of performance and<br>[02:13] then apply fine-tuning on top of that.<br>[02:18] And<br>[02:19] these openweight models are highly<br>[02:21] competitive and I'll admit they are not<br>[02:24] the top performing models today. And so<br>[02:26] this is pulled from a very recent uh<br>[02:28] leaderboard. And you can see that GPT 5<br>[02:30] and Gro 4 and Gemini 2.5 still dominate<br>[02:33] the leaderboard. But I want to<br>[02:35] illustrate the GPT OSS 120 billion and<br>[02:39] Quen 3 235 billion are now placing in<br>[02:42] the top 10. So this is an incredibly<br>[02:45] competitive space and while we<br>[02:48] anticipate the proprietary models to<br>[02:50] continue to lead and continue to really<br>[02:52] push the frontier, we should expect<br>[02:55] these openweight models to also continue<br>[02:57] to improve. And so this puts an<br>[02:59] incredible amount of intelligence at our<br>[03:01] fingertips and we really are approaching<br>[03:03] a point where the cost of intelligence<br>[03:06] is plummeting and is gradually<br>[03:08] approaching towards zero.<br>[03:12] And the other story here is that small<br>[03:15] models are catching up. So yes, the best<br>[03:18] performing openweight models I just<br>[03:20] showed you are 120 billion parameters<br>[03:22] and 235 billion parameters. Those are<br>[03:25] large. Those are not easy to host.<br>[03:28] But I'd like you to take a look at this<br>[03:31] chart and you will see that the gap that<br>[03:33] we used to see between these large and<br>[03:36] small models has really closed. And the<br>[03:41] improvements that we've seen on these<br>[03:42] large models over the last couple years<br>[03:44] is really impressive. But look at what's<br>[03:47] happened since even March of this year.<br>[03:50] These tiny models, less than four<br>[03:53] billion parameters, used to be really<br>[03:55] hard to work with, right? They were<br>[03:56] scoring at a level of 15 on this<br>[04:00] composite intelligent index. Look at<br>[04:02] these leaps up to 40. That's really<br>[04:05] where the largest models were performing<br>[04:08] in January of this year. So that gap is<br>[04:11] narrowing and this is a whole sequence<br>[04:13] of of innovations that are continuing to<br>[04:17] drive this. We're getting better at<br>[04:18] distillation. We're getting better at<br>[04:20] quantization. And as we are continuing<br>[04:23] to advance the frontier models, we're<br>[04:25] finding better ways to then extract that<br>[04:28] and condense that into smaller and<br>[04:30] smaller form factors. And this is<br>[04:31] exciting. This is moving towards more<br>[04:33] intelligence that we can deploy on the<br>[04:35] edge on mobile devices on laptops and so<br>[04:39] expect this trend to continue.<br>[04:42] Now this does not mean that we're<br>[04:45] getting to universal high performance<br>[04:48] across our models and that your price<br>[04:51] performance and value may vary widely.<br>[04:54] And so this is my buyer beware slide.<br>[04:57] You can spend a lot of money for a<br>[05:00] really expensive model that doesn't work<br>[05:02] all that well for your use case. You can<br>[05:05] also find really affordable models that<br>[05:08] will work really well for your use case.<br>[05:10] And similarly with the openw weight<br>[05:12] models, I'm not saying that all of them<br>[05:14] are good. Many of them are not. And so<br>[05:17] you do need to be a little cautious. But<br>[05:19] if you are willing to pay attention and<br>[05:22] track the leaderboards and take some of<br>[05:23] the most promising models and assess<br>[05:25] them on your use case, you can find high<br>[05:28] performing models that will work very<br>[05:30] well for your problems and your context<br>[05:33] at a tiny fraction of price. And so this<br>[05:36] is good. This is going to put more<br>[05:38] competition on the labs to be able to<br>[05:41] keep providing higher quality at lower<br>[05:43] price. And remember that benchmarks do<br>[05:46] not tell the whole story. and many of<br>[05:48] the labs are perhaps overoptimizing for<br>[05:51] the benchmarks. So make sure that you<br>[05:53] evaluate for your use case. You might<br>[05:55] actually see widely different uh<br>[05:57] performance across the different models<br>[05:59] due to different training recipes and<br>[06:01] different training data. So evaluation<br>[06:04] will be your friend.<br>[06:06] So let's stop and think a bit about<br>[06:09] choosing a proprietary versus going<br>[06:12] after a fine-tuned model. So I recommend<br>[06:15] you always start with proprietary<br>[06:18] models. We now have access to frontier<br>[06:20] intelligence with a simple API call. You<br>[06:23] don't need to worry about deployment.<br>[06:24] You don't need to worry about training.<br>[06:26] And what this is doing is enabling<br>[06:28] greater capabilities and intelligence<br>[06:30] for a much wider range of teams and<br>[06:33] companies. You no longer need a giant<br>[06:35] machine learning organization and all of<br>[06:39] that infrastructure that it used to take<br>[06:41] to be able to do machine learning at<br>[06:43] scale. This is bringing intelligence and<br>[06:45] making it much more accessible.<br>[06:47] But it does come with some costs. It<br>[06:49] comes with this strategic dependence and<br>[06:53] you do at least get lower costs at<br>[06:55] scale. I'd also like to refer back to a<br>[06:58] fantastic point that Chip Wyn made in<br>[07:00] her opening keynote that if all of the<br>[07:04] companies are depending on a small<br>[07:06] number of research labs and a small<br>[07:08] number of APIs,<br>[07:10] there's very little differentiation.<br>[07:12] That's a commoditization layer. And so,<br>[07:15] yes, you can do additional work with<br>[07:17] context engineering and rag to better<br>[07:19] personalize those results. But if<br>[07:22] increasingly the model is the product,<br>[07:24] then choosing to take that significant<br>[07:27] of strategic dependence, choosing to to<br>[07:30] accept that degree of commoditization is<br>[07:32] a really important strategic question<br>[07:34] that each organization needs to think<br>[07:36] through carefully.<br>[07:38] Now, making that decision to move over<br>[07:40] to fine-tuning. It comes with a lot of<br>[07:42] benefits. It allows you to own your own<br>[07:45] model. It allows you to adjust and<br>[07:47] modify it to make sure that it works<br>[07:49] well for your use case. It comes with<br>[07:52] some ongoing training responsibilities<br>[07:54] and deployment overhead of course, but<br>[07:56] you also get more privacy and more<br>[07:58] security if you handle it appropriately.<br>[08:01] Uh it also allows you to get<br>[08:03] outperformance on your tasks. It's<br>[08:05] possible that you're working on<br>[08:06] something that is not that important to<br>[08:09] the big research labs. If you need<br>[08:11] better performance on a domain specific<br>[08:13] language, if you need better performance<br>[08:15] on your particular area, going to<br>[08:18] fine-tuning can allow you to really<br>[08:21] focus and drive performance on that task<br>[08:23] that's more important to you than anyone<br>[08:25] else. It gives you much greater control<br>[08:27] over knowledge and style and it can give<br>[08:31] you lower costs at higher scale. Again,<br>[08:34] if you're starting out small number of<br>[08:36] API calls, stick with the big models.<br>[08:39] But as you start feeling the pain of<br>[08:42] cutting larger and larger checks out to<br>[08:44] the big model providers, then it might<br>[08:47] be time to start making the investment<br>[08:49] into openw weight models and fine-tune<br>[08:52] models that might work better for your<br>[08:54] use case.<br>[08:56] Now, let's talk about the difference<br>[08:58] between rag and fine-tuning. Rag is a<br>[09:01] fantastic technique because it allows<br>[09:03] you to adapt very quickly. It allows you<br>[09:05] to bring in your dynamic context, your<br>[09:08] dynamic information, and it allows you<br>[09:11] to pull quick API calls, say pull in<br>[09:14] information about that particular case,<br>[09:16] that particular customer. It allows you<br>[09:18] to pull in real time data. And so that<br>[09:21] adaptability is really great and it<br>[09:23] comes with no upfront additional<br>[09:25] training investment. It's great for<br>[09:27] lower query volume and it's also very<br>[09:29] good for knowledge heavy tasks. allows<br>[09:31] you to augment the domain the knowledge<br>[09:34] and awareness that is uh been trained<br>[09:37] into those model parameters.<br>[09:40] But if you find yourself continually<br>[09:42] adding similar information, similar<br>[09:45] instructions, um I think this is<br>[09:48] probably an underappreciated aspect of<br>[09:50] these uh language model and generative<br>[09:52] AI applications and systems is in<br>[09:54] practice I see prompts grow over time.<br>[09:58] we tend to add more instructions, more<br>[10:00] context, more details. We're not as good<br>[10:03] at going back and cleaning up and<br>[10:05] removing that information. And so the<br>[10:07] longer your prompt gets, that's more<br>[10:10] computation, that's higher cost, it's<br>[10:11] higher latency.<br>[10:13] If you move over to fine-tuning, you can<br>[10:15] take that information that you want to<br>[10:17] add every single time and through<br>[10:20] fine-tuning, update those parameters and<br>[10:23] really bake that additional information<br>[10:25] more deeply into your model. And so this<br>[10:27] works much better with higher volume and<br>[10:30] when you need to reason more deeply over<br>[10:32] that information that you've pulled.<br>[10:34] So where exactly is this cost break<br>[10:37] even? It depends on a few factors. It<br>[10:39] depends on the size of the model that<br>[10:42] you need. That depends on the complexity<br>[10:43] you're working with. I know Nicole spoke<br>[10:45] at some length about choosing large<br>[10:47] versus small models. Fine-tuning works<br>[10:49] for any size and scale, but of course<br>[10:52] it's going to be faster, it's going to<br>[10:53] be cheaper, and it's going to be easier<br>[10:55] to do this on smaller models. And then<br>[10:57] it's going to be more affordable to<br>[10:58] serve. And one of the benefits of<br>[11:00] working with fine-tuning is allows you<br>[11:03] to really find and calibrate which model<br>[11:05] is going to work best for your use case<br>[11:07] and it's going to give you that optimal<br>[11:09] performance.<br>[11:12] One other big algorithmic innovation<br>[11:14] that's come through recently is low rank<br>[11:16] adaptation. So rather than needing to do<br>[11:18] full fine-tuning on every single<br>[11:21] parameter in your model which measures<br>[11:23] in the billions, we can use this<br>[11:26] technique uh called Laura where we use a<br>[11:30] a dimensionality reduction technique and<br>[11:33] effectively we add in this uh matrix<br>[11:37] approximation. So we freeze the vast<br>[11:40] majority of the weights in the model and<br>[11:44] we only learn that low rank adaptation.<br>[11:46] It's a much smaller number of parameters<br>[11:48] that we can tune over. So it's more<br>[11:50] computationally efficient and you can<br>[11:52] also uh efficiently<br>[11:55] host and serve multiple Laura adapters.<br>[11:58] And so you can even reduce your cost for<br>[12:00] serving multiple models this way. But<br>[12:03] it's a really useful uh technique that<br>[12:05] allows you to get more performance with<br>[12:07] lower costs. And of course it's tunable.<br>[12:09] So that inner dimension what uh<br>[12:12] dimension you are uh shrinking down to<br>[12:16] you can keep that higher in order to get<br>[12:18] better performance or you can make it<br>[12:20] smaller to uh to further compress and<br>[12:22] make it faster to train.<br>[12:24] So thinking about your data requirements<br>[12:27] let's say you've now decided that you<br>[12:28] want to move to fine-tuning. What I want<br>[12:30] to say is the volume that you need to<br>[12:34] fine-tune has come down. Now<br>[12:35] pre-training of course requires an<br>[12:37] enormous amount of information and data.<br>[12:40] Supervised fine-tuning at the really<br>[12:41] large scale also requires quite a bit of<br>[12:44] work. But now when you want to adapt in<br>[12:46] just your particular domain, quality is<br>[12:50] much more important than quantity. All<br>[12:52] things being equal, more quantity will<br>[12:54] help. But I've been very surprised to<br>[12:56] see how much just a few dozen to a few<br>[12:59] hundred examples can really dramatically<br>[13:01] improve performance on a domain that<br>[13:03] that model is not great at working with<br>[13:05] in the beginning. The other thing is if<br>[13:08] you can mining from production is a much<br>[13:11] more uh effective manner. I've heard few<br>[13:14] a few of the presenters talk about this<br>[13:16] earlier of how do you close that<br>[13:18] flywheel? How do you close that loop?<br>[13:20] How do you learn from failure modes?<br>[13:22] Well, this is a great opportunity to<br>[13:23] extract out those cases that are not<br>[13:25] working, really specify what type of<br>[13:28] behavior you hope to see, and then send<br>[13:30] those back in for fine-tuning. This only<br>[13:32] works for some cases. I know certain<br>[13:34] domains are very sensitive about<br>[13:35] training, but if you work in a domain<br>[13:37] where you can feed those samples back<br>[13:40] in, can be a really powerful technique<br>[13:42] to allow you to solve this problem at<br>[13:44] the model level rather than having to<br>[13:46] spend the work tweaking prompts and uh<br>[13:50] trying to to maintain that overtime.<br>[13:54] So many of the big model providers work<br>[13:58] through a few different training steps<br>[14:01] and I'm going to move a little quickly<br>[14:02] here. I want to make sure I uh I uh save<br>[14:05] us some time. But typically, you need to<br>[14:08] go through pre-training, instruction<br>[14:09] fine-tuning, preference fine-tuning, and<br>[14:11] reasoning fine-tuning. And that<br>[14:13] reasoning fine-tuning is typically with<br>[14:16] reinforcement learning. And this is the<br>[14:18] technique I'm going to focus on because<br>[14:20] it is the one that has led to some of<br>[14:22] the most significant advancements. If<br>[14:24] you think back to that significant leap<br>[14:27] up we saw around last year from the<br>[14:29] proprietary model that came from 01 that<br>[14:31] came from the shift of adding in a<br>[14:34] greater based on verifiable rewards. So<br>[14:36] supervised fine-tuning is great if you<br>[14:39] have a clean set of input output pairs.<br>[14:41] It's a great place to start. When you<br>[14:43] shift over to reinforcement learning you<br>[14:46] now need a grader. You now need an<br>[14:47] ability to assess every single type of<br>[14:50] output that comes from the model during<br>[14:52] training. But if you can do that grading<br>[14:54] effectively, it allows you to really<br>[14:56] extract a lot more information. You get<br>[14:59] more juice from every training sample.<br>[15:01] Comes at more computational cost, but<br>[15:03] allows you to typically build more<br>[15:05] robust models that can handle a wider<br>[15:08] range of inputs more reliably.<br>[15:12] Now, preference tuning is still<br>[15:14] incredibly important and reinforcement<br>[15:16] learning with human feedback and direct<br>[15:18] preference optimizations are fantastic<br>[15:21] uh techniques to do that. Those tend to<br>[15:24] be better when you have training data<br>[15:26] that consists of multiple outputs and a<br>[15:29] preference coming uh from typically your<br>[15:31] users of A is better in this case, B is<br>[15:34] better in this case. When we move to<br>[15:37] reinforcement learning with verifiable<br>[15:38] rewards, this is a way for us to tell<br>[15:41] the model this was correct and this is<br>[15:44] wrong. Now, this is incredibly powerful<br>[15:46] for shaping the outputs and for ensuring<br>[15:51] that our model is actually solving the<br>[15:53] problem in the correct way and in the<br>[15:55] way we want it to be solved. It's<br>[15:57] incredibly useful for code generation.<br>[15:59] It's great for structured outputs. It's<br>[16:01] incredibly good for tool use. Uh,<br>[16:03] Chipwin also mentioned that choosing<br>[16:06] which functions to call and how to use<br>[16:08] tools is a valuable use case. That sets<br>[16:11] me up very nicely. That's exactly the<br>[16:12] problem that I'm going to focus on here.<br>[16:16] And in reinforcement learning with<br>[16:18] verifiable rewards, we take our training<br>[16:20] data and we pass those into our current<br>[16:22] model here. That's uh represented as the<br>[16:25] policy box. From that model policy, we<br>[16:29] generate multiple completions, also<br>[16:31] known as rollouts. We grade every single<br>[16:33] one of those and that goes through this<br>[16:36] verifiable reward box. It returns zero<br>[16:39] if it's a failure or alpha which is some<br>[16:41] reward if uh if otherwise. Now you<br>[16:45] probably want a scale of multiple<br>[16:48] types of rewards. You can use binary but<br>[16:51] having intermediate rewards can really<br>[16:53] help with more stable training. I<br>[16:55] sometimes get asked if you need an upper<br>[16:58] limit if this has to be zero to one. I<br>[17:00] typically use zero to one because that's<br>[17:02] easy for me to reason about, but given<br>[17:04] the way the the optimizer works, it<br>[17:07] really is unbounded because the rewards<br>[17:10] are relative. So if you want to use much<br>[17:12] larger numbers, that's actually fine and<br>[17:14] won't interfere with the training<br>[17:15] process.<br>[17:17] We typically use group relative policy<br>[17:19] optimization. This is a relatively new<br>[17:21] but much more efficient new algorithm<br>[17:24] for doing reinforcement learning based<br>[17:26] training compared to the prior version<br>[17:28] of a proximal policy optimization which<br>[17:31] came from more traditional reinforcement<br>[17:34] learning for optimizing sequences using<br>[17:36] a value model to help compute the<br>[17:39] advantage. With group relative policy<br>[17:42] optimization, we're able to do away with<br>[17:46] the value model and instead we compute<br>[17:48] multiple rollouts and then we compute<br>[17:50] the advantages uh relative to the other<br>[17:53] rollouts. And so typically you need a<br>[17:55] few more rollouts for this but you're<br>[17:58] saving trainable parameters and you're<br>[18:00] saving memory which is really important<br>[18:02] for fine-tuning these these larger<br>[18:04] models.<br>[18:06] So I'll walk you through an example<br>[18:07] here, but I've taken something called<br>[18:09] the Glaive function calling V2 data set.<br>[18:12] This is one of the best function calling<br>[18:13] data sets out there right now. And it<br>[18:15] comes along with a sequence of<br>[18:18] interactions with user interacting with<br>[18:20] the assistant with ground truth examples<br>[18:22] of what function should be used, what<br>[18:25] parameters it should be used with. So I<br>[18:27] took this data set and I implemented a<br>[18:30] greater uh based on uh reinforcement<br>[18:33] learning with verifiable rewards and<br>[18:35] I've put together a compound uh greater<br>[18:38] function that operates over<br>[18:42] uh creating valid JSON outputting the<br>[18:44] correct function for the current context<br>[18:47] and additional rewards for each of the<br>[18:50] arguments and then some additional<br>[18:51] penalties if it's missing a function<br>[18:53] call at all. It's not particularly<br>[18:55] complex, but I think what this<br>[18:57] illustrates is it gives you a lot of<br>[18:59] control to specify exactly what behavior<br>[19:02] you're looking for and then to shape<br>[19:05] those model outputs to get exactly the<br>[19:07] reliability that you determine that that<br>[19:10] you need for your use case. But you<br>[19:12] still get to benefit from the the vast<br>[19:16] number of parameters and the deep<br>[19:18] ability to understand context that these<br>[19:21] language models come with. I then uh<br>[19:23] specify our training configuration here.<br>[19:25] I'm using the hugging face transformers<br>[19:27] library. It's a a great library. It's<br>[19:30] entirely open source and my source code<br>[19:32] also includes some scripts in order to<br>[19:34] set up the environment and then uh train<br>[19:36] your model. Here is my uh reward curve<br>[19:39] and you can see we go from very poor<br>[19:40] performance at the very beginning to<br>[19:42] getting consistently uh answering the<br>[19:45] function calls as well as getting most<br>[19:46] of the parameters correct over time.<br>[19:48] Always watch out for rapid spikes in the<br>[19:51] reward which can indicate reward<br>[19:53] hacking. And this is the model finding a<br>[19:55] way to get a lot of reward without<br>[19:57] actually solving the model with solving<br>[19:59] the problem that you intend. Don't be<br>[20:01] surprised if it happens. These models<br>[20:02] are really good at getting high rewards<br>[20:05] even if it's going around your<br>[20:07] intention. I will uh skip over the<br>[20:10] hyperparameters here just in the<br>[20:11] interest of time. Well, what I'll leave<br>[20:13] you with is always start with uh<br>[20:17] proprietary models and start with<br>[20:18] context engineering and rag. It's<br>[20:20] faster, it's easier, it gets you to a<br>[20:22] product experience quickly. But really<br>[20:25] consider moving over to fine-tuning as a<br>[20:27] way to improve performance on your use<br>[20:29] case, reduce cost, and give you more<br>[20:31] control. Remember, the big model<br>[20:33] providers are telling us to only trust<br>[20:36] them and rely on their models and their<br>[20:38] APIs. But when it comes time for them to<br>[20:41] design and ship their own product<br>[20:43] experiences, most of the time they're<br>[20:45] doing additional fine-tuning to get<br>[20:46] better performance and better results<br>[20:48] because they know that's an important<br>[20:49] part of their moat. And so I encourage<br>[20:51] all of you to think about what your moat<br>[20:53] is on your team and think about the data<br>[20:57] and the training process and the greater<br>[20:59] all of this is something that can help<br>[21:01] give you better performance and it's<br>[21:03] something that can create enduring value<br>[21:06] and create that better performance over<br>[21:08] time. a new better model comes out.<br>[21:10] Great. Now you can start with that<br>[21:12] higher foundation and still pass it<br>[21:13] through that same training regime that<br>[21:15] you've built.<br>[21:17] And one last thing, if you've enjoyed<br>[21:19] this presentation, my book building<br>[21:22] applications with AI agents, uh this is<br>[21:24] my first book is now available on the<br>[21:26] O'Reilly platform and it is also<br>[21:28] available on Amazon. <!-- deep-read:sections end -->