keras-team/keras · error · NotImplementedError

Subclasses must implement compute_loss

Error message

Subclasses must implement compute_loss

What it means

Error "Subclasses must implement compute_loss" thrown in keras-team/keras.

Source

Thrown at keras/src/distillation/distillation_loss.py:60

    override the `compute_loss` method.
    """

    def compute_loss(self, teacher_outputs, student_outputs, **kwargs):
        """Compute distillation loss between teacher and student outputs.

        This method should implement the specific distillation logic for
        transferring knowledge from teacher to student.

        Arguments:
            teacher_outputs: Outputs from the teacher model. Can be a single
                tensor or a list/tuple of tensors for multi-output models.
            student_outputs: Outputs from the student model. Can be a single
                tensor or a list/tuple of tensors for multi-output models.
            **kwargs: Additional arguments for custom distillation_loss.
        Returns:
            Distillation loss tensor.
        """
        raise NotImplementedError("Subclasses must implement compute_loss")

    def validate_outputs(self, teacher_outputs, student_outputs):
        """Validate that teacher and student outputs are compatible.

        Arguments:
            teacher_outputs: Outputs from the teacher model.
            student_outputs: Outputs from the student model.
        Raises:
            ValueError: If outputs are not compatible.
        """
        keras.tree.assert_same_structure(teacher_outputs, student_outputs)

    def validate_model_compatibility(self, teacher, student):
        """Validate that teacher and student models are compatible.

        Arguments:
            teacher: The teacher model.
            student: The student model.

View on GitHub (pinned to 7a34a03db6)

When it happens

Trigger: Thrown at keras/src/distillation/distillation_loss.py:60 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of keras-team/keras@7a34a03db6 (2026-08-25). Data as JSON: /api/errors/e910568fe9c48ad6. Report an issue: GitHub.