loss_balancer
Fixed-weight KD loss balancer for Megatron noise distillation.
FixedWeightedKDLossBalancer combines ModelOpt's per-criterion losses with
fixed weights: the mean of all logits (KL) losses, the mean of all intermediate
losses (which includes the noise-embedding loss), and — optionally — the student's
original task loss. This is Slot 2's combiner in the two-slot loss design.
Classes:
| Name | Description |
|---|---|
FixedWeightedKDLossBalancer |
Combine logits and intermediate KD losses with fixed weights. |
FixedWeightedKDLossBalancer
¶
Bases: DistillationLossBalancer
Combine logits and intermediate KD losses with fixed weights.
Methods:
| Name | Description |
|---|---|
__init__ |
Initialize the balancer. |
forward |
Combine the per-criterion losses into the total KD loss. |
__init__
¶
__init__(
logits_weight: float = 1.0,
intermediate_weight: float = 1.0,
original_loss_weight: float = 1.0,
skip_original_loss: bool = True,
) -> None
Initialize the balancer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
float
|
Weight on the mean logits-distillation (KL) loss. |
1.0
|
|
float
|
Weight on the mean intermediate loss (includes the noise-embedding loss). |
1.0
|
|
float
|
Weight on the student's original task loss. |
1.0
|
|
bool
|
If True, the student's original task loss is excluded from the total (pure distillation). |
True
|
forward
¶
Combine the per-criterion losses into the total KD loss.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
dict[str, Tensor]
|
Mapping from criterion key to its scalar loss. Logits losses
are keyed by the |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Tensor]
|
A mapping with the combined |
dict[str, Tensor]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If no logits distillation loss is present. |