File size: 5,982 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 | import os
import torch
from shared.utils.hf import build_hf_url
class family_handler:
@staticmethod
def query_model_def(base_model_type, model_def):
extra_model_def = {
"image_outputs": True,
"guidance_max_phases": 0,
"fit_into_canvas_image_refs": 0,
"profiles_dir": [],
}
text_encoder_folder = "Qwen3"
extra_model_def["text_encoder_URLs"] = [
build_hf_url("DeepBeepMeep/Z-Image", text_encoder_folder, "qwen3_bf16.safetensors"),
build_hf_url("DeepBeepMeep/Z-Image", text_encoder_folder, "qwen3_quanto_bf16_int8.safetensors"),
]
extra_model_def["text_encoder_folder"] = text_encoder_folder
if base_model_type in ["z_image_control", "z_image_control2", "z_image_control2_1"]:
extra_model_def["mask_preprocessing"] = {
"selection":[ ""],
"visible": False
}
extra_model_def["control_net_weight_name"] = "Control"
extra_model_def["control_net_weight_size"] = 1
extra_model_def["guide_preprocessing"] = {
"selection": ["", "PV", "DV", "EV", "V"],
"labels" : { "V": "Use Z-Image Raw Format"},
}
if base_model_type in ["z_image_control2", "z_image_control2_1"]:
extra_model_def["mask_preprocessing"] = {
"selection":[ "", "A", "NA"],
"visible": False,
}
extra_model_def["inpaint_support"] = True
extra_model_def["inpaint_video_prompt_type"]= "VA"
# extra_model_def["image_ref_choices"] = {
# "choices":[("No Reference Image",""), ("Image is a Reference Image", "KI")],
# "default": "",
# "letters_filter": "KI",
# "label": "Reference Image for Inpainting",
# "visible": True,
# }
extra_model_def["NAG"] = base_model_type in ["z_image"]
return extra_model_def
@staticmethod
def query_supported_types():
return ["z_image", "z_image_control", "z_image_control2", "z_image_control2_1"]
@staticmethod
def query_family_maps():
models_eqv_map = {
"z_image_control2_1" : "z_image_control2",
}
models_comp_map = {}
return models_eqv_map, models_comp_map
@staticmethod
def query_model_family():
return "z_image"
@staticmethod
def query_family_infos():
return {"z_image": (120, "Z-Image") }
@staticmethod
def register_lora_cli_args(parser):
parser.add_argument(
"--lora-dir-z-image",
type=str,
default=os.path.join("loras", "z_image"),
help="Path to a directory that contains z image settings"
)
@staticmethod
def get_lora_dir(base_model_type, args):
return args.lora_dir_z_image
@staticmethod
def query_model_files(computeList, base_model_type, model_def=None):
download_def = [
{
"repoId": "DeepBeepMeep/Z-Image",
"sourceFolderList": ["Qwen3", ""],
"fileList": [
["tokenizer.json", "tokenizer_config.json", "vocab.json", "config.json", "merges.txt"],
["ZImageTurbo_VAE_bf16_config.json", "ZImageTurbo_VAE_bf16.safetensors", "ZImageTurbo_scheduler_config.json"],
],
}
]
return download_def
@staticmethod
def load_model(
model_filename,
model_type=None,
base_model_type=None,
model_def=None,
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 .z_image_main import model_factory
# Detect if this is a control variant (v1 or v2)
is_control = base_model_type in ["z_image_control", "z_image_control2", "z_image_control2_1"]
pipe_processor = model_factory(
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,
is_control=is_control,
)
pipe = {
"transformer": pipe_processor.transformer,
"text_encoder": pipe_processor.text_encoder,
"vae": pipe_processor.vae,
}
return pipe_processor, pipe
def get_rgb_factors(base_model_type ):
from shared.RGB_factors import get_rgb_factors
latent_rgb_factors, latent_rgb_factors_bias = get_rgb_factors("flux")
return latent_rgb_factors, latent_rgb_factors_bias
@staticmethod
def update_default_settings(base_model_type, model_def, ui_defaults):
ui_defaults.update(
{
"guidance_scale": 0.0,
"num_inference_steps": ui_defaults.get("num_inference_steps", 9),
"NAG_scale": ui_defaults.get("NAG_scale", 1.0),
"NAG_tau": ui_defaults.get("NAG_tau", 3.5),
"NAG_alpha": ui_defaults.get("NAG_alpha", 0.5),
}
)
# Add control defaults for z_image_control and z_image_control2
if base_model_type in ["z_image_control", "z_image_control2", "z_image_control2_1"]:
ui_defaults.update(
{
"control_net_weight": 0.75,
}
)
|