{"record":{"id":"2b1dd18fd77a8485","repo":"Stability-AI/generative-models","slug":"unknown-loss-type-self-loss-type","errorCode":null,"errorMessage":"Unknown loss type {self.loss_type}","messagePattern":"Unknown loss type (.+?)","errorType":"exception","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"sgm/modules/diffusionmodules/loss.py","lineNumber":105,"sourceCode":"            network, noised_input, sigmas, cond, **additional_model_inputs\n        )\n        w = append_dims(self.loss_weighting(sigmas), input.ndim)\n        return self.get_loss(model_output, input, w)\n\n    def get_loss(self, model_output, target, w):\n        if self.loss_type == \"l2\":\n            return torch.mean(\n                (w * (model_output - target) ** 2).reshape(target.shape[0], -1), 1\n            )\n        elif self.loss_type == \"l1\":\n            return torch.mean(\n                (w * (model_output - target).abs()).reshape(target.shape[0], -1), 1\n            )\n        elif self.loss_type == \"lpips\":\n            loss = self.lpips(model_output, target).reshape(-1)\n            return loss\n        else:\n            raise NotImplementedError(f\"Unknown loss type {self.loss_type}\")\n","sourceCodeStart":87,"sourceCodeEnd":106,"githubUrl":"https://github.com/Stability-AI/generative-models/blob/e8cd657656fa5d61688191730d0e03242bf4ed44/sgm/modules/diffusionmodules/loss.py#L87-L106","documentation":"VDenoisingWarmupLoss/VAEDiffusionLoss's get_loss only implements loss_type values such as 'l1', 'l2', and 'lpips'; any other configured loss type raises NotImplementedError inside the training step.","triggerScenarios":"Training a model whose config sets loss_type to an unimplemented string (e.g. 'huber', 'mse', 'ssim') so get_loss reaches the final else.","commonSituations":"Copied configs from other diffusion repos using 'mse'/'mae' naming, hand-edited loss_type entries, or newer configs run against older library code.","solutions":["Set loss_type to 'l1', 'l2', or 'lpips' in the training config","Fix the typo in loss_type","Add the new loss implementation to get_loss if a custom loss is required"],"exampleFix":"// before (yaml)\nloss_config:\n  loss_type: mse\n// after (yaml)\nloss_config:\n  loss_type: l2","handlingStrategy":"validation","validationCode":"SUPPORTED = {\"l1\", \"l2\", \"lpips\"}\nif loss_config[\"loss_type\"] not in SUPPORTED:\n    raise ValueError(f\"loss_type {loss_config['loss_type']!r} unsupported; choose from {SUPPORTED}\")","typeGuard":"def is_supported_loss(t) -> bool:\n    return t in (\"l1\", \"l2\", \"lpips\")","tryCatchPattern":"try:\n    loss = loss_module(x, t, context)\nexcept NotImplementedError as e:\n    raise ConfigError(f\"training config uses unsupported loss: {e}\") from e","preventionTips":["Check the source get_loss for the supported loss_type set before editing configs","Map common aliases (mse->l2, mae->l1) in your config loader","Pin library version when using configs copied from other repos"],"tags":["python","config","not-implemented","loss"],"backgroundTag":"invalid-enum-value","analyzedSha":"e8cd657656fa5d61688191730d0e03242bf4ed44","analyzedAt":"2026-08-29T11:23:43.234Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}