Skip to content

Commit c8b392b

Browse files
authored
Merge pull request #2111 from bghira/bugfix/kandinsky-i2i-validation
(#2106) kandinsky i2i scale factor should be the size scale factor, not shift + scale
2 parents eed8c57 + 23a7748 commit c8b392b

1 file changed

Lines changed: 37 additions & 3 deletions

File tree

simpletuner/helpers/models/kandinsky5_image/pipeline_kandinsky5_t2i.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,35 @@ def __init__(
9898
@property
9999
def vae_scale_factor_spatial(self):
100100
vae = getattr(self, "vae", None)
101-
if vae is None or getattr(vae, "config", None) is None:
102-
return 1.0
103-
return getattr(vae.config, "scaling_factor", 1.0)
101+
config = getattr(vae, "config", None) if vae is not None else None
102+
if config is None:
103+
return 8
104+
105+
def _sanitize_scale(value):
106+
if value is None:
107+
return None
108+
if torch.is_tensor(value):
109+
if value.numel() != 1:
110+
return None
111+
value = value.item()
112+
if isinstance(value, int):
113+
return value
114+
if isinstance(value, float) and value.is_integer():
115+
return int(value)
116+
return None
117+
118+
for attr in ("scale_factor_spatial", "spatial_compression_ratio"):
119+
scale = _sanitize_scale(getattr(config, attr, None))
120+
if scale is not None and scale > 0:
121+
return scale
122+
123+
block_out_channels = getattr(config, "block_out_channels", None)
124+
if block_out_channels:
125+
# Downsampling happens on every block except the last one.
126+
downsample_blocks = max(len(block_out_channels) - 1, 0)
127+
return max(1, 2**downsample_blocks)
128+
129+
return 1
104130

105131
@property
106132
def guidance_scale(self):
@@ -110,6 +136,14 @@ def guidance_scale(self):
110136
def do_classifier_free_guidance(self):
111137
return self.guidance_scale > 1.0
112138

139+
@property
140+
def interrupt(self):
141+
return getattr(self, "_interrupt", False)
142+
143+
@interrupt.setter
144+
def interrupt(self, value: bool):
145+
self._interrupt = bool(value)
146+
113147
def encode_prompt(
114148
self,
115149
prompt: Union[str, List[str]],

0 commit comments

Comments
 (0)