Coders In Hoods
  • Courses
  • Roles
  • Blog
  • Setup

Coders In Hoods AI Academy

Every course is free. Sign in to start, and your progress, quiz scores and bookmarks follow you.

AI Academy

  • Courses
  • Paths
  • Setup guides
  • How we teach

Role roadmaps

  • AI Engineer
  • Forward Deployed Engineer
  • Machine Learning Engineer
  • All roles

Coders In Hoods

  • The agency
  • Coaching for teams
  • Blog
  • LinkedIn
  • X (Twitter)

Contact

codersinhoods@gmail.com

© Coders In Hoods · since 2019

Course overview

LLM Cost Engineering

Free · sign in to start and track progress

1 · Spending less on the same work

  • 1Token economics of an agent fleet
  • 2Prompt caching as system design
  • 3Trimming and compacting context
  • 4Batch, flex and fast tiers

2 · Changing the model, and governing the spend

  • 5Cost-quality curves, routing and cascades
  • 6Distilling into small models

    Exercise answers

    • Answer: Distil a clause tagger and measure the gap
  • 7Self-hosting break-even
  • 8Attribution, budgets and alerts
CapstoneCost-engineer an agent pipelineReference implementation

Module 2 · Changing the model, and governing the spend · Lesson 6

Distilling into small models

When training a small open-weight model on a larger model's outputs pays for itself, how the pipeline works from teacher labels to LoRA fine-tuning and serving, and the break-even arithmetic that often says no.

75 min 1 video 2 exercises 6-question quiz Answers
Setup for the exercises:Install Claude CodePython with uvGet an OpenRouter keyLocal models with OllamaRun GPU code on ModalRun Hugging Face models on CPU

By the end of this lesson you can

  • Explain sequence-level distillation and LoRA fine-tuning, and compute the size of a LoRA adapter for a given model
  • Design a distillation pipeline from teacher labelling to evaluation and serving, using routing logs and verifiers as data sources
  • Compute the fixed and marginal costs of distillation and the break-even volume against both the teacher and an off-the-shelf small model
  • Identify the contractual, data-protection and quality risks of training on client documents and on a provider's outputs

On this page

  • Intuition: training a specialist paralegal
  • The mechanism
  • Distillation
  • LoRA
  • The pipeline
  • A worked example: tagging lease clauses
  • When it does pay
  • Risks and obligations
  • Connections
  • Summary
  • Sources & further reading
  • Quiz

In this lesson

  1. 01Intuition: training a specialist paralegal
  2. 02The mechanism
  3. 03The pipeline
  4. 04A worked example: tagging lease clauses
  5. 05Risks and obligations
  6. 06Connections
  7. 07Summary

Sources & further reading

  • Distilling Step-by-Step! Outperforming Larger Language Models with Less Training Data and Smaller Model SizesPaper · Hsieh, Li, Yeh, Nakhost, Fujii et al. · Google Research · 2023ACL 2023. Training small models on a large model's rationales as well as its labels; a 770M-parameter T5 beat few-shot 540B PaLM on a benchmark with 80% of the data. Read section 3 for the multi-task set-up.
  • A Survey on Knowledge Distillation of Large Language ModelsPaper · Xu, Li, Tao, Shen, Cheng, Li, Xu, Tao, Zhou · 2024The map of LLM distillation methods (label, rationale, feedback and logit-based) organised by algorithm, skill and vertical, with an explicit call to respect the legal terms of the teacher model.
  • LoRA: Low-Rank Adaptation of Large Language ModelsPaper · Hu, Shen, Wallis, Allen-Zhu, Li et al. · Microsoft · 2021ICLR 2022. Freeze the base model and learn a low-rank update per weight matrix. Section 4 gives the parameterisation behind the adapter-size calculation in this lesson.
  • QLoRA: Efficient Finetuning of Quantized LLMsPaper · Dettmers, Pagnoni, Holtzman, Zettlemoyer · 2023NeurIPS 2023. LoRA on a 4-bit quantised base, fine-tuning a 65B model on one 48 GB GPU; why training small adapters has become cheap.
  • S-LoRA: Serving Thousands of Concurrent LoRA AdaptersPaper · Sheng, Cao, Li et al. · 2023Serving many adapters on one base model with unified paging; the systems basis for per-firm or per-task adapters at the cost of one deployment.
  • Fireworks pricingDocs · Fireworks AIPer-token LoRA and full fine-tuning prices by model size, and the statement that fine-tuned models are served at base-model prices. Pair with the serverless pricing docs for inference rates.
  • Commercial Terms of ServiceDocs · AnthropicSection D.4, the restriction on using the services to build a competing product, including training competing AI models. Read it before any distillation project; it is why the teacher in this lesson is an open-weight model.
Free · sign in to start

Sign in to keep reading.

Free, no card. We use your account to save progress, quiz scores, bookmarks and occasionally send updates from our team.

  • 7 more sections
  • 2 hands-on exercises
  • A 6-question quiz
  • Progress, quiz scores and bookmarks