base
shrinkai.distillation.losses.base
Base class for Knowledge Distillation loss functions.
Classes:
| Name | Description |
|---|---|
BaseDistillationLoss |
Abstract base class for all distillation loss functions. |
Classes
BaseDistillationLoss
Bases: Module, ABC
Abstract base class for all distillation loss functions.
All concrete implementations must override the forward method.
Methods:
| Name | Description |
|---|---|
forward |
Computes the distillation loss. |
Source code in src/shrinkai/distillation/losses/base.py
Methods:
forward
abstractmethod
forward(
student_outputs: Tensor | dict[str, Tensor],
teacher_outputs: Tensor | dict[str, Tensor],
labels: Tensor | None = None,
) -> torch.Tensor
Computes the distillation loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
student_outputs
|
Tensor | dict[str, Tensor]
|
Output tensor (or dict of activations) from the student model. |
required |
teacher_outputs
|
Tensor | dict[str, Tensor]
|
Output tensor (or dict of activations) from the teacher model. |
required |
labels
|
Tensor | None
|
Ground-truth task labels (optional depending on the loss type). |
None
|
Returns:
| Type | Description |
|---|---|
Tensor
|
torch.Tensor: Scalar loss tensor for backpropagation. |