|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""Loss config options |
|
|
|
|
|
Loss weights are scheduled using a piecewise linear LR schedule. The schedule is defined by a list of boundaries and values. |
|
|
|
|
|
`boundaries` is a list of integers representing the iteration at which the weight value changes. |
|
|
`values` is a list of floats representing the weight value at each boundary. It should have one more value than `boundaries`. |
|
|
|
|
|
Example: |
|
|
A loss's weight will be: |
|
|
values[0] when step <= boundaries[0], |
|
|
values[1] when step > boundaries[0] and step <= boundaries[1], |
|
|
..., and |
|
|
values[-1] when step > boundaries[-1]. |
|
|
""" |
|
|
import attrs |
|
|
|
|
|
from cosmos_predict1.tokenizer.training.losses import ReduceMode |
|
|
from cosmos_predict1.tokenizer.training.losses.continuous import ( |
|
|
ColorLoss, |
|
|
FlowLoss, |
|
|
KLLoss, |
|
|
PerceptualLoss, |
|
|
TokenizerLoss, |
|
|
VideoConsistencyLoss, |
|
|
) |
|
|
from cosmos_predict1.utils.lazy_config import LazyCall as L |
|
|
from cosmos_predict1.utils.lazy_config import LazyDict |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class KLConfig: |
|
|
|
|
|
boundaries: list[int] = [0] |
|
|
values: list[float] = [1e-6] |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class PerceptualConfig: |
|
|
lpips_boundaries: list[int] = [500000] |
|
|
lpips_values: list[float] = [0.1, 0.073] |
|
|
|
|
|
layer_weights: list[float] = [1.0 / 2.6, 1.0 / 4.8, 1.0 / 3.7, 1.0 / 5.6, 10.0 / 1.5] |
|
|
|
|
|
gram_enabled: bool = True |
|
|
gram_boundaries: list[int] = [500000] |
|
|
gram_values: list[float] = [0.0, 0.062] |
|
|
|
|
|
corr_enabled: bool = False |
|
|
corr_boundaries: list[int] = [0] |
|
|
corr_values: list[float] = [0.0] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkpoint_activations: bool = False |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class ColorConfig: |
|
|
|
|
|
norm: str = "L1" |
|
|
boundaries: list[int] = [0] |
|
|
values: list[float] = [1.0] |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class FlowConfig: |
|
|
|
|
|
boundaries: list[int] = [250000] |
|
|
values: list[float] = [0.0, 0.01] |
|
|
scale: int = 2 |
|
|
|
|
|
dtype: str = "bfloat16" |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
checkpoint_activations: bool = False |
|
|
enabled: bool = False |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class VideoConsistencyConfig: |
|
|
|
|
|
boundaries: list[int] = [250000] |
|
|
values: list[float] = [0.0, 0.01] |
|
|
enabled: bool = False |
|
|
num_frames: int = 9 |
|
|
step: int = 1 |
|
|
|
|
|
|
|
|
@attrs.define(slots=False) |
|
|
class VideoLoss: |
|
|
|
|
|
color: LazyDict = L(ColorLoss)(config=ColorConfig()) |
|
|
kl: LazyDict = L(KLLoss)(config=KLConfig()) |
|
|
perceptual: LazyDict = L(PerceptualLoss)(config=PerceptualConfig()) |
|
|
flow: LazyDict = L(FlowLoss)(config=FlowConfig()) |
|
|
video_consistency: LazyDict = L(VideoConsistencyLoss)(config=VideoConsistencyConfig()) |
|
|
reduce: str = ReduceMode.MEAN.value |
|
|
|
|
|
|
|
|
VideoLossConfig: LazyDict = L(TokenizerLoss)(config=VideoLoss()) |
|
|
|