$ show arcee-ai/DistillKit
DistillKit is a production-ready toolkit for knowledge distillation of large language models, supporting both online and offline workflows. It features advanced logit compression techniques (polynomial approximation + quantization + bit-packing) that enable efficient offline distillation at scale. The toolkit provides composable loss functions (KL, JSD, TVD, ranking losses, hidden state alignment) and integrates with Hugging Face Transformers, TRL, and Accelerate. It powers Arcee AI's distilled model releases and includes CLI tools for easy experimentation.
The LLM identified 3 files worth highlighting for reuse:
Provides efficient bit-level packing and unpacking of integers with arbitrary bit widths (1-64 bits). This self-contained utility implements optimized bit manipulation algorithms for storing integer arrays in minimal space, with no external dependencies beyond PyTorch. The pack_to_bytes and unpack_from_bytes functions demonstrate non-obvious skill in bit manipulation and could be extracted for use in any project requiring compact integer storage.
Expands sparse probability distributions (top-k logits and values) into dense tensors while handling missing probability mass according to specified strategies (zero or symmetric uniform). This simple but crucial function manages the conversion between sparse and dense representations with proper handling of renormalization and missing value treatment. Its minimal dependencies (only torch and a small enum) make it highly reusable in any probabilistic machine learning workflow.
Implements hidden state mapping for knowledge distillation, including learned linear projections when teacher and student hidden state dimensions differ. Supports various initialization strategies (xavier, kaiming, zero, identity) and handles layer mapping configurations. While it uses transformers for type hints, the core projection logic is general and could be adapted for any hidden state distillation scenario. The module cleanly encapsulates the complexity of hidden state alignment.