Back to Skills

knowledge-distillation

Compress large language models using knowledge distillation from teacher to student models. Use when deploying smaller models with retained performance, transferring GPT-4 capabilities to open-source models, or reducing inference costs. Covers temperature scaling, soft targets, reverse KLD, logit distillation, and MiniLLM training strategies.

3,579stars289forksUpdated 2/18/2026

Security Assessment

Safe(100/100)
Security Score100/100

About knowledge-distillation

The knowledge-distillation skill allows the compression of large language models (LLMs) by transferring knowledge from a teacher model (typically large and powerful) to a smaller student model. The key objective of this skill is to reduce the size and inference costs of models, all while maintaining a high level of performance. This technique is useful in scenarios where deploying a large LLM is not feasible due to computational limitations or cost constraints. By utilizing teacher-student relationships, knowledge distillation helps in transferring the capabilities of large proprietary models like GPT-4 to smaller, open-source models like LLaMA or Mistral, without significant loss in performance.

This skill supports several key techniques for distilling knowledge, including temperature scaling, soft targets, reverse KLD, logit distillation, and response distillation. It is primarily used when there is a need to compress models (e.g., reducing a 70B model to a 7B one), transfer knowledge between different models, or create specialized models for particular tasks or domains. With the incorporation of MiniLLM and reverse KLD, it further enhances the distillation process by improving the quality of generative model outputs. Target users include machine learning practitioners and researchers focused on optimizing large language models for deployment in resource-constrained environments, or anyone looking to improve the efficiency and performance of smaller models using knowledge from larger ones.

FAQ

How do I install the knowledge-distillation skill?

To install the knowledge-distillation skill, you need to install the necessary dependencies. For standard transformers, use 'pip install transformers datasets accelerate'. For training, install 'torch deepspeed wandb'. Optionally, for MiniLLM implementation, clone the repository from GitHub and install it using 'pip install -e .'

What is the purpose of the temperature parameter in the distillation loss function?

The temperature parameter is used to soften the probability distributions of the teacher and student models. Higher values of temperature result in softer probability distributions, which allows the student model to better mimic the teacher's behavior, improving the distillation process.

Can I use this skill with models other than LLaMA and Mistral?

Yes, while the examples use LLaMA and Mistral models, the knowledge-distillation skill is not limited to these models. You can apply it to any teacher-student model architecture, as long as the models are compatible with the PyTorch framework and Transformers library.

What is reverse KLD, and why is it important for distillation?

Reverse KLD (KL Divergence) is an innovation introduced in MiniLLM that improves the distillation process by reversing the direction of the KL divergence between the student and teacher models. This approach has shown to enhance the quality of generative outputs in distillation tasks, particularly for generative models.

Are there any specific hardware requirements for running the skill?

The skill uses PyTorch and requires a compatible CUDA device for efficient model training, especially for large models. It is recommended to have access to a GPU for optimal performance during distillation tasks.

Install knowledge-distillation

Download and extract the skill files to your .claude/skills/ directory.

Quick Setup:

  1. Copy the skill folder to .claude/skills/
  2. Claude will automatically detect and use the skill