Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions neural_compressor/experimental/common/criterion.py
Original file line number Diff line number Diff line change
Expand Up @@ -1252,14 +1252,17 @@ def __call__(self, **kwargs):
class SelfKnowledgeDistillationLoss(KnowledgeDistillationFramework):
"""SelfKnowledge Distillation Loss."""

def __init__(self, layer_mappings=[], loss_types=None, loss_weights=None, temperature=1.0,add_origin_loss=False, student_model=None, teacher_model=None):
def __init__(self, layer_mappings=[], loss_types=None, loss_weights=None, temperature=1.0,add_origin_loss=False,
student_model=None, teacher_model=None):
"""Initialize SelfKnowledge Distillation Loss class.

Args:
layer_mappings (list): layers of distillation.Format like
[[[student1_layer_name1, teacher_layer_name1],[student2_layer_name1, teacher_layer_name1]],[[student1_layer_name2, teacher_layer_name2],[student2_layer_name2, teacher_layer_name2]]]
[[[student1_layer_name1, teacher_layer_name1],[student2_layer_name1, teacher_layer_name1]],
[[student1_layer_name2, teacher_layer_name2],[student2_layer_name2, teacher_layer_name2]]]
loss_types (list, optional): loss types. Defaults to ['CE'] * len(layer_mappings).
loss_weights (list, optional): loss weights. Defaults to [1.0 / len(layer_mappings)] * len(layer_mappings).temperature (float, optional): use to calculate the soft label CE.
loss_weights (list, optional): loss weights. Defaults to [1.0 / len(layer_mappings)] *
len(layer_mappings).temperature (float, optional): use to calculate the soft label CE.
temperature (optional): temperature. Defaults to 1.0.
add_origin_loss (bool, optional): whether to add origin loss for hard label loss.
student_model (optional): student model. Defaults to None.
Expand Down Expand Up @@ -1342,14 +1345,17 @@ class PyTorchSelfKnowledgeDistillationLoss(
SelfKnowledgeDistillationLoss
):
"""PyTorch SelfKnowledge Distillation Loss."""
def __init__(self, layer_mappings=[], loss_types=None, loss_weights=None, temperature=1.0,add_origin_loss=False, student_model=None, teacher_model=None):
def __init__(self, layer_mappings=[], loss_types=None, loss_weights=None, temperature=1.0,add_origin_loss=False,
student_model=None, teacher_model=None):
"""Initialize PyTorch SelfKnowledge Distillation Loss class.

Args:
layer_mappings (list): layers of distillation.Format like
[[[student1_layer_name1, teacher_layer_name1],[student2_layer_name1, teacher_layer_name1]],[[student1_layer_name2, teacher_layer_name2],[student2_layer_name2, teacher_layer_name2]]]
[[[student1_layer_name1, teacher_layer_name1],[student2_layer_name1, teacher_layer_name1]],
[[student1_layer_name2, teacher_layer_name2],[student2_layer_name2, teacher_layer_name2]]]
loss_types (list, optional): loss types. Defaults to ['CE'] * len(layer_mappings).
loss_weights (list, optional): loss weights. Defaults to [1.0 / len(layer_mappings)] * len(layer_mappings).temperature (float, optional): use to calculate the soft label CE.
loss_weights (list, optional): loss weights. Defaults to [1.0 / len(layer_mappings)] *
len(layer_mappings).temperature (float, optional): use to calculate the soft label CE.
temperature (optional): temperature. Defaults to 1.0.
add_origin_loss (bool, optional): whether to add origin loss for hard label loss.
student_model (optional): student model. Defaults to None.
Expand Down