Open-Sora: Democratizing Efficient Video Production for All
Python
enable end to end loss training
Shen-Chenhui8d914707f87d
diff --git a/configs/vae_magvit_v2/train/17x128x128.py b/configs/vae_magvit_v2/train/17x128x128.pyindex cda536b..98e91c4 100644--- a/configs/vae_magvit_v2/train/17x128x128.py+++ b/configs/vae_magvit_v2/train/17x128x128.py@@ -1,63 +1,73 @@num_frames = 17-frame_interval = 3image_size = (128, 128)--# Define dataset-root = None-data_path = "CSV_PATH"-use_image_transform = False-num_workers = 4-video_contains_first_frame = True+dataset = dict(+ type="VideoTextDataset",+ data_path=None,+ num_frames=num_frames,+ frame_interval=3,+ image_size=image_size,+ get_text=False,+)# Define acceleration+num_workers = 4dtype = "bf16"grad_checkpoint = Trueplugin = "zero2"sp_size = 1+use_pipeline = True+video_contains_first_frame = True# Define model-+vae_2d = dict(+ type="VideoAutoencoderKL",+ from_pretrained="stabilityai/sd-vae-ft-ema",+ # SDXL+)model = dict(type="VAE_MAGVIT_V2",- in_out_channels = 3,- latent_embed_dim = 256,- filters = 128,- num_res_blocks = 4,- channel_multipliers = (1, 2, 2, 4),- temporal_downsample = (False, True, True),- num_groups = 32, # for nn.GroupNorm- kl_embed_dim = 64,- activation_fn = 'swish',- separate_first_frame_encoding = False,- custom_conv_padding = None+ in_out_channels=4,+ latent_embed_dim=64,+ filters=128,+ num_res_blocks=4,+ channel_multipliers=(1, 2, 2, 4),+ temporal_downsample=(False, True, True),+ num_groups=32, # for nn.GroupNorm+ kl_embed_dim=4,+ activation_fn="swish",+ separate_first_frame_encoding=False,+ disable_space=True,+ encoder_double_z=True,+ custom_conv_padding=None,)discriminator = dict(type="DISCRIMINATOR_3D",- image_size = image_size,- num_frames = num_frames,- in_channels = 3,- filters = 128,- channel_multipliers = (2,4,4,4,4) # (2,4,4,4) for 64x64 resolution+ image_size=image_size, # NOTE: here image size is different+ num_frames=num_frames,+ in_channels=3,+ filters=128,+ use_pretrained=True, # NOTE: set to False only if we want to disable load+ channel_multipliers = (2,4,4,4,4), # (2,4,4,4) for 64x64 resolution+ # channel_multipliers=(2, 4, 4), # since on intermediate layer dimension ofs z)-# loss weights-logvar_init=0.0+# loss weights+logvar_init = 0.0kl_loss_weight = 0.000001-perceptual_loss_weight = 0.1 # use vgg is not None and more than 0-discriminator_factor = 1.0 # for discriminator adversarial loss-# discriminator_loss_weight = 0.5 # for generator adversarial loss-generator_factor = 0.1 # SCH: generator adversarial loss, MAGVIT v2 uses 0.1-lecam_loss_weight = None # NOTE: MAVGIT v2 use 0.001-# discriminator_loss_type="non-saturating"-# generator_loss_type="non-saturating"-discriminator_loss_type="hinge"-generator_loss_type="hinge"-discriminator_start = -1 # 50000 NOTE: change to correct val, debug use -1 for now-gradient_penalty_loss_weight = None # 10 # SCH: MAGVIT uses 10, opensora plan doesn't use+perceptual_loss_weight = 0.1 # use vgg is not None and more than 0+discriminator_factor = 1.0 # for discriminator adversarial loss+generator_factor = 0.1 # SCH: generator adversarial loss, MAGVIT v2 uses 0.1+lecam_loss_weight = None # NOTE: MAVGIT v2 use 0.001+discriminator_loss_type = "non-saturating"+generator_loss_type = "non-saturating"+# discriminator_loss_type="hinge"+# generator_loss_type="hinge"+discriminator_start = 2000 # 5000 # 8k data / (8*1) = 1000 steps per epoch+gradient_penalty_loss_weight = None # 10 # SCH: MAGVIT uses 10, opensora plan doesn't useema_decay = 0.999 # ema decay factor for generator@@ -67,17 +77,19 @@ outputs = "outputs"wandb = False# Training-''' NOTE:+""" NOTE:magvit uses about # samples (K) * epochs ~ 2-5 K, num_frames = 4, reso = 128-==> ours num_frams = 16, reso = 256, so samples (K) * epochs ~ [500 - 1200],+==> ours num_frams = 16, reso = 256, so samples (K) * epochs ~ [500 - 1200],3-6 epochs for pexel, from pexel observation its correct-'''+"""-epochs = 10+epochs = 100log_every = 1-ckpt_every = 1000++ckpt_every = 500load = None-batch_size = 4+batch_size = 1+lr = 1e-4grad_clip = 1.0diff --git a/scripts/train-vae-v2.py b/scripts/train-vae-v2.pyindex 4e15c1c..e8a06f6 100644--- a/scripts/train-vae-v2.py+++ b/scripts/train-vae-v2.py@@ -326,14 +326,16 @@ def main():# ===== Spatial VAE =====if cfg.get("use_pipeline") == True:with torch.no_grad():- video = vae_2d.encode(video)+ t_video = vae_2d.encode(video)# ====== VAE ======- recon_video, posterior = vae(- video,+ t_recon_video, posterior = vae(+ t_video,video_contains_first_frame=video_contains_first_frame,)+ recon_video = vae_2d.decode(t_recon_video)+# ====== Generator Loss ======# simple nll lossnll_loss, weighted_nll_loss, weighted_kl_loss = vae_loss_fn(