Skip to content

Commit

Permalink
infotext support for #14978
Browse files Browse the repository at this point in the history
  • Loading branch information
AUTOMATIC1111 committed Mar 2, 2024
1 parent aabedcb commit bb24c13
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
3 changes: 3 additions & 0 deletions modules/infotext_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,9 @@ def parse_generation_parameters(x: str, skip_fields: list[str] | None = None):
if "Emphasis" not in res:
res["Emphasis"] = "Original"

if "Refiner switch by sampling steps" not in res:
res["Refiner switch by sampling steps"] = False

infotext_versions.backcompat(res)

for key in skip_fields:
Expand Down
3 changes: 3 additions & 0 deletions modules/infotext_versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

v160 = version.parse("1.6.0")
v170_tsnr = version.parse("v1.7.0-225")
v180 = version.parse("1.8.0")


def parse_version(text):
Expand Down Expand Up @@ -40,3 +41,5 @@ def backcompat(d):
if ver < v170_tsnr:
d["Downcast alphas_cumprod"] = True

if ver < v180 and d.get('Refiner'):
d["Refiner switch by sampling steps"] = True
8 changes: 5 additions & 3 deletions modules/sd_samplers_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,16 @@ def torchsde_randn(size, dtype, device, seed):
replace_torchsde_browinan()


def apply_refiner(cfg_denoiser, sigma):
if opts.refiner_switch_by_sample_steps:
def apply_refiner(cfg_denoiser, sigma=None):
if opts.refiner_switch_by_sample_steps or not sigma:
completed_ratio = cfg_denoiser.step / cfg_denoiser.total_steps
cfg_denoiser.p.extra_generation_params["Refiner switch by sampling steps"] = True

else:
# torch.max(sigma) only to handle rare case where we might have different sigmas in the same batch
try:
timestep = torch.argmin(torch.abs(cfg_denoiser.inner_model.sigmas - torch.max(sigma)))
except AttributeError: # for samplers that dont use sigmas (DDIM) sigma is actually the timestep
except AttributeError: # for samplers that don't use sigmas (DDIM) sigma is actually the timestep
timestep = torch.max(sigma).to(dtype=int)
completed_ratio = (999 - timestep) / 1000

Expand Down

0 comments on commit bb24c13

Please sign in to comment.