Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adapted pretrained model to training #371

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 17 additions & 1 deletion opensora/models/stdit/stdit2.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import numpy as np
import torch
import torch.nn as nn
import os
from einops import rearrange
from rotary_embedding_torch import RotaryEmbedding
from timm.models.layers import DropPath
Expand All @@ -23,6 +24,7 @@
)
from opensora.registry import MODELS
from transformers import PretrainedConfig, PreTrainedModel
from opensora.utils.ckpt_utils import load_checkpoint


class STDiT2Block(nn.Module):
Expand Down Expand Up @@ -502,8 +504,22 @@ def _basic_init(module):
@MODELS.register_module("STDiT2-XL/2")
def STDiT2_XL_2(from_pretrained=None, **kwargs):
if from_pretrained is not None:
model = STDiT2.from_pretrained(from_pretrained, **kwargs)
if os.path.isdir(from_pretrained) or os.path.isfile(from_pretrained):
# if it is a directory or a file, we load the checkpoint manually
config = STDiT2Config(
depth=28,
hidden_size=1152,
patch_size=(1, 2, 2),
num_heads=16, **kwargs
)
model = STDiT2(config)
load_checkpoint(model, from_pretrained)
return model
else:
# otherwise, we load the model from hugging face hub
return STDiT2.from_pretrained(from_pretrained)
else:
# create a new model
config = STDiT2Config(
depth=28,
hidden_size=1152,
Expand Down
3 changes: 1 addition & 2 deletions scripts/train.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ def main():
input_size=latent_size,
in_channels=vae.out_channels,
caption_channels=text_encoder.output_dim,
model_max_length=text_encoder.model_max_length,
dtype=dtype,
model_max_length=text_encoder.model_max_length
)
model_numel, model_numel_trainable = get_model_numel(model)
logger.info(
Expand Down