From prompts to fine-tuning: four levels of adapting open-source models

Anna Shchenikova22 Aug 2024

Problem

An analyst at a telecom R&D center regularly gets tasks that need an open-source LLM, such as summarization, code generation or translation. The question is how far to adapt the model. A wrong guess means weeks lost on prompts that cannot reach the needed quality, or an expensive fine-tuning project that a simpler approach would have made unnecessary.

Example from the article: on a summarization project, prompt techniques brought factual accuracy to about 90%. After a Docker container problem the model produced one meaningless word on repeat, and three weeks of prompt tuning were needed to get back to 90%.

Solution in brief

Think of adaptation as four levels: off-the-shelf use, prompt engineering, agents and RAG, and fine-tuning. Start at the cheapest level, cap the time for each at its proof-of-concept estimate, and move up when specific symptoms appear: unstable factual accuracy, hallucinations, missing skills or a weak language.

Questions this case answers
  • How to choose the cheapest adaptation level (off-the-shelf model, prompts, agent with retrieval, fine-tuning) that meets the quality bar of a text-generation task
  • How to recognize that prompting can no longer fix unstable factual accuracy and hallucinations of a generative model
  • How to decide whether an LLM task needs prompts, agents or fine-tuning before spending weeks on it
  • How to recognize that prompt engineering has hit its ceiling on factual accuracy

Tools and methods

  • Prompt engineering — system and user messages, chain-of-thought, few-shot examples
  • LangChain agents — thought, action, result loop with tools (web search, calculator)
  • RAG — retrieval from a knowledge store, with Elasticsearch, vector search or a knowledge graph
  • LoRA fine-tuning — training small copies of some layers instead of all weights, via Hugging Face PEFT
  • GPT-4o, Llama, Mistral, Qwen — cloud and open-source models tried at level zero
Continue reading — it's free

Google or a one-time email code. No password.