File size: 6,439 Bytes
31112ad |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 |
import os
import torch
from shared.utils.hf import build_hf_url
class family_handler:
@staticmethod
def query_supported_types():
return ["longcat_video", "longcat_avatar"]
@staticmethod
def query_family_maps():
return {}, {}
@staticmethod
def query_model_family():
return "longcat"
@staticmethod
def query_family_infos():
return {"longcat": (60, "LongCat")}
@staticmethod
def register_lora_cli_args(parser):
parser.add_argument(
"--lora-dir-longcat",
type=str,
default=os.path.join("loras", "longcat"),
help="Path to a directory that contains LongCat Video LoRAs",
)
parser.add_argument(
"--lora-dir-longcat-avatar",
type=str,
default=os.path.join("loras", "longcat_avatar"),
help="Path to a directory that contains LongCat Avatar LoRAs",
)
@staticmethod
def get_lora_dir(base_model_type, args):
if base_model_type == "longcat_avatar":
return args.lora_dir_longcat_avatar
return args.lora_dir_longcat
@staticmethod
def query_model_def(base_model_type, model_def):
extra_model_def = {
"frames_minimum": 5,
"frames_steps": 4,
"sliding_window": True,
"guidance_max_phases": 1,
"image_prompt_types_allowed": "TSVL",
"video_continuation": True,
"sample_solvers": [
("Auto (Continuation = Enhanced HF)", "auto"),
("Default", ""),
("Enhanced HF", "enhance_hf"),
("Distill", "distill"),
],
}
text_encoder_folder = "umt5-xxl"
extra_model_def["text_encoder_URLs"] = [
build_hf_url("DeepBeepMeep/Wan2.1", text_encoder_folder, "models_t5_umt5-xxl-enc-bf16.safetensors"),
build_hf_url("DeepBeepMeep/Wan2.1", text_encoder_folder, "models_t5_umt5-xxl-enc-quanto_int8.safetensors"),
]
extra_model_def["text_encoder_folder"] = text_encoder_folder
if base_model_type == "longcat_video":
extra_model_def.update(
{
"fps": 15,
"profiles_dir": ["longcat_video"],
}
)
elif base_model_type == "longcat_avatar":
extra_model_def.update(
{
"fps": 16,
"profiles_dir": [base_model_type],
"audio_guide_label": "Voice to follow",
"audio_guide2_label": "Voice to follow #2",
"audio_guidance": True,
"any_audio_prompt": True,
"audio_prompt_choices": True,
"image_ref_choices": {
"choices": [("None", ""), ("Anchor Reference Image", "KI")],
"letters_filter": "KI",
"visible": True,
"label": "Anchor Reference Image",
},
"reference_image_enabled": True,
"no_background_removal": True,
"image_prompt_types_allowed": "TSVL",
}
)
return extra_model_def
@staticmethod
def get_rgb_factors(base_model_type):
from shared.RGB_factors import get_rgb_factors
return get_rgb_factors("wan")
@staticmethod
def query_model_files(computeList, base_model_type, model_def=None):
download_def = [
{
"repoId": "DeepBeepMeep/Wan2.1",
"sourceFolderList": ["umt5-xxl", "chinese-wav2vec2-base"],
"fileList": [
["special_tokens_map.json", "spiece.model", "tokenizer.json", "tokenizer_config.json"],
[
"config.json",
"preprocessor_config.json",
"pytorch_model.bin",
"readme.txt",
],
],
}
]
download_def += [
{
"repoId": "DeepBeepMeep/Wan2.1",
"sourceFolderList": [""],
"fileList": [["Wan2.1_VAE_bf16.safetensors"]],
}
]
return download_def
@staticmethod
def load_model(
model_filename,
model_type,
base_model_type,
model_def,
quantizeTransformer=False,
text_encoder_quantization=None,
dtype=torch.bfloat16,
VAE_dtype=torch.float32,
mixed_precision_transformer=False,
save_quantized=False,
submodel_no_list=None,
text_encoder_filename=None,
**kwargs,
):
from .longcat_main import LongCatModel
longcat_model = LongCatModel(
checkpoint_dir="ckpts",
model_filename=model_filename,
model_type=model_type,
model_def=model_def,
base_model_type=base_model_type,
text_encoder_filename=text_encoder_filename,
quantizeTransformer=quantizeTransformer,
dtype=dtype,
VAE_dtype=VAE_dtype,
mixed_precision_transformer=mixed_precision_transformer,
save_quantized=save_quantized,
)
pipe = {
"transformer": longcat_model.transformer,
"vae": longcat_model.vae,
"text_encoder": longcat_model.text_encoder.model,
}
if longcat_model.audio_encoder is not None:
pipe["wav2vec"] = longcat_model.audio_encoder
return longcat_model, pipe
@staticmethod
def update_default_settings(base_model_type, model_def, ui_defaults):
ui_defaults.update(
{
"guidance_scale": 4.0,
"num_inference_steps": 50,
"audio_guidance_scale": 4.0,
"sliding_window_overlap": 13,
"sliding_window_size": 93,
}
)
if base_model_type == "longcat_video":
ui_defaults.update({"video_length": 93})
if base_model_type in ["longcat_avatar"]:
ui_defaults.update({"video_length": 93, "video_prompt_type": ""})
if ui_defaults.get("sample_solver", "") == "":
ui_defaults["sample_solver"] = "auto"
|