{"record":{"id":"56c5900a2a2016bc","repo":"lllyasviel/ControlNet","slug":"unknown-loss-type-loss-type","errorCode":null,"errorMessage":"unknown loss type '{loss_type}'","messagePattern":"unknown loss type '(.+?)'","errorType":"validation","errorClass":"NotImplementedError","httpStatus":null,"severity":"error","filePath":"ldm/models/diffusion/ddpm.py","lineNumber":378,"sourceCode":"\n    def get_v(self, x, noise, t):\n        return (\n                extract_into_tensor(self.sqrt_alphas_cumprod, t, x.shape) * noise -\n                extract_into_tensor(self.sqrt_one_minus_alphas_cumprod, t, x.shape) * x\n        )\n\n    def get_loss(self, pred, target, mean=True):\n        if self.loss_type == 'l1':\n            loss = (target - pred).abs()\n            if mean:\n                loss = loss.mean()\n        elif self.loss_type == 'l2':\n            if mean:\n                loss = torch.nn.functional.mse_loss(target, pred)\n            else:\n                loss = torch.nn.functional.mse_loss(target, pred, reduction='none')\n        else:\n            raise NotImplementedError(\"unknown loss type '{loss_type}'\")\n\n        return loss\n\n    def p_losses(self, x_start, t, noise=None):\n        noise = default(noise, lambda: torch.randn_like(x_start))\n        x_noisy = self.q_sample(x_start=x_start, t=t, noise=noise)\n        model_out = self.model(x_noisy, t)\n\n        loss_dict = {}\n        if self.parameterization == \"eps\":\n            target = noise\n        elif self.parameterization == \"x0\":\n            target = x_start\n        elif self.parameterization == \"v\":\n            target = self.get_v(x_start, noise, t)\n        else:\n            raise NotImplementedError(f\"Parameterization {self.parameterization} not yet supported\")\n","sourceCodeStart":360,"sourceCodeEnd":396,"githubUrl":"https://github.com/lllyasviel/ControlNet/blob/ed85cd1e25a5ed592f7d8178495b4483de0331bf/ldm/models/diffusion/ddpm.py#L360-L396","documentation":"DDPM get_loss supports only 'l1' and 'l2' loss types; any other value in the diffusion config's loss_type parameter raises NotImplementedError. Note the message is a plain string so the placeholder will not interpolate — the raw '{loss_type}' text appears.","triggerScenarios":"Configuring LatentDiffusion with parameters.loss_type set to something like 'mse', 'huber', or 'l1+l2', then running a training step (forward -> p_losses -> get_loss).","commonSituations":"Migrating configs from other diffusion repos (e.g. stable-diffusion uses 'L1'/'L2' uppercase in some forks); experimenting with perceptual losses not supported here.","solutions":["Set loss_type to 'l1' or 'l2' exactly (lowercase) in your diffusion YAML","If you need another loss, subclass DDPM and override get_loss","Check for accidental capitalization like 'L2'"],"exampleFix":"# before\nloss_type: mse\n# after\nloss_type: l2","handlingStrategy":"validation","validationCode":"assert loss_type in ('l1', 'l2'), f\"unsupported loss_type {loss_type!r}\"","typeGuard":"def is_valid_loss_type(lt: str) -> bool:\n    return lt in ('l1', 'l2')","tryCatchPattern":null,"preventionTips":["Validate diffusion YAML against the class's supported options at startup","Lowercase-normalize config strings before passing them in"],"tags":["diffusion","training","config","loss-function"],"backgroundTag":"unsupported-config-option","analyzedSha":"ed85cd1e25a5ed592f7d8178495b4483de0331bf","analyzedAt":"2026-08-27T12:58:54.167Z","schemaVersion":2},"datasetVersion":"2026-08-27T13:17:12.746Z"}