|
122 | 122 | "lumina2": ["model.diffusion_model.cap_embedder.0.weight", "cap_embedder.0.weight"], |
123 | 123 | "z-image-turbo": "cap_embedder.0.weight", |
124 | 124 | "z-image-turbo-controlnet": "control_all_x_embedder.2-1.weight", |
| 125 | + "z-image-turbo-controlnet-2.x": "control_layers.14.adaLN_modulation.0.weight", |
125 | 126 | "sana": [ |
126 | 127 | "blocks.0.cross_attn.q_linear.weight", |
127 | 128 | "blocks.0.cross_attn.q_linear.bias", |
|
221 | 222 | "cosmos-2.0-v2w-2B": {"pretrained_model_name_or_path": "nvidia/Cosmos-Predict2-2B-Video2World"}, |
222 | 223 | "cosmos-2.0-v2w-14B": {"pretrained_model_name_or_path": "nvidia/Cosmos-Predict2-14B-Video2World"}, |
223 | 224 | "z-image-turbo": {"pretrained_model_name_or_path": "Tongyi-MAI/Z-Image-Turbo"}, |
| 225 | + "z-image-turbo-controlnet": {"pretrained_model_name_or_path": "hlky/Z-Image-Turbo-Fun-Controlnet-Union"}, |
| 226 | + "z-image-turbo-controlnet-2.x": {"pretrained_model_name_or_path": "hlky/Z-Image-Turbo-Fun-Controlnet-Union-2.1"}, |
224 | 227 | } |
225 | 228 |
|
226 | 229 | # Use to configure model sample size when original config is provided |
@@ -780,6 +783,9 @@ def infer_diffusers_model_type(checkpoint): |
780 | 783 | else: |
781 | 784 | raise ValueError(f"Unexpected x_embedder shape: {x_embedder_shape} when loading Cosmos 2.0 model.") |
782 | 785 |
|
| 786 | + elif CHECKPOINT_KEY_NAMES["z-image-turbo-controlnet-2.x"] in checkpoint: |
| 787 | + model_type = "z-image-turbo-controlnet-2.x" |
| 788 | + |
783 | 789 | elif CHECKPOINT_KEY_NAMES["z-image-turbo-controlnet"] in checkpoint: |
784 | 790 | model_type = "z-image-turbo-controlnet" |
785 | 791 |
|
@@ -3891,47 +3897,12 @@ def update_state_dict(state_dict: dict[str, object], old_key: str, new_key: str) |
3891 | 3897 | return converted_state_dict |
3892 | 3898 |
|
3893 | 3899 |
|
3894 | | -def create_z_image_controlnet_config(checkpoint, **kwargs): |
3895 | | - v1_config = { |
3896 | | - "control_in_dim": 16, |
3897 | | - "control_layers_places": [0, 5, 10, 15, 20, 25], |
3898 | | - "dim": 3840, |
3899 | | - "n_heads": 30, |
3900 | | - "n_kv_heads": 30, |
3901 | | - "n_refiner_layers": 2, |
3902 | | - "norm_eps": 1e-05, |
3903 | | - "qk_norm": True, |
3904 | | - "all_f_patch_size": [1], |
3905 | | - "all_patch_size": [2], |
3906 | | - } |
3907 | | - v2_config = { |
3908 | | - "control_in_dim": 33, |
3909 | | - "control_layers_places": [0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 26, 28], |
3910 | | - "control_refiner_layers_places": [0, 1], |
3911 | | - "add_control_noise_refiner": True, |
3912 | | - "dim": 3840, |
3913 | | - "n_heads": 30, |
3914 | | - "n_kv_heads": 30, |
3915 | | - "n_refiner_layers": 2, |
3916 | | - "norm_eps": 1e-05, |
3917 | | - "qk_norm": True, |
3918 | | - "all_f_patch_size": [1], |
3919 | | - "all_patch_size": [2], |
3920 | | - } |
3921 | | - control_x_embedder_weight_shape = checkpoint["control_all_x_embedder.2-1.weight"].shape[1] |
3922 | | - if control_x_embedder_weight_shape == 64: |
3923 | | - return v1_config |
3924 | | - elif control_x_embedder_weight_shape == 132: |
3925 | | - return v2_config |
3926 | | - else: |
3927 | | - raise ValueError("Unknown Z-Image Turbo ControlNet type.") |
3928 | | - |
3929 | | - |
3930 | | -def convert_z_image_controlnet_checkpoint_to_diffusers(checkpoint, **kwargs): |
3931 | | - control_x_embedder_weight_shape = checkpoint["control_all_x_embedder.2-1.weight"].shape[1] |
3932 | | - if control_x_embedder_weight_shape == 64: |
| 3900 | +def convert_z_image_controlnet_checkpoint_to_diffusers(checkpoint, config, **kwargs): |
| 3901 | + if config["add_control_noise_refiner"] is None: |
| 3902 | + return checkpoint |
| 3903 | + elif config["add_control_noise_refiner"] == "control_noise_refiner": |
3933 | 3904 | return checkpoint |
3934 | | - elif control_x_embedder_weight_shape == 132: |
| 3905 | + elif config["add_control_noise_refiner"] == "control_layers": |
3935 | 3906 | converted_state_dict = { |
3936 | 3907 | key: checkpoint.pop(key) for key in list(checkpoint.keys()) if not key.startswith("control_noise_refiner.") |
3937 | 3908 | } |
|
0 commit comments