hpcaitech/Open-Sora · error · ValueError
Unknown GAN loss '{self.disc_loss_type}'.
Error message
Unknown GAN loss '{self.disc_loss_type}'. What it means
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.
Source
Thrown at opensora/models/vae/losses.py:208
class DiscriminatorLoss(nn.Module):
def __init__(self, disc_start=2001, disc_factor=1.0, disc_loss_type="hinge"):
super().__init__()
assert disc_loss_type in ["hinge", "vanilla", "wgan-gp"]
self.disc_factor = disc_factor
self.disc_start = disc_start
self.disc_loss_type = disc_loss_type
if self.disc_loss_type == "hinge":
self.loss_fn = hinge_d_loss
elif self.disc_loss_type == "vanilla":
self.loss_fn = vanilla_d_loss
elif self.disc_loss_type == "wgan-gp":
self.loss_fn = wgan_gp_loss
else:
raise ValueError(f"Unknown GAN loss '{self.disc_loss_type}'.")
def forward(
self,
real_logits,
fake_logits,
global_step,
):
if self.disc_factor is not None and self.disc_factor > 0.0:
disc_factor = adopt_weight(self.disc_factor, global_step, threshold=self.disc_start)
disc_loss = self.loss_fn(real_logits, fake_logits)
weighted_discriminator_loss = disc_factor * disc_loss
else:
weighted_discriminator_loss = 0
return weighted_discriminator_loss
View on GitHub (pinned to 7ad6a96a13)
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
Example fix
# before loss = DiscLoss(disc_loss_type="logistic") # after loss = DiscLoss(disc_loss_type="hinge")
Defensive patterns
Strategy: validation
Validate before calling
assert disc_loss_type in {"hinge", "vanilla", "wgan-gp"}, f"unknown disc_loss_type {disc_loss_type!r}" Type guard
def is_valid_disc_loss(s: str) -> bool:
return s in {"hinge", "vanilla", "wgan-gp"} Prevention
- Whitelist loss names at config load
- Keep loss-name strings lowercase exact
- Test training config construction in CI
When it happens
Trigger: 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).
Common situations: Copying loss names from other GAN codebases (stylegan 'logistic', 'r1'); case mismatches; config edits while tuning VAE-GAN training.
Related errors
- dtype: {dtype}
- Unknown optimizer: {optimizer_name}
- block_type {block_type} is not supported
- ConvPixelUnshuffle downsample is not supported for video
- block_type {block_type} is not supported for downsampling
AI-assisted analysis of hpcaitech/Open-Sora@7ad6a96a13 (2026-08-28).
Data as JSON: /api/errors/773a73185497d049.
Report an issue: GitHub.