Meetup

Fine-Tuning LLMs: Best Practices and When to Go Small

Mark Kim-Huang, Preemo Inc.Episode 124 · 53:48 · Jun 2023 · 10K viewsHosted by Demetrios Brinkmann
Thumbnail for Fine-Tuning LLMs: Best Practices and When to Go Small Watch on YouTube
TL;DR
  1. 1

    Fine-tuning open-source models gives teams control over model ownership, domain expertise, service levels, security, and privacy.

  2. 2

    Small specialized models are often the right choice for simple tasks because they can already deliver near-perfect performance on their specific benchmarks.

  3. 3

    Task definition, diverse training data, synthetic data generation, prompt engineering, and parameter-efficient methods such as LoRA make fine-tuning more practical.

Summary

Mark Kim-Huang compares closed-source models, fine-tuned open-source models, and small specialized models. He explains why teams may need custom models when they require control over intellectual property, service levels, domain behavior, security, or privacy. Small models are appropriate when a task is simple and specialized, since they can already perform near the state of the art for that task. For fine-tuning, Mark recommends defining the task clearly, evaluating it with resources such as Stanford's HELM, and diversifying training data through task clustering. He describes instruction fine-tuning, self-instruct for generating synthetic examples, and prompt design built from meta-prompts, templates, and exemplars. He then explains why full fine-tuning has a large memory cost and how LoRA freezes most model weights while learning a lower-rank update. The discussion also covers reasoning paths, self-consistency, inference cost, vector databases, and when fine-tuning is preferable to prompting.

Key ideas
01:42

Custom models provide control that closed-source endpoints cannot

Mark separates model options into closed-source models accessed through APIs, fine-tuned open-source models, and small specialized models. He argues that custom models matter when a company needs ownership of its intellectual property and control over service levels. An external provider outage can prevent a product from meeting its own SLA. Fine-tuning also lets a model develop expertise in the tasks that drive a business. Security and privacy are another reason to keep the model and training data under the company's control. Mark points to finance and healthcare, where regulations such as HIPAA can make sending data to an outside endpoint impractical.

08:18

Small specialized models are a better fit for simple tasks

Mark says small models work well when the task is simple and narrowly defined. He recommends using Papers with Code to inspect benchmarks and understand whether a task already has a strong specialized model. If a small model has effectively solved the task and delivers near-perfect performance, scaling to a much larger language model adds little value. This is the case for many focused applications where the model does not need broad knowledge or complex reasoning. The decision should begin with the task and its measured requirements, rather than with a preference for the largest available model.

09:42

Fine-tuning starts with a precise definition of the task

Mark describes four fine-tuning categories: multitask fine-tuning, few-shot fine-tuning, domain-specific fine-tuning, and prompt-based fine-tuning. His main focus is instruction fine-tuning, which provides an interface for exposing model capabilities on downstream tasks. Before collecting data, he recommends classifying the work into knowledge-based and reasoning-based tasks. Knowledge tasks may involve many simple tasks or a few complex ones. Reasoning tasks can include code generation, code explanation and debugging, mathematics, and higher-order abstractions. This framework helps teams work backward from the capability they need instead of collecting generic examples.

23:49

Task diversity can improve performance outside the training distribution

Mark recommends Stanford's HELM, the Holistic Evaluation of Language Models, for comparing models and selecting relevant evaluation scenarios. He also describes task clustering as a way to diversify fine-tuning data. In the FLAN work he cites, training across diverse task clusters improved performance on tasks outside the training distribution. He adds a qualification: this effect generally requires a fairly large model, probably more than about 10 billion parameters. Mark gives the combination of language and code data as a community example, where the symbolic relationship between the two types of data can improve both language and coding performance.

18:37

Synthetic instruction data can expand a small set of curated examples

A prompt can contain a meta-prompt, a template, and exemplars. Mark describes using a meta-prompt to ask a language model to create tasks, then using a template with existing examples and a blank slot for another task. The self-instruct method seeds this process with human-curated tasks, generates more tasks through a task pool, and filters the results before using them for fine-tuning. He cites the self-instruct paper's result of generating 82,000 task instances from 175 curated tasks. He also connects this method to Alpaca's approach for producing data used to fine-tune Llama.

21:02

Reasoning traces are more useful than answers alone for many training examples

Mark advises focusing on rationales rather than only correct answers. He compares this with a mathematics exam, where the reasoning path shows whether the method can transfer to other questions. For language models, the reasoning path can teach a pattern that applies across examples, while a label only identifies the outcome. He also recommends pushing the context limit when creating examples, since more demonstrations can clarify the intended behavior through few-shot or in-context learning. Another approach is to ask the model to generate its own rationale, using chain-of-thought reasoning to provide a path from the input to the answer.

23:41

LoRA reduces fine-tuning memory by learning a low-rank update

Mark estimates that full fine-tuning of a 15-billion-parameter model with mixed precision requires about 270 gigabytes of VRAM before activations. The memory includes model weights, a full-precision master copy, optimizer states, and gradients, which can require four 80-gigabyte A100 GPUs. LoRA, or Low-Rank Adaptation, freezes the original weights and learns an incremental update represented by lower-rank matrices. A rank of eight can reduce the trainable portion substantially, making the added parameters tens of megabytes and reducing the memory footprint by about 78 percent in his example. He says this can allow the model to fit on one 80-gigabyte A100, although overhead can still cause out-of-memory errors.

52:00

Fine-tuning and prompting should be chosen from task quality and cost

In the closing question, Mark says fine-tuning is appropriate when a team needs domain expertise, better performance, or more zero-shot behavior from the model. It is also needed when the required expertise is absent from the pretrained model. Prompting can expose capabilities that are already embedded in a general model, so the choice depends on how well the model performs on the tasks that matter and whether the cost is acceptable. He also discusses reasoning-path selection through self-consistency, where the model is sampled repeatedly and the most frequent answer is used to select corresponding reasoning paths. This improves explainability, but repeated inference raises costs.

"Small models are already state of the art and they've already solved the problem that they're in tasks that they've been dedicated to perform on."Mark Kim-Huang09:18
Who should watch
  • You are deciding between a closed-source API, a fine-tuned open-source model, and a smaller specialized model for a product.
  • Your fine-tuning project is blocked by weak training data, unclear task definitions, or the cost of creating many labeled examples.
  • You need to reduce GPU memory use or decide whether prompting and retrieval are sufficient before investing in fine-tuning.