Merge branch 'development' of github.com:pbaylies/stable-diffusion into pbaylies-development

This commit is contained in:
Lincoln Stein
2022-10-04 22:31:11 -04:00
10 changed files with 16 additions and 38 deletions

View File

@ -189,7 +189,6 @@ class Args(object):
switches.append(f'--perlin {a["perlin"]}')
if a['threshold'] > 0:
switches.append(f'--threshold {a["threshold"]}')
if a['grid']:
switches.append('--grid')
if a['seamless']:

View File

@ -32,7 +32,7 @@ class Txt2Img(Generator):
if self.free_gpu_mem and self.model.model.device != self.model.device:
self.model.model.to(self.model.device)
sampler.make_schedule(ddim_num_steps=steps, ddim_eta=ddim_eta, verbose=True)
sampler.make_schedule(ddim_num_steps=steps, ddim_eta=ddim_eta, verbose=False)
samples, _ = sampler.sample(
batch_size = 1,

View File

@ -79,17 +79,9 @@ class KSampler(Sampler):
ddim_eta=0.0,
verbose=False,
)
self.model = outer_model
self.model = outer_model
self.ddim_num_steps = ddim_num_steps
sigmas = K.sampling.get_sigmas_karras(
n=ddim_num_steps,
sigma_min=self.model.sigmas[0].item(),
sigma_max=self.model.sigmas[-1].item(),
rho=7.,
device=self.device,
# Birch-san recommends this, but it doesn't match the call signature in his branch of k-diffusion
# concat_zero=False
)
sigmas = self.model.get_sigmas(ddim_num_steps)
self.sigmas = sigmas
# ALERT: We are completely overriding the sample() method in the base class, which
@ -133,7 +125,8 @@ class KSampler(Sampler):
# sigmas = self.model.get_sigmas(S)
# sigmas are now set up in make_schedule - we take the last steps items
sigmas = self.sigmas[-S:]
sigmas = self.sigmas[-S-1:]
if x_T is not None:
x = x_T * sigmas[0]
else:
@ -147,7 +140,7 @@ class KSampler(Sampler):
'uncond': unconditional_conditioning,
'cond_scale': unconditional_guidance_scale,
}
print(f'>> Sampling with k__{self.schedule}')
print(f'>> Sampling with k_{self.schedule}')
return (
K.sampling.__dict__[f'sample_{self.schedule}'](
model_wrap_cfg, x, sigmas, extra_args=extra_args,

View File

@ -218,7 +218,7 @@ def rand_perlin_2d(shape, res, fade = lambda t: 6*t**5 - 15*t**4 + 10*t**3):
delta = (res[0] / shape[0], res[1] / shape[1])
d = (shape[0] // res[0], shape[1] // res[1])
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1])), dim = -1) % 1
grid = torch.stack(torch.meshgrid(torch.arange(0, res[0], delta[0]), torch.arange(0, res[1], delta[1]), indexing='ij'), dim = -1) % 1
angles = 2*math.pi*torch.rand(res[0]+1, res[1]+1)
gradients = torch.stack((torch.cos(angles), torch.sin(angles)), dim = -1)
@ -230,4 +230,4 @@ def rand_perlin_2d(shape, res, fade = lambda t: 6*t**5 - 15*t**4 + 10*t**3):
n01 = dot(tile_grads([0, -1],[1, None]), [0, -1])
n11 = dot(tile_grads([1, None], [1, None]), [-1,-1])
t = fade(grid[:shape[0], :shape[1]])
return math.sqrt(2) * torch.lerp(torch.lerp(n00, n10, t[..., 0]), torch.lerp(n01, n11, t[..., 0]), t[..., 1])
return math.sqrt(2) * torch.lerp(torch.lerp(n00, n10, t[..., 0]), torch.lerp(n01, n11, t[..., 0]), t[..., 1])