recoilme commited on
Commit
8592059
·
verified ·
1 Parent(s): 8353dfd

Upload folder using huggingface_hub

Browse files
samples/sample_0.jpg CHANGED

Git LFS Details

  • SHA256: 41f044b6a5cac9e969e6ffebfebc7bb861f31aff9b1290487faefc6ee158d3bc
  • Pointer size: 130 Bytes
  • Size of remote file: 83.5 kB

Git LFS Details

  • SHA256: c4e815d64f34c24b8e56359be835dfaed9442439a95a387076b86e76791dd216
  • Pointer size: 130 Bytes
  • Size of remote file: 97 kB
samples/sample_1.jpg CHANGED

Git LFS Details

  • SHA256: 90e7cfa798f1b791315f06c12114031a5e4a1f85290ff89c54ea740c7c1206d1
  • Pointer size: 131 Bytes
  • Size of remote file: 254 kB

Git LFS Details

  • SHA256: 7581064f43dc8e29b122e9e2c8e85d17db746999f8c96970d92ce3503e819d09
  • Pointer size: 131 Bytes
  • Size of remote file: 216 kB
samples/sample_2.jpg CHANGED

Git LFS Details

  • SHA256: c8babf008259f36a969abd71581df7b3a560720fb5bfbd2d2cbc576a8fc335de
  • Pointer size: 131 Bytes
  • Size of remote file: 199 kB

Git LFS Details

  • SHA256: 2a1dc60b95faf2711b2cc2d24ea50a676db5bd95884787f7b4d26a39f2431fbd
  • Pointer size: 131 Bytes
  • Size of remote file: 190 kB
samples/sample_decoded.jpg CHANGED

Git LFS Details

  • SHA256: 41f044b6a5cac9e969e6ffebfebc7bb861f31aff9b1290487faefc6ee158d3bc
  • Pointer size: 130 Bytes
  • Size of remote file: 83.5 kB

Git LFS Details

  • SHA256: c4e815d64f34c24b8e56359be835dfaed9442439a95a387076b86e76791dd216
  • Pointer size: 130 Bytes
  • Size of remote file: 97 kB
samples/sample_real.jpg CHANGED

Git LFS Details

  • SHA256: ceb8046ebc63541d081e999bbb4f05638f326ae46919bc10720c53864b99d495
  • Pointer size: 130 Bytes
  • Size of remote file: 88.4 kB

Git LFS Details

  • SHA256: 3cc35d9bbece554c4c56a1ab764588e545c4292654d3288e43f8abffa04d249a
  • Pointer size: 130 Bytes
  • Size of remote file: 87.6 kB
train_vae.py CHANGED
@@ -28,12 +28,12 @@ from collections import deque
28
 
29
  # --------------------------- Параметры ---------------------------
30
  ds_path = "/workspace/d23"
31
- project = "vae"
32
  batch_size = 1
33
- base_learning_rate = 2e-6
34
  min_learning_rate = 8e-8
35
- num_epochs = 25
36
- sample_interval_share = 2
37
  use_wandb = True
38
  save_model = True
39
  use_decay = True
@@ -52,7 +52,7 @@ clip_grad_norm = 1.0
52
  mixed_precision = "no"
53
  gradient_accumulation_steps = 16
54
  generated_folder = "samples"
55
- save_as = "vae"
56
  num_workers = 0
57
  device = None
58
 
@@ -171,10 +171,9 @@ else:
171
  if hasattr(core, "decoder"):
172
  if hasattr(core.decoder, "up_blocks") and len(core.decoder.up_blocks) > 0:
173
  # --- только 0-й up_block ---
174
- # for name, p in core.decoder.up_blocks[0].named_parameters():
175
- for name, p in core.decoder.up_blocks.named_parameters():
176
  p.requires_grad = True
177
- unfrozen_param_names.append(f"decoder.up_blocks.0.{name}")
178
  else:
179
  print("[WARN] Decoder has no up_blocks — fallback to full decoder")
180
  for name, p in core.decoder.named_parameters():
@@ -232,12 +231,12 @@ class PngFolderDataset(Dataset):
232
  scale = resize_long_side / float(long)
233
  new_w = int(round(w * scale))
234
  new_h = int(round(h * scale))
235
- return img.resize((new_w, new_h), Image.LANCZOS)
236
 
237
  def random_crop(img, sz):
238
  w, h = img.size
239
  if w < sz or h < sz:
240
- img = img.resize((max(sz, w), max(sz, h)), Image.LANCZOS)
241
  x = random.randint(0, max(1, img.width - sz))
242
  y = random.randint(0, max(1, img.height - sz))
243
  return img.crop((x, y, x + sz, y + sz))
 
28
 
29
  # --------------------------- Параметры ---------------------------
30
  ds_path = "/workspace/d23"
31
+ project = "vae2"
32
  batch_size = 1
33
+ base_learning_rate = 6e-6
34
  min_learning_rate = 8e-8
35
+ num_epochs = 20
36
+ sample_interval_share = 10
37
  use_wandb = True
38
  save_model = True
39
  use_decay = True
 
52
  mixed_precision = "no"
53
  gradient_accumulation_steps = 16
54
  generated_folder = "samples"
55
+ save_as = "vae2"
56
  num_workers = 0
57
  device = None
58
 
 
171
  if hasattr(core, "decoder"):
172
  if hasattr(core.decoder, "up_blocks") and len(core.decoder.up_blocks) > 0:
173
  # --- только 0-й up_block ---
174
+ for name, p in core.decoder.up_blocks[0].named_parameters():
 
175
  p.requires_grad = True
176
+ unfrozen_param_names.append(f"{name}")
177
  else:
178
  print("[WARN] Decoder has no up_blocks — fallback to full decoder")
179
  for name, p in core.decoder.named_parameters():
 
231
  scale = resize_long_side / float(long)
232
  new_w = int(round(w * scale))
233
  new_h = int(round(h * scale))
234
+ return img.resize((new_w, new_h), Image.BICUBIC)
235
 
236
  def random_crop(img, sz):
237
  w, h = img.size
238
  if w < sz or h < sz:
239
+ img = img.resize((max(sz, w), max(sz, h)), Image.BICUBIC)
240
  x = random.randint(0, max(1, img.width - sz))
241
  y = random.randint(0, max(1, img.height - sz))
242
  return img.crop((x, y, x + sz, y + sz))
transfer_simplevae.ipynb CHANGED
@@ -82,7 +82,7 @@
82
  " \"DownEncoderBlock2D\",\n",
83
  " ],\n",
84
  " \"latent_channels\": 16,\n",
85
- " \"up_block_out_channels\": [128, 256, 512, 512, 512], # +1 блок\n",
86
  " \"up_block_types\": [\n",
87
  " \"UpDecoderBlock2D\",\n",
88
  " \"UpDecoderBlock2D\",\n",
 
82
  " \"DownEncoderBlock2D\",\n",
83
  " ],\n",
84
  " \"latent_channels\": 16,\n",
85
+ " \"up_block_out_channels\": [64, 128, 256, 512, 512], # +1 блок\n",
86
  " \"up_block_types\": [\n",
87
  " \"UpDecoderBlock2D\",\n",
88
  " \"UpDecoderBlock2D\",\n",
transfer_simplevae2.ipynb ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "cells": [
3
+ {
4
+ "cell_type": "code",
5
+ "execution_count": 1,
6
+ "id": "c15deb04-94a0-4073-a174-adcd22af10b8",
7
+ "metadata": {},
8
+ "outputs": [
9
+ {
10
+ "name": "stdout",
11
+ "output_type": "stream",
12
+ "text": [
13
+ "✅ Создана новая модель: <class 'diffusers.models.autoencoders.autoencoder_asym_kl.AsymmetricAutoencoderKL'>\n"
14
+ ]
15
+ },
16
+ {
17
+ "name": "stderr",
18
+ "output_type": "stream",
19
+ "text": [
20
+ "The config attributes {'block_out_channels': [64, 128, 256, 512, 512], 'force_upcast': False} were passed to AsymmetricAutoencoderKL, but are not expected and will be ignored. Please verify your config.json configuration file.\n"
21
+ ]
22
+ },
23
+ {
24
+ "name": "stdout",
25
+ "output_type": "stream",
26
+ "text": [
27
+ "\n",
28
+ "--- Перенос весов ---\n"
29
+ ]
30
+ },
31
+ {
32
+ "name": "stderr",
33
+ "output_type": "stream",
34
+ "text": [
35
+ "100%|██████████| 248/248 [00:00<00:00, 114887.05it/s]"
36
+ ]
37
+ },
38
+ {
39
+ "name": "stdout",
40
+ "output_type": "stream",
41
+ "text": [
42
+ "\n",
43
+ "✅ Перенос завершён.\n",
44
+ "Статистика:\n",
45
+ " перенесено: 216\n",
46
+ " дублировано: 26\n",
47
+ " пропущено: 0\n"
48
+ ]
49
+ },
50
+ {
51
+ "name": "stderr",
52
+ "output_type": "stream",
53
+ "text": [
54
+ "\n"
55
+ ]
56
+ }
57
+ ],
58
+ "source": [
59
+ "from diffusers.models import AsymmetricAutoencoderKL, AutoencoderKL\n",
60
+ "import torch\n",
61
+ "from tqdm import tqdm\n",
62
+ "\n",
63
+ "# ---- Конфиг новой модели ----\n",
64
+ "config = {\n",
65
+ " \"_class_name\": \"AsymmetricAutoencoderKL\",\n",
66
+ " \"act_fn\": \"silu\",\n",
67
+ " \"in_channels\": 3,\n",
68
+ " \"out_channels\": 3,\n",
69
+ " \"scaling_factor\": 1.0,\n",
70
+ " \"norm_num_groups\": 32,\n",
71
+ " \"down_block_out_channels\": [128, 256, 512, 512],\n",
72
+ " \"down_block_types\": [\n",
73
+ " \"DownEncoderBlock2D\",\n",
74
+ " \"DownEncoderBlock2D\",\n",
75
+ " \"DownEncoderBlock2D\",\n",
76
+ " \"DownEncoderBlock2D\",\n",
77
+ " ],\n",
78
+ " \"latent_channels\": 16,\n",
79
+ " # Новый UpDecoderBlock добавлен в начало\n",
80
+ " \"up_block_out_channels\": [64, 128, 256, 512, 512],\n",
81
+ " \"up_block_types\": [\n",
82
+ " \"UpDecoderBlock2D\",\n",
83
+ " \"UpDecoderBlock2D\",\n",
84
+ " \"UpDecoderBlock2D\",\n",
85
+ " \"UpDecoderBlock2D\",\n",
86
+ " \"UpDecoderBlock2D\",\n",
87
+ " ],\n",
88
+ "}\n",
89
+ "\n",
90
+ "# ---- Создание пустой асимметричной модели ----\n",
91
+ "vae = AsymmetricAutoencoderKL(\n",
92
+ " act_fn=config[\"act_fn\"],\n",
93
+ " down_block_out_channels=config[\"down_block_out_channels\"],\n",
94
+ " down_block_types=config[\"down_block_types\"],\n",
95
+ " latent_channels=config[\"latent_channels\"],\n",
96
+ " up_block_out_channels=config[\"up_block_out_channels\"],\n",
97
+ " up_block_types=config[\"up_block_types\"],\n",
98
+ " in_channels=config[\"in_channels\"],\n",
99
+ " out_channels=config[\"out_channels\"],\n",
100
+ " scaling_factor=config[\"scaling_factor\"],\n",
101
+ " norm_num_groups=config[\"norm_num_groups\"],\n",
102
+ " layers_per_down_block=2,\n",
103
+ " layers_per_up_block=2,\n",
104
+ " sample_size=1024\n",
105
+ ")\n",
106
+ "\n",
107
+ "vae.save_pretrained(\"asymmetric_vae_empty\")\n",
108
+ "print(\"✅ Создана новая модель:\", type(vae))\n",
109
+ "\n",
110
+ "# ---- Функция переноса весов старого VAE ----\n",
111
+ "def transfer_weights(old_path, new_path, save_path=\"asymmetric_vae\", device=\"cuda\", dtype=torch.float16):\n",
112
+ " old_vae = AutoencoderKL.from_pretrained(old_path, subfolder=\"vae\").to(device, dtype=dtype)\n",
113
+ " new_vae = AsymmetricAutoencoderKL.from_pretrained(new_path).to(device, dtype=dtype)\n",
114
+ "\n",
115
+ " old_sd = old_vae.state_dict()\n",
116
+ " new_sd = new_vae.state_dict()\n",
117
+ "\n",
118
+ " transferred_keys = set()\n",
119
+ " transfer_stats = {\"перенесено\": 0, \"дублировано\": 0, \"пропущено\": 0}\n",
120
+ "\n",
121
+ " print(\"\\n--- Перенос весов ---\")\n",
122
+ " for k, v in tqdm(old_sd.items()):\n",
123
+ " # Копирование энкодера и прочих совпадающих ключей\n",
124
+ " if (\"encoder\" in k) or (\"quant_conv\" in k) or (\"post_quant_conv\" in k):\n",
125
+ " if k in new_sd and new_sd[k].shape == v.shape:\n",
126
+ " new_sd[k] = v.clone()\n",
127
+ " transferred_keys.add(k)\n",
128
+ " transfer_stats[\"перенесено\"] += 1\n",
129
+ " continue\n",
130
+ "\n",
131
+ " # Копирование декодера (без сдвига)\n",
132
+ " if \"decoder.up_blocks\" in k:\n",
133
+ " if k in new_sd and new_sd[k].shape == v.shape:\n",
134
+ " new_sd[k] = v.clone()\n",
135
+ " transferred_keys.add(k)\n",
136
+ " transfer_stats[\"перенесено\"] += 1\n",
137
+ " continue\n",
138
+ "\n",
139
+ " # Дублирование весов старого первого 512→512 блока в новый блок 64→128 для апскейла\n",
140
+ " ref_prefix = \"decoder.up_blocks.1\"\n",
141
+ " new_prefix = \"decoder.up_blocks.0\"\n",
142
+ " for k, v in old_sd.items():\n",
143
+ " if k.startswith(ref_prefix) and new_prefix + k[len(ref_prefix):] in new_sd:\n",
144
+ " new_k = k.replace(ref_prefix, new_prefix)\n",
145
+ " if new_sd[new_k].shape == v.shape:\n",
146
+ " new_sd[new_k] = v.clone()\n",
147
+ " transferred_keys.add(new_k)\n",
148
+ " transfer_stats[\"дублировано\"] += 1\n",
149
+ "\n",
150
+ " # Загрузка и сохранение\n",
151
+ " new_vae.load_state_dict(new_sd, strict=False)\n",
152
+ " new_vae.save_pretrained(save_path)\n",
153
+ "\n",
154
+ " print(\"\\n✅ Перенос завершён.\")\n",
155
+ " print(\"Статистика:\")\n",
156
+ " for k, v in transfer_stats.items():\n",
157
+ " print(f\" {k}: {v}\")\n",
158
+ "\n",
159
+ "# ---- Запуск переноса ----\n",
160
+ "transfer_weights(\"AiArtLab/simplevae\", \"asymmetric_vae_empty\", save_path=\"vae2\")\n"
161
+ ]
162
+ },
163
+ {
164
+ "cell_type": "code",
165
+ "execution_count": 8,
166
+ "id": "65653a65-e7c2-4b67-bc17-62c21cfd1db8",
167
+ "metadata": {},
168
+ "outputs": [
169
+ {
170
+ "name": "stdout",
171
+ "output_type": "stream",
172
+ "text": [
173
+ "Collecting hf_transfer\n",
174
+ " Downloading hf_transfer-0.1.9-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.metadata (1.7 kB)\n",
175
+ "Downloading hf_transfer-0.1.9-cp38-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (3.6 MB)\n",
176
+ "\u001b[2K \u001b[90m━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\u001b[0m \u001b[32m3.6/3.6 MB\u001b[0m \u001b[31m34.5 MB/s\u001b[0m \u001b[33m0:00:00\u001b[0m\n",
177
+ "\u001b[?25hInstalling collected packages: hf_transfer\n",
178
+ "Successfully installed hf_transfer-0.1.9\n"
179
+ ]
180
+ }
181
+ ],
182
+ "source": [
183
+ "!pip install hf_transfer"
184
+ ]
185
+ },
186
+ {
187
+ "cell_type": "code",
188
+ "execution_count": null,
189
+ "id": "59fcafb9-6d89-49b4-8362-b4891f591687",
190
+ "metadata": {},
191
+ "outputs": [],
192
+ "source": []
193
+ }
194
+ ],
195
+ "metadata": {
196
+ "kernelspec": {
197
+ "display_name": "Python 3 (ipykernel)",
198
+ "language": "python",
199
+ "name": "python3"
200
+ },
201
+ "language_info": {
202
+ "codemirror_mode": {
203
+ "name": "ipython",
204
+ "version": 3
205
+ },
206
+ "file_extension": ".py",
207
+ "mimetype": "text/x-python",
208
+ "name": "python",
209
+ "nbconvert_exporter": "python",
210
+ "pygments_lexer": "ipython3",
211
+ "version": "3.12.3"
212
+ }
213
+ },
214
+ "nbformat": 4,
215
+ "nbformat_minor": 5
216
+ }
vae/config.json CHANGED
@@ -3,13 +3,6 @@
3
  "_diffusers_version": "0.35.1",
4
  "_name_or_path": "vae",
5
  "act_fn": "silu",
6
- "block_out_channels": [
7
- 128,
8
- 256,
9
- 512,
10
- 512,
11
- 512
12
- ],
13
  "down_block_out_channels": [
14
  128,
15
  256,
@@ -22,7 +15,6 @@
22
  "DownEncoderBlock2D",
23
  "DownEncoderBlock2D"
24
  ],
25
- "force_upcast": false,
26
  "in_channels": 3,
27
  "latent_channels": 16,
28
  "layers_per_down_block": 2,
 
3
  "_diffusers_version": "0.35.1",
4
  "_name_or_path": "vae",
5
  "act_fn": "silu",
 
 
 
 
 
 
 
6
  "down_block_out_channels": [
7
  128,
8
  256,
 
15
  "DownEncoderBlock2D",
16
  "DownEncoderBlock2D"
17
  ],
 
18
  "in_channels": 3,
19
  "latent_channels": 16,
20
  "layers_per_down_block": 2,
vae2/config.json ADDED
@@ -0,0 +1,48 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_class_name": "AsymmetricAutoencoderKL",
3
+ "_diffusers_version": "0.35.1",
4
+ "_name_or_path": "vae2",
5
+ "act_fn": "silu",
6
+ "block_out_channels": [
7
+ 64,
8
+ 128,
9
+ 256,
10
+ 512,
11
+ 512
12
+ ],
13
+ "down_block_out_channels": [
14
+ 128,
15
+ 256,
16
+ 512,
17
+ 512
18
+ ],
19
+ "down_block_types": [
20
+ "DownEncoderBlock2D",
21
+ "DownEncoderBlock2D",
22
+ "DownEncoderBlock2D",
23
+ "DownEncoderBlock2D"
24
+ ],
25
+ "force_upcast": false,
26
+ "in_channels": 3,
27
+ "latent_channels": 16,
28
+ "layers_per_down_block": 2,
29
+ "layers_per_up_block": 2,
30
+ "norm_num_groups": 32,
31
+ "out_channels": 3,
32
+ "sample_size": 1024,
33
+ "scaling_factor": 1.0,
34
+ "up_block_out_channels": [
35
+ 64,
36
+ 128,
37
+ 256,
38
+ 512,
39
+ 512
40
+ ],
41
+ "up_block_types": [
42
+ "UpDecoderBlock2D",
43
+ "UpDecoderBlock2D",
44
+ "UpDecoderBlock2D",
45
+ "UpDecoderBlock2D",
46
+ "UpDecoderBlock2D"
47
+ ]
48
+ }
vae2/diffusion_pytorch_model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:22865ffa9f97886f766a9ee38537a8e4cab2b9ad1672a2a3c600152235ce392b
3
+ size 364540148