Skip to content

feat(hslm): knowledge distillation from FP32 teacher to ternary student#567

Merged
gHashTag merged 1 commit into
mainfrom
feat/322-knowledge-distillation
Apr 30, 2026
Merged

feat(hslm): knowledge distillation from FP32 teacher to ternary student#567
gHashTag merged 1 commit into
mainfrom
feat/322-knowledge-distillation

Conversation

@gHashTag

Copy link
Copy Markdown
Owner

Summary

Knowledge distillation framework for transferring FP32 teacher knowledge to ternary student.

New file

  • src/b2t/knowledge_distillation.zig — 216 LOC

Method (Hinton et al. 2015)

  • Teacher produces soft targets (temperature-scaled softmax)
  • Student learns from both soft targets (KL divergence) and hard labels (cross-entropy)
  • Combined: alpha * KL(teacher || student) + (1-alpha) * CE(student, target)

Features

  • DistillationLoss: soft-target KL, hard-label CE, combined loss
  • softmaxAlloc(), logSoftmaxAlloc(): numerically stable softmax
  • TeacherStudent: paired forward pass wrapper
  • Configurable: temperature, alpha weights

Tests (6)

  • Softmax valid probabilities, log-softmax, soft target loss, hard label loss, combined loss, teacher-student wrapper

Closes #322

- Add src/b2t/knowledge_distillation.zig
- DistillationLoss: soft-target KL divergence + hard-label CE
- Temperature-scaled softmax/log-softmax
- Combined loss: alpha*soft + (1-alpha)*hard
- TeacherStudent wrapper for paired forward passes
- Hinton et al. (2015) distillation framework
- 6 tests: softmax valid probs, log-softmax, soft loss,
  hard loss, combined, teacher-student wrapper

Closes #322
@gHashTag gHashTag merged commit e25fcb3 into main Apr 30, 2026
9 of 19 checks passed
@gHashTag gHashTag deleted the feat/322-knowledge-distillation branch April 30, 2026 00:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(hslm): knowledge distillation from FP32 teacher to ternary student

1 participant