diff options
Diffstat (limited to 'modules')
-rw-r--r-- | modules/images.py | 16 | ||||
-rw-r--r-- | modules/interrogate.py | 2 | ||||
-rw-r--r-- | modules/sd_hijack.py | 2 | ||||
-rw-r--r-- | modules/sd_samplers.py | 2 | ||||
-rw-r--r-- | modules/shared.py | 1 |
5 files changed, 14 insertions, 9 deletions
diff --git a/modules/images.py b/modules/images.py index 1c01d6d8..97cccf54 100644 --- a/modules/images.py +++ b/modules/images.py @@ -345,16 +345,20 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i if not os.path.exists(fullfn):
break
- if extension.lower() in ("jpg", "jpeg", "webp"):
- exif_bytes = piexif.dump({
+ def exif_bytes():
+ return piexif.dump({
"Exif": {
- piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info, encoding="unicode")
+ piexif.ExifIFD.UserComment: piexif.helper.UserComment.dump(info or "", encoding="unicode")
},
})
+
+ if extension.lower() in ("jpg", "jpeg", "webp"):
+ image.save(fullfn, quality=opts.jpeg_quality, exif_bytes=exif_bytes())
else:
- exif_bytes = None
+ image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo)
- image.save(fullfn, quality=opts.jpeg_quality, pnginfo=pnginfo, exif=exif_bytes)
+ if extension.lower() == "webp":
+ piexif.insert(exif_bytes, fullfn)
target_side_length = 4000
oversize = image.width > target_side_length or image.height > target_side_length
@@ -366,7 +370,7 @@ def save_image(image, path, basename, seed=None, prompt=None, extension='png', i elif oversize:
image = image.resize((image.width * target_side_length // image.height, target_side_length), LANCZOS)
- image.save(fullfn, quality=opts.jpeg_quality, exif=exif_bytes)
+ image.save(fullfn_without_extension + ".jpg", quality=opts.jpeg_quality, exif_bytes=exif_bytes())
if opts.save_txt and info is not None:
with open(f"{fullfn_without_extension}.txt", "w", encoding="utf8") as file:
diff --git a/modules/interrogate.py b/modules/interrogate.py index 06862fcc..f62a4745 100644 --- a/modules/interrogate.py +++ b/modules/interrogate.py @@ -98,7 +98,7 @@ class InterrogateModels: text_array = text_array[0:int(shared.opts.interrogate_clip_dict_limit)]
top_count = min(top_count, len(text_array))
- text_tokens = clip.tokenize([text for text in text_array]).to(shared.device)
+ text_tokens = clip.tokenize([text for text in text_array], truncate=True).to(shared.device)
text_features = self.clip_model.encode_text(text_tokens).type(self.dtype)
text_features /= text_features.norm(dim=-1, keepdim=True)
diff --git a/modules/sd_hijack.py b/modules/sd_hijack.py index ec7d14cb..65414518 100644 --- a/modules/sd_hijack.py +++ b/modules/sd_hijack.py @@ -57,7 +57,7 @@ def split_cross_attention_forward(self, x, context=None, mask=None): q, k, v = map(lambda t: rearrange(t, 'b n (h d) -> (b h) n d', h=h), (q_in, k_in, v_in))
del q_in, k_in, v_in
- r1 = torch.zeros(q.shape[0], q.shape[1], v.shape[2], device=q.device)
+ r1 = torch.zeros(q.shape[0], q.shape[1], v.shape[2], device=q.device, dtype=q.dtype)
stats = torch.cuda.memory_stats(q.device)
mem_active = stats['active_bytes.all.current']
diff --git a/modules/sd_samplers.py b/modules/sd_samplers.py index c042c5c3..df3a6fe8 100644 --- a/modules/sd_samplers.py +++ b/modules/sd_samplers.py @@ -185,7 +185,7 @@ def extended_trange(count, *args, **kwargs): class KDiffusionSampler:
def __init__(self, funcname, sd_model):
- self.model_wrap = k_diffusion.external.CompVisDenoiser(sd_model)
+ self.model_wrap = k_diffusion.external.CompVisDenoiser(sd_model, quantize=shared.opts.enable_quantization)
self.funcname = funcname
self.func = getattr(k_diffusion.sampling, self.funcname)
self.model_wrap_cfg = CFGDenoiser(self.model_wrap)
diff --git a/modules/shared.py b/modules/shared.py index 939d7fe1..78450546 100644 --- a/modules/shared.py +++ b/modules/shared.py @@ -125,6 +125,7 @@ class Options: "enable_pnginfo": OptionInfo(True, "Save text information about generation parameters as chunks to png files"),
"add_model_hash_to_info": OptionInfo(False, "Add model hash to generation information"),
"img2img_color_correction": OptionInfo(False, "Apply color correction to img2img results to match original colors."),
+ "enable_quantization": OptionInfo(False, "Enable quantization in K samplers for sharper and cleaner results. This may change existing seeds. Requires restart to apply."),
"font": OptionInfo("", "Font for image grids that have text"),
"enable_emphasis": OptionInfo(True, "Use (text) to make model pay more attention to text and [text] to make it pay less attention"),
"save_txt": OptionInfo(False, "Create a text file next to every image with generation parameters."),
|