lllyasviel commited on
Commit
b881d9e
·
1 Parent(s): 58261f5
Files changed (1) hide show
  1. modules/core.py +33 -4
modules/core.py CHANGED
@@ -6,11 +6,12 @@ import torch
6
  import numpy as np
7
 
8
  import comfy.model_management
9
- import comfy.sample
10
  import comfy.utils
11
 
12
  from comfy.sd import load_checkpoint_guess_config
13
  from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
 
 
14
 
15
 
16
  opCLIPTextEncode = CLIPTextEncode()
@@ -105,9 +106,37 @@ def ksampler(model, positive, negative, latent, seed=None, steps=30, cfg=9.0, sa
105
  previewer.preview(x0, step, total_steps)
106
  pbar.update_absolute(step + 1, total_steps, None)
107
 
108
- samples = comfy.sample.sample(model, noise, steps, cfg, sampler_name, scheduler, positive, negative, latent_image,
109
- denoise=denoise, disable_noise=disable_noise, start_step=start_step, last_step=last_step,
110
- force_full_denoise=force_full_denoise, noise_mask=noise_mask, callback=callback, seed=seed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  out = latent.copy()
112
  out["samples"] = samples
113
 
 
6
  import numpy as np
7
 
8
  import comfy.model_management
 
9
  import comfy.utils
10
 
11
  from comfy.sd import load_checkpoint_guess_config
12
  from nodes import VAEDecode, EmptyLatentImage, CLIPTextEncode
13
+ from comfy.sample import prepare_mask, broadcast_cond, load_additional_models, cleanup_additional_models
14
+ from comfy.samplers import KSampler
15
 
16
 
17
  opCLIPTextEncode = CLIPTextEncode()
 
106
  previewer.preview(x0, step, total_steps)
107
  pbar.update_absolute(step + 1, total_steps, None)
108
 
109
+ sigmas = None
110
+ disable_pbar = False
111
+
112
+ device = comfy.model_management.get_torch_device()
113
+
114
+ if noise_mask is not None:
115
+ noise_mask = prepare_mask(noise_mask, noise.shape, device)
116
+
117
+ comfy.model_management.load_model_gpu(model)
118
+ real_model = model.model
119
+
120
+ noise = noise.to(device)
121
+ latent_image = latent_image.to(device)
122
+
123
+ positive_copy = broadcast_cond(positive, noise.shape[0], device)
124
+ negative_copy = broadcast_cond(negative, noise.shape[0], device)
125
+
126
+ models = load_additional_models(positive, negative, model.model_dtype())
127
+
128
+ sampler = KSampler(real_model, steps=steps, device=device, sampler=sampler_name, scheduler=scheduler,
129
+ denoise=denoise, model_options=model.model_options)
130
+
131
+ samples = sampler.sample(noise, positive_copy, negative_copy, cfg=cfg, latent_image=latent_image,
132
+ start_step=start_step, last_step=last_step, force_full_denoise=force_full_denoise,
133
+ denoise_mask=noise_mask, sigmas=sigmas, callback=callback, disable_pbar=disable_pbar,
134
+ seed=seed)
135
+
136
+ samples = samples.cpu()
137
+
138
+ cleanup_additional_models(models)
139
+
140
  out = latent.copy()
141
  out["samples"] = samples
142