Squeezer
Lightweight knowledge distillation pipeline
Install / Use
/learn @esceptico/SqueezerREADME
Squeezer (WIP)
Usage
Step 1: Define Distiller class
Implement teacher_forward, student_forward
and (if required) move_batch_to_device methods.
from squeezer import Distiller
class CustomDistiller(Distiller):
def teacher_forward(self, batch):
return self.teacher(batch['data'])
def student_forward(self, batch):
return self.student(batch['data'])
Step 2: Define LossPolicy
from torch.nn.functional import mse_loss
from squeezer import AbstractDistillationPolicy
class DistillationPolicy(AbstractDistillationPolicy):
def forward(self, teacher_output, student_output, batch, epoch):
loss_mse = mse_loss(student_output, teacher_output)
loss_dict = {'mse': loss_mse.item()}
return loss_mse, loss_dict
Step 3: Fit
from torch import optim
from squeezer.logging import TensorboardLogger
train_loader = ...
teacher = Teacher()
student = Student()
logger = TensorboardLogger('runs', 'experiment')
optimizer = optim.AdamW(student.parameters(), lr=3e-4)
policy = DistillationPolicy()
distiller = CustomDistiller(teacher, student, policy, optimizer=optimizer, logger=logger)
distiller(train_loader, n_epochs=10)
distiller.save('path_to_some_directory')
Related Skills
node-connect
347.6kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
108.4kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
347.6kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
347.6kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
