main
File_xor 2023-06-24 01:00:30 +09:00
parent 2e8bb4a8f1
commit a6bcef01eb
1 changed files with 21 additions and 39 deletions

View File

@ -394,26 +394,6 @@ class Clip_IO(scripts.Script):
return prompt_parser.MulticondLearnedConditioning(shape=(len(prompts),), batch=res)
pass
def my_get_conds_with_caching(self, function, required_prompts, steps, cache):
"""
Returns the result of calling function(shared.sd_model, required_prompts, steps)
using a cache to store the result if the same arguments have been used before.
cache is an array containing two elements. The first element is a tuple
representing the previously used arguments, or None if no arguments
have been used before. The second element is where the previously
computed result is stored.
"""
if cache[0] is not None and (required_prompts, steps, opts.CLIP_stop_at_last_layers, shared.sd_model.sd_checkpoint_info) == cache[0]:
return cache[1]
with devices.autocast():
cache[1] = function(shared.sd_model, required_prompts, steps, self)
cache[0] = (required_prompts, steps, opts.CLIP_stop_at_last_layers, shared.sd_model.sd_checkpoint_info)
return cache[1]
pass
def load_csv_conditioning(filename: str | os.PathLike) -> torch.Tensor | None:
filename = os.path.realpath(filename)
with open(filename, newline='') as csv_file:
@ -490,28 +470,30 @@ class Clip_IO(scripts.Script):
pass
pass
def get_my_get_conds_with_caching():
def get_conds_with_caching(function, required_prompts, steps, cache):
"""
Returns the result of calling function(shared.sd_model, required_prompts, steps)
using a cache to store the result if the same arguments have been used before.
def get_my_get_conds_with_caching(p: processing.StableDiffusionProcessing):
class StableDiffusionProcessing:
@classmethod
def my_get_conds_with_caching(p, function, required_prompts, steps, cache):
"""
Returns the result of calling function(shared.sd_model, required_prompts, steps)
using a cache to store the result if the same arguments have been used before.
cache is an array containing two elements. The first element is a tuple
representing the previously used arguments, or None if no arguments
have been used before. The second element is where the previously
computed result is stored.
"""
cache is an array containing two elements. The first element is a tuple
representing the previously used arguments, or None if no arguments
have been used before. The second element is where the previously
computed result is stored.
"""
if cache[0] is not None and (required_prompts, steps, opts.CLIP_stop_at_last_layers, shared.sd_model.sd_checkpoint_info) == cache[0]:
return cache[1]
if cache[0] is not None and (required_prompts, steps) == cache[0]:
with devices.autocast():
cache[1] = function(shared.sd_model, required_prompts, steps, p)
cache[0] = (required_prompts, steps, opts.CLIP_stop_at_last_layers, shared.sd_model.sd_checkpoint_info)
return cache[1]
with devices.autocast():
cache[1] = function(shared.sd_model, required_prompts, steps)
cache[0] = (required_prompts, steps)
return cache[1]
pass
pass
return get_conds_with_caching
return StableDiffusionProcessing.my_get_conds_with_caching
pass
def get_inner_function(outer, new_inner):
@ -630,7 +612,7 @@ class Clip_IO(scripts.Script):
Clip_IO.mode_positive = args[1]
Clip_IO.mode_negative = args[2]
Clip_IO.evacuate_get_conds_with_caching = p.get_conds_with_caching
p.get_conds_with_caching = Clip_IO.my_get_conds_with_caching
p.get_conds_with_caching = Clip_IO.get_my_get_conds_with_caching(p)
pass
def postprocess_batch(self, p: processing.StableDiffusionProcessing, *args, **kwargs):