This project implements knowledge distillation from a larger language model (teacher) to a smaller model (student) using the TorchTune framework.
Environment Setup
Create a new conda environment using the provided environment.yml:
conda env create -f environment.yml
Activate the environment:
conda activate torchtune
Model Preparation
Before running the distillation process, you need to download both the teacher and student models. Make sure to download them to the correct paths as specified in the configuration file:
<YOUR_OUTPUT_DIR>: Directory where the distilled model will be saved
<YOUR_STUDENT_MODEL_PATH>: Path where you downloaded the student model
<YOUR_TEACHER_MODEL_PATH>: Path where you downloaded the teacher model
Running Knowledge Distillation
After setting up the environment and downloading the models, you can run the knowledge distillation process using the provided configuration file:
tune run knowledge_distillation_single_device --config 8B_to_1B_KD_lora_single_device.yaml
Merging LoRA Adapters
After the distillation process is complete, you need to merge the LoRA adapters with the base model(Llama-3.2-1B-Instruct). Before running the merge script, modify the paths in merge_lora.py: