Skip to content

Open-Sora: Democratizing Efficient Video Production for All

Python

[exp]

Zangwei Zhengc23fe85a708e
diff --git a/configs/opensora-v1-2/inference/xl-rf.py b/configs/opensora-v1-2/inference/xl-rf.py
index 2192ae5..3dff9e0 100644
--- a/configs/opensora-v1-2/inference/xl-rf.py
+++ b/configs/opensora-v1-2/inference/xl-rf.py
@@ -6,7 +6,7 @@ multi_resolution = "STDiT2"
model = dict(
type="STDiT3-XL/2",
- from_pretrained="PixArt-Sigma-XL-2-2K-MS.pth",
+ from_pretrained=None,
qk_norm=True,
enable_flashattn=True,
enable_layernorm_kernel=True,
@@ -26,7 +26,8 @@ text_encoder = dict(
)
scheduler = dict(
type="rflow",
- use_discrete_timesteps=True,
+ use_discrete_timesteps=False,
+ use_timestep_transform=True,
num_sampling_steps=50,
cfg_scale=4.5,
)
diff --git a/configs/opensora-v1-2/train/adapt-rf.py b/configs/opensora-v1-2/train/adapt-rf.py
index 2cfd00a..9c641ba 100644
--- a/configs/opensora-v1-2/train/adapt-rf.py
+++ b/configs/opensora-v1-2/train/adapt-rf.py
@@ -55,8 +55,8 @@ text_encoder = dict(
scheduler = dict(
type="rflow",
use_discrete_timesteps=False,
- sample_method="logit-normal",
use_timestep_transform=True,
+ sample_method="logit-normal",
)
# Others
@@ -69,6 +69,8 @@ log_every = 10
ckpt_every = 500
load = None
-batch_size = 10 # only for logging
-lr = 2e-5
+batch_size = None
+lr = 1e-4
grad_clip = 1.0
+ema_decay = 0.99
+adam_eps = 1e-15
diff --git a/opensora/schedulers/rf/__init__.py b/opensora/schedulers/rf/__init__.py
index 3a3465c..2ea0ee3 100644
--- a/opensora/schedulers/rf/__init__.py
+++ b/opensora/schedulers/rf/__init__.py
@@ -62,7 +62,10 @@ class RFLOW:
timesteps = [int(round(t)) for t in timesteps]
if self.use_timestep_transform:
- timesteps = [timestep_transform(t, additional_args, scale=self.cfg_scale) for t in timesteps]
+ timesteps = [
+ timestep_transform(t, additional_args, scale=self.cfg_scale, num_timesteps=self.num_timesteps)
+ for t in timesteps
+ ]
for i, t in enumerate(timesteps):
z_in = torch.cat([z, z], 0)
diff --git a/opensora/schedulers/rf/rectified_flow.py b/opensora/schedulers/rf/rectified_flow.py
index 577254e..9570a23 100644
--- a/opensora/schedulers/rf/rectified_flow.py
+++ b/opensora/schedulers/rf/rectified_flow.py
@@ -7,11 +7,13 @@ from ..iddpm.gaussian_diffusion import _extract_into_tensor, mean_flat
# and https://github.com/magic-research/piecewise-rectified-flow/blob/main/src/scheduler_perflow.py
-def timestep_transform(t, model_kwargs, base_resolution=512 * 512, base_num_frames=1, scale=1.0):
+def timestep_transform(t, model_kwargs, base_resolution=512 * 512, base_num_frames=1, scale=1.0, num_timesteps=1):
+ t = t / num_timesteps
resolution = model_kwargs["height"] * model_kwargs["width"]
num_frames = model_kwargs["num_frames"]
ratio = (resolution / base_resolution).sqrt() * (num_frames / base_num_frames).sqrt() * scale
new_t = ratio * t / (1 + (ratio - 1) * t)
+ new_t = new_t * num_timesteps
return new_t
@@ -59,9 +61,7 @@ class RFlowScheduler:
t = self.sample_t(x_start) * self.num_timesteps
if self.use_timestep_transform:
- t = t / self.num_timesteps
- t = timestep_transform(t, model_kwargs, scale=self.transform_scale)
- t = t * self.num_timesteps
+ t = timestep_transform(t, model_kwargs, scale=self.transform_scale, num_timesteps=self.num_timesteps)
if model_kwargs is None:
model_kwargs = {}
diff --git a/scripts/train.py b/scripts/train.py
index 1c14fd7..26f0964 100644
--- a/scripts/train.py
+++ b/scripts/train.py
@@ -159,6 +159,7 @@ def main():
lr=cfg.lr,
weight_decay=0,
adamw_mode=True,
+ eps=cfg.get("adam_eps", 1e-8),
)
lr_scheduler = None
@@ -260,7 +261,7 @@ def main():
optimizer.zero_grad()
# Update EMA
- update_ema(ema, model.module, optimizer=optimizer)
+ update_ema(ema, model.module, optimizer=optimizer, decay=cfg.get("ema_decay", 0.9999))
# Log loss values:
all_reduce_mean(loss)