Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

inference script update

Shen-Chenhui9683ec66c733
diff --git a/opensora/models/vae/vae_3d_v2.py b/opensora/models/vae/vae_3d_v2.py
index ff770a6..76309ab 100644
--- a/opensora/models/vae/vae_3d_v2.py
+++ b/opensora/models/vae/vae_3d_v2.py
@@ -65,6 +65,7 @@ def lecam_reg(real_pred, fake_pred, ema_real_pred, ema_fake_pred):
return lecam_loss
# Open-Sora-Plan
+# Very bad, do not use
def r1_penalty(real_img, real_pred):
"""R1 regularization for discriminator. The core idea is to
penalize the gradient on real data alone: when the
@@ -82,6 +83,7 @@ def r1_penalty(real_img, real_pred):
return grad_penalty
# Open-Sora-Plan
+# Implementation as described by https://arxiv.org/abs/1704.00028 # TODO: checkout the codes
def gradient_penalty_loss(discriminator, real_data, fake_data, weight=None):
"""Calculate gradient penalty for wgan-gp.
diff --git a/scripts/inference-vae-v2.py b/scripts/inference-vae-v2.py
index 1f3a44d..65cb411 100644
--- a/scripts/inference-vae-v2.py
+++ b/scripts/inference-vae-v2.py
@@ -227,7 +227,7 @@ def main():
real_logits = discriminator(real_video.contiguous().detach())
fake_logits = discriminator(fake_video.contiguous().detach())
- disc_loss = disc_loss_fn(
+ weighted_d_adversarial_loss, lecam_loss, gradient_penalty_loss = disc_loss_fn(
real_logits,
fake_logits,
cfg.discriminator_start+1, # Hack to use discriminator
@@ -236,6 +236,8 @@ def main():
real_video = real_video if cfg.gradient_penalty_loss_weight is not None else None,
)
+ disc_loss = weighted_d_adversarial_loss + lecam_loss + gradient_penalty_loss
+
if cfg.ema_decay is not None:
# SCH: TODO: is this written properly like this for moving average? e.g. distributed training etc.
lecam_ema_real = lecam_ema_real * cfg.ema_decay + (1 - cfg.ema_decay) * torch.mean(real_logits.clone().detach())