o0o0o00o0 commited on
Commit
243b8a4
·
verified ·
1 Parent(s): f4e777f

Upload folder using huggingface_hub

Browse files
convert.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import torch, argparse
2
+ import torch.nn as nn
3
+ from diffusers import AutoencoderKL
4
+
5
+ def convert_module(model: AutoencoderKL):
6
+ conv_in = model.encoder.conv_in
7
+ conv_in_new = nn.Conv2d(
8
+ 4,
9
+ conv_in.out_channels,
10
+ conv_in.kernel_size,
11
+ conv_in.stride,
12
+ conv_in.padding
13
+ )
14
+ with torch.no_grad():
15
+ conv_in_new.weight[:, :3] = conv_in.weight
16
+ conv_in_new.weight[:, 3:] = 0
17
+ conv_in_new.bias.copy_(conv_in.bias)
18
+ model.encoder.conv_in = conv_in_new
19
+
20
+ conv_out = model.decoder.conv_out
21
+ conv_out_new = nn.Conv2d(
22
+ conv_out.in_channels,
23
+ 4,
24
+ conv_out.kernel_size,
25
+ conv_out.stride,
26
+ conv_out.padding
27
+ )
28
+ with torch.no_grad():
29
+ conv_out_new.weight[:3] = conv_out.weight
30
+ conv_out_new.weight[3:] = 0
31
+ conv_out_new.bias[:3] = conv_out.bias
32
+ conv_out_new.bias[3] = 1
33
+ model.decoder.conv_out = conv_out_new
34
+
35
+ config = dict(model._internal_dict)
36
+ config.update({
37
+ "in_channels": 4,
38
+ "out_channels": 4,
39
+ })
40
+ model._internal_dict = config
41
+
42
+ return model
43
+
44
+ def main():
45
+ arg_parse = argparse.ArgumentParser()
46
+ arg_parse.add_argument("--src", type=str, required=True, help="source model path")
47
+ arg_parse.add_argument("--dst", type=str, required=True, help="destination model path")
48
+ args = arg_parse.parse_args()
49
+
50
+ vae: AutoencoderKL = AutoencoderKL.from_pretrained(args.src)
51
+ converted_vae = convert_module(vae)
52
+ converted_vae.save_pretrained(args.dst)
53
+
54
+ if __name__ == '__main__':
55
+ main()
finetune_VAE/config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AutoencoderKL",
3
+ "_diffusers_version": "0.33.1",
4
+ "act_fn": "silu",
5
+ "block_out_channels": [
6
+ 128,
7
+ 256,
8
+ 512,
9
+ 512
10
+ ],
11
+ "down_block_types": [
12
+ "DownEncoderBlock2D",
13
+ "DownEncoderBlock2D",
14
+ "DownEncoderBlock2D",
15
+ "DownEncoderBlock2D"
16
+ ],
17
+ "force_upcast": true,
18
+ "in_channels": 4,
19
+ "latent_channels": 16,
20
+ "latents_mean": null,
21
+ "latents_std": null,
22
+ "layers_per_block": 2,
23
+ "mid_block_add_attention": true,
24
+ "norm_num_groups": 32,
25
+ "out_channels": 4,
26
+ "sample_size": 1024,
27
+ "scaling_factor": 0.3611,
28
+ "shift_factor": 0.1159,
29
+ "up_block_types": [
30
+ "UpDecoderBlock2D",
31
+ "UpDecoderBlock2D",
32
+ "UpDecoderBlock2D",
33
+ "UpDecoderBlock2D"
34
+ ],
35
+ "use_post_quant_conv": false,
36
+ "use_quant_conv": false
37
+ }
finetune_VAE/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e932691bed6fa7dc679e1b1f9a6c1e27f0d54d2cd79ef25fbfb51743d030e199
3
+ size 167671512
finetune_VAE/finetune_diffusion/pytorch_lora_weights.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:279ffa8385820f7c081e83aba61b75c3cfd9d4d623b5dd232b84d26dfc35a7ff
3
+ size 1434546472