Update src/pipeline.py
Browse files- src/pipeline.py +5 -3
src/pipeline.py
CHANGED
|
@@ -9,7 +9,7 @@ from loss import SchedulerWrapper, get_instance
|
|
| 9 |
import time
|
| 10 |
from onediffx import compile_pipe, save_pipe, load_pipe
|
| 11 |
from torch.cuda.amp import autocast, GradScaler
|
| 12 |
-
|
| 13 |
instance = None
|
| 14 |
loss_fn = None
|
| 15 |
optimizer = None
|
|
@@ -84,6 +84,7 @@ def load_pipeline(pipeline=None) -> StableDiffusionXLPipeline:
|
|
| 84 |
optimizer = torch.optim.Adam([param for layer in trainable_layers for param in layer.parameters()], lr=0.001)
|
| 85 |
print(len([param for layer in trainable_layers for param in layer.parameters()]))
|
| 86 |
instance.train()
|
|
|
|
| 87 |
|
| 88 |
device = 'cuda'
|
| 89 |
mul = torch.nn.Parameter(torch.tensor(1.2, requires_grad=True, device=device))
|
|
@@ -119,13 +120,14 @@ def load_pipeline(pipeline=None) -> StableDiffusionXLPipeline:
|
|
| 119 |
print("creating latent")
|
| 120 |
latents = torch.randn(1, 4, 128, 128, device='cuda', requires_grad=False)
|
| 121 |
print("decoding ")
|
|
|
|
| 122 |
latents = latents.to(dtype=torch.half)
|
| 123 |
res_sd = pipeline.vae.decode(latents)[0]
|
| 124 |
print("compressing ")
|
| 125 |
-
latents =
|
| 126 |
# res_taesd = instance(latents.mul(scaling_factor)).mul(mul).sub(sub)
|
| 127 |
with autocast(dtype=torch.half):
|
| 128 |
-
res_taesd = instance(
|
| 129 |
loss = loss_fn(res_taesd, res_sd)
|
| 130 |
|
| 131 |
scaler.scale(loss).backward()
|
|
|
|
| 9 |
import time
|
| 10 |
from onediffx import compile_pipe, save_pipe, load_pipe
|
| 11 |
from torch.cuda.amp import autocast, GradScaler
|
| 12 |
+
import copy
|
| 13 |
instance = None
|
| 14 |
loss_fn = None
|
| 15 |
optimizer = None
|
|
|
|
| 84 |
optimizer = torch.optim.Adam([param for layer in trainable_layers for param in layer.parameters()], lr=0.001)
|
| 85 |
print(len([param for layer in trainable_layers for param in layer.parameters()]))
|
| 86 |
instance.train()
|
| 87 |
+
pipeline.vae.eval()
|
| 88 |
|
| 89 |
device = 'cuda'
|
| 90 |
mul = torch.nn.Parameter(torch.tensor(1.2, requires_grad=True, device=device))
|
|
|
|
| 120 |
print("creating latent")
|
| 121 |
latents = torch.randn(1, 4, 128, 128, device='cuda', requires_grad=False)
|
| 122 |
print("decoding ")
|
| 123 |
+
latents_orig = copy.deepcopy(latents)
|
| 124 |
latents = latents.to(dtype=torch.half)
|
| 125 |
res_sd = pipeline.vae.decode(latents)[0]
|
| 126 |
print("compressing ")
|
| 127 |
+
# latents = latents_orig.float()
|
| 128 |
# res_taesd = instance(latents.mul(scaling_factor)).mul(mul).sub(sub)
|
| 129 |
with autocast(dtype=torch.half):
|
| 130 |
+
res_taesd = instance(latents_orig.mul(scaling_factor)).mul(mul).sub(sub)
|
| 131 |
loss = loss_fn(res_taesd, res_sd)
|
| 132 |
|
| 133 |
scaler.scale(loss).backward()
|