{"record":{"id":"e910568fe9c48ad6","repo":"keras-team/keras","slug":"subclasses-must-implement-compute-loss","errorCode":null,"errorMessage":"Subclasses must implement compute_loss","messagePattern":"Subclasses must implement compute_loss","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"keras/src/distillation/distillation_loss.py","lineNumber":60,"sourceCode":"    override the `compute_loss` method.\n    \"\"\"\n\n    def compute_loss(self, teacher_outputs, student_outputs, **kwargs):\n        \"\"\"Compute distillation loss between teacher and student outputs.\n\n        This method should implement the specific distillation logic for\n        transferring knowledge from teacher to student.\n\n        Arguments:\n            teacher_outputs: Outputs from the teacher model. Can be a single\n                tensor or a list/tuple of tensors for multi-output models.\n            student_outputs: Outputs from the student model. Can be a single\n                tensor or a list/tuple of tensors for multi-output models.\n            **kwargs: Additional arguments for custom distillation_loss.\n        Returns:\n            Distillation loss tensor.\n        \"\"\"\n        raise NotImplementedError(\"Subclasses must implement compute_loss\")\n\n    def validate_outputs(self, teacher_outputs, student_outputs):\n        \"\"\"Validate that teacher and student outputs are compatible.\n\n        Arguments:\n            teacher_outputs: Outputs from the teacher model.\n            student_outputs: Outputs from the student model.\n        Raises:\n            ValueError: If outputs are not compatible.\n        \"\"\"\n        keras.tree.assert_same_structure(teacher_outputs, student_outputs)\n\n    def validate_model_compatibility(self, teacher, student):\n        \"\"\"Validate that teacher and student models are compatible.\n\n        Arguments:\n            teacher: The teacher model.\n            student: The student model.","sourceCodeStart":42,"sourceCodeEnd":78,"githubUrl":"https://github.com/keras-team/keras/blob/7a34a03db60bf60042242d6a556fc3be119046a5/keras/src/distillation/distillation_loss.py#L42-L78","documentation":"Error \"Subclasses must implement compute_loss\" thrown in keras-team/keras.","triggerScenarios":"Thrown at keras/src/distillation/distillation_loss.py:60 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"7a34a03db60bf60042242d6a556fc3be119046a5","analyzedAt":"2026-08-25T21:25:25.994Z","schemaVersion":2},"datasetVersion":"2026-08-26T02:17:13.382Z"}