neural_compressor.experimental.common.criterion

Initialize critetion classes.

Classes includes:

TensorFlowCrossEntropyLoss, PyTorchCrossEntropyLoss, TensorflowKnowledgeDistillationLoss, PyTorchKnowledgeDistillationLoss, PyTorchIntermediateLayersKnowledgeDistillationLoss.

Module Contents

Classes

TensorflowCriterions

Record criterions in TensorflowCriterions class.

PyTorchCriterions

Record criterions in PyTorchCriterions class.

Criterions

Integrate criterions of different framework.

KnowledgeDistillationFramework

Knowledge Distillation Framework.

KnowledgeDistillationLoss

Initialize the KnowledgeDistillationLoss class.

PyTorchKnowledgeDistillationLoss

The PyTorchKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss.

PyTorchKnowledgeDistillationLossWrapper

PyTorchKnowledgeDistillationLossWrapper wraps PyTorchKnowledgeDistillationLoss.

TensorflowKnowledgeDistillationLossExternal

TensorflowKnowledgeDistillationLossExternal inherits from KnowledgeDistillationLoss.

IntermediateLayersKnowledgeDistillationLoss

The IntermediateLayersKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss.

PyTorchIntermediateLayersKnowledgeDistillationLoss

PyTorch Intermediate Layers Knowledge Distillation Loss.

PyTorchIntermediateLayersKnowledgeDistillationLossWrapper

PyTorch Intermediate Layers Knowledge Distillation Loss Wrapper.

SelfKnowledgeDistillationLoss

SelfKnowledge Distillation Loss.

Functions

criterion_registry(criterion_type, framework)

Use to register criterion classes in registry_criterions.

class neural_compressor.experimental.common.criterion.TensorflowCriterions[source]

Record criterions in TensorflowCriterions class.

class neural_compressor.experimental.common.criterion.PyTorchCriterions[source]

Record criterions in PyTorchCriterions class.

class neural_compressor.experimental.common.criterion.Criterions(framework)[source]

Integrate criterions of different framework.

neural_compressor.experimental.common.criterion.criterion_registry(criterion_type, framework)[source]

Use to register criterion classes in registry_criterions.

Parameters:
  • criterion_type (str) – The string of supported criterion.

  • framework (str) – The string of supported framework.

Returns:

The class of register.

Return type:

cls

class neural_compressor.experimental.common.criterion.KnowledgeDistillationFramework(student_model=None, teacher_model=None)[source]

Knowledge Distillation Framework.

class neural_compressor.experimental.common.criterion.KnowledgeDistillationLoss(temperature=1.0, loss_types=['CE', 'CE'], loss_weights=[0.5, 0.5], student_model=None, teacher_model=None)[source]

Initialize the KnowledgeDistillationLoss class.

class neural_compressor.experimental.common.criterion.PyTorchKnowledgeDistillationLoss(temperature=1.0, loss_types=['CE', 'CE'], loss_weights=[0.5, 0.5], student_model=None, teacher_model=None)[source]

The PyTorchKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss.

class neural_compressor.experimental.common.criterion.PyTorchKnowledgeDistillationLossWrapper(param_dict)[source]

PyTorchKnowledgeDistillationLossWrapper wraps PyTorchKnowledgeDistillationLoss.

class neural_compressor.experimental.common.criterion.TensorflowKnowledgeDistillationLossExternal(temperature=1.0, loss_types=['CE', 'CE'], loss_weights=[0.5, 0.5], student_model=None, teacher_model=None)[source]

TensorflowKnowledgeDistillationLossExternal inherits from KnowledgeDistillationLoss.

class neural_compressor.experimental.common.criterion.IntermediateLayersKnowledgeDistillationLoss(layer_mappings=[], loss_types=None, loss_weights=None, add_origin_loss=False, student_model=None, teacher_model=None)[source]

The IntermediateLayersKnowledgeDistillationLoss class inherits from KnowledgeDistillationLoss.

class neural_compressor.experimental.common.criterion.PyTorchIntermediateLayersKnowledgeDistillationLoss(layer_mappings=[], loss_types=None, loss_weights=None, add_origin_loss=False, student_model=None, teacher_model=None)[source]

PyTorch Intermediate Layers Knowledge Distillation Loss.

class neural_compressor.experimental.common.criterion.PyTorchIntermediateLayersKnowledgeDistillationLossWrapper(param_dict)[source]

PyTorch Intermediate Layers Knowledge Distillation Loss Wrapper.

class neural_compressor.experimental.common.criterion.SelfKnowledgeDistillationLoss(layer_mappings=[], loss_types=None, loss_weights=None, temperature=1.0, add_origin_loss=False, student_model=None, teacher_model=None)[source]

SelfKnowledge Distillation Loss.