This is a solid implementation guide for compressing large language models using knowledge distillation, with working code for the main techniques. You get standard teacher-student training with temperature scaling and soft targets, plus MiniLLM's reverse KLD approach which actually works better for generative models because it's mode-covering instead of mode-seeking. The examples show real transfers like 70B to 7B LLaMA models and include response distillation for creating synthetic training data. Good coverage of the alpha hyperparameter for balancing soft and hard losses. If you're trying to deploy a cheaper model or transfer GPT-4 capabilities to something you can run locally, this gives you the core techniques with reasonable defaults.

skills.sh installs
1K
GitHub stars
14.4K
last updated
Aug 21, 2026

Install

$ npx -y skills add orchestra-research/ai-research-skills --skill knowledge-distillation --agent claude-code

Installs into .claude/skills of the current project.

Files

Knowledge Distillation: Compressing LLMs

When to Use This Skill

Use Knowledge Distillation when you need to:

  • Compress models from 70B → 7B while retaining 90%+ performance
  • Transfer capabilities from proprietary models (GPT-4) to open-source (LLaMA, Mistral)
  • Reduce inference costs by deploying smaller student models
  • Create specialized models by distilling domain-specific knowledge
  • Improve small models using synthetic data from large teachers

Key Techniques: Temperature scaling, soft targets, reverse KLD (MiniLLM), logit distillation, response distillation

Papers: Hinton et al. 2015 (arXiv 1503.02531), MiniLLM (arXiv 2306.08543), KD Survey (arXiv 2402.13116)

Installation

# Standard transformers
pip install transformers datasets accelerate

# For training
pip install torch deepspeed wandb

# Optional: MiniLLM implementation
git clone https://github.com/microsoft/LMOps
cd LMOps/minillm
pip install -e .

Quick Start

Basic Knowledge Distillation

import torch
import torch.nn.functional as F
from transformers import AutoModelForCausalLM, AutoTokenizer, Trainer, TrainingArguments

Sponsors

Details

Repository
github.com/orchestra-research/ai-research-skills
Categories
AI & Agent Building, Data Science & ML, Debugging
First seen
Jun 3, 2026

More from orchestra-research/ai-research-skills

All 95
1orchestra-research avatarray-dataorchestra-research/ai-research-skillsScalable data processing for ML workloads. Streaming execution across CPU/GPU, supports Parquet/CSV/JSON/images. Integrates with Ray Train, PyTorch, TensorFlow.1Kskills.sh installs
2gocallum avatarprisma-orm-v7-skillsgocallum/nextjs16-agent-skillsKey facts and breaking changes for upgrading to Prisma ORM 7. Consider version 7 changes before generation or troubleshooting1Kskills.sh installs
3orchestra-research avatarfine-tuning-with-trlorchestra-research/ai-research-skillsFine-tune LLMs using reinforcement learning with TRL - SFT for instruction tuning, DPO for preference alignment, PPO/GRPO for reward optimization, and reward mo1Kskills.sh installs
4orchestra-research avatardeepspeedorchestra-research/ai-research-skillsExpert guidance for distributed training with DeepSpeed - ZeRO optimization stages, pipeline parallelism, FP16/BF16/FP8, 1-bit Adam, sparse attention1Kskills.sh installs
5orchestra-research avatargrpo-rl-trainingorchestra-research/ai-research-skillsExpert guidance for GRPO/RL fine-tuning with TRL for reasoning and task-specific model training1Kskills.sh installs
6orchestra-research avataroptimizing-attention-flashorchestra-research/ai-research-skillsOptimizes transformer attention with Flash Attention for 2-4x speedup and 10-20x memory reduction. Use when training/running transformers with long sequences (>1Kskills.sh installs