{"record":{"id":"773a73185497d049","repo":"hpcaitech/Open-Sora","slug":"unknown-gan-loss-self-disc-loss-type","errorCode":null,"errorMessage":"Unknown GAN loss '{self.disc_loss_type}'.","messagePattern":"Unknown GAN loss '(.+?)'\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"opensora/models/vae/losses.py","lineNumber":208,"sourceCode":"\n\nclass DiscriminatorLoss(nn.Module):\n    def __init__(self, disc_start=2001, disc_factor=1.0, disc_loss_type=\"hinge\"):\n        super().__init__()\n\n        assert disc_loss_type in [\"hinge\", \"vanilla\", \"wgan-gp\"]\n        self.disc_factor = disc_factor\n        self.disc_start = disc_start\n        self.disc_loss_type = disc_loss_type\n\n        if self.disc_loss_type == \"hinge\":\n            self.loss_fn = hinge_d_loss\n        elif self.disc_loss_type == \"vanilla\":\n            self.loss_fn = vanilla_d_loss\n        elif self.disc_loss_type == \"wgan-gp\":\n            self.loss_fn = wgan_gp_loss\n        else:\n            raise ValueError(f\"Unknown GAN loss '{self.disc_loss_type}'.\")\n\n    def forward(\n        self,\n        real_logits,\n        fake_logits,\n        global_step,\n    ):\n        if self.disc_factor is not None and self.disc_factor > 0.0:\n            disc_factor = adopt_weight(self.disc_factor, global_step, threshold=self.disc_start)\n            disc_loss = self.loss_fn(real_logits, fake_logits)\n            weighted_discriminator_loss = disc_factor * disc_loss\n        else:\n            weighted_discriminator_loss = 0\n\n        return weighted_discriminator_loss\n","sourceCodeStart":190,"sourceCodeEnd":224,"githubUrl":"https://github.com/hpcaitech/Open-Sora/blob/7ad6a96a135feb81f755c84fb391818718f6beb2/opensora/models/vae/losses.py#L190-L224","documentation":"The discriminator GAN loss wrapper in vae/losses.py selects its loss function by string: 'hinge', 'vanilla', or 'wgan-gp'. Any other disc_loss_type string falls through to the else and raises ValueError at construction time.","triggerScenarios":"Constructing the discriminator loss (class wrapping this __init__) with disc_loss_type not in {'hinge','vanilla','wgan-gp'} — e.g. 'wgan', 'logistic', 'ls', or a typo like 'Hinge' (case-sensitive).","commonSituations":"Copying loss names from other GAN codebases (stylegan 'logistic', 'r1'); case mismatches; config edits while tuning VAE-GAN training.","solutions":["Use one of: 'hinge', 'vanilla', or 'wgan-gp' (lowercase, exact)","Check the YAML/config string for typos and casing","If you need another loss, implement it as a function and assign self.loss_fn directly in a subclass"],"exampleFix":"# before\nloss = DiscLoss(disc_loss_type=\"logistic\")\n# after\nloss = DiscLoss(disc_loss_type=\"hinge\")","handlingStrategy":"validation","validationCode":"assert disc_loss_type in {\"hinge\", \"vanilla\", \"wgan-gp\"}, f\"unknown disc_loss_type {disc_loss_type!r}\"","typeGuard":"def is_valid_disc_loss(s: str) -> bool:\n    return s in {\"hinge\", \"vanilla\", \"wgan-gp\"}","tryCatchPattern":null,"preventionTips":["Whitelist loss names at config load","Keep loss-name strings lowercase exact","Test training config construction in CI"],"tags":["gan","training","loss","config"],"backgroundTag":"unsupported-enum-value","analyzedSha":"7ad6a96a135feb81f755c84fb391818718f6beb2","analyzedAt":"2026-08-28T16:58:37.171Z","schemaVersion":2},"datasetVersion":"2026-08-28T21:17:43.275Z"}