-
Notifications
You must be signed in to change notification settings - Fork 330
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a78ebd
commit 9c1a127
Showing
2 changed files
with
24 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from keras import ops | ||
|
||
|
||
class CFGDenoiser: | ||
def __call__(self, batched, cond_scale): | ||
# `batched` is the outputs from `BaseModel.apply_model` | ||
pos_out, neg_out = ops.split(batched, 2, axis=0) | ||
scaled = neg_out + (pos_out - neg_out) * cond_scale | ||
return scaled |
15 changes: 15 additions & 0 deletions
15
keras_cv/src/models/stable_diffusion_v3/sd3_latent_format.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
class SD3LatentFormat: | ||
"""Latents are slightly shifted from center. | ||
This class must be called after VAE Decode to correct for the shift. | ||
""" | ||
|
||
def __init__(self): | ||
self.scale_factor = 1.5305 | ||
self.shift_factor = 0.0609 | ||
|
||
def process_in(self, latent): | ||
return (latent - self.shift_factor) * self.scale_factor | ||
|
||
def process_out(self, latent): | ||
return (latent / self.scale_factor) + self.shift_factor |