better diffuser patcher

This commit is contained in:
lllyasviel
2024-02-02 00:32:15 -08:00
parent cb1aa493e2
commit b944aa9242
2 changed files with 8 additions and 4 deletions

View File

@@ -55,7 +55,11 @@ class PreprocessorMarigold(Preprocessor):
self.load_model()
model_management.load_models_gpu([self.diffusers_patcher.patcher])
H, W, C = input_image.shape
self.diffusers_patcher.prepare_memory_before_sampling(
batchsize=1, latent_width=W // 8, latent_height=H // 8
)
with torch.no_grad():
img = numpy_to_pytorch(input_image).movedim(-1, 1).to(
@@ -63,8 +67,8 @@ class PreprocessorMarigold(Preprocessor):
dtype=self.diffusers_patcher.dtype)
img = img * 2.0 - 1.0
depth = self.diffusers_patcher.patcher.model(img, num_inference_steps=20, show_pbar=False)
depth = depth * 0.5 + 0.5
depth = self.diffusers_patcher.pipeline(img, num_inference_steps=20, show_pbar=False)
depth = 0.5 - depth * 0.5
depth = depth.movedim(1, -1)[0].cpu().numpy()
depth_image = HWC3((depth * 255.0).clip(0, 255).astype(np.uint8))

View File

@@ -43,6 +43,6 @@ class DiffusersModelPatcher:
area = 2 * batchsize * latent_width * latent_height
inference_memory = (((area * 0.6) / 0.9) + 1024) * (1024 * 1024)
model_management.load_models_gpu(
models=[self.pipeline],
models=[self.patcher],
memory_required=inference_memory
)