mirror of
https://github.com/comfyanonymous/ComfyUI.git
synced 2025-07-10 01:17:38 +08:00
Don't add tiny bit of random noise when VAE encoding. (#8705)
Shouldn't change outputs but might make things a tiny bit more deterministic.
This commit is contained in:
parent
bd951a714f
commit
9093301a49
@ -11,7 +11,7 @@ from comfy.ldm.modules.ema import LitEma
|
|||||||
import comfy.ops
|
import comfy.ops
|
||||||
|
|
||||||
class DiagonalGaussianRegularizer(torch.nn.Module):
|
class DiagonalGaussianRegularizer(torch.nn.Module):
|
||||||
def __init__(self, sample: bool = True):
|
def __init__(self, sample: bool = False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.sample = sample
|
self.sample = sample
|
||||||
|
|
||||||
@ -19,16 +19,12 @@ class DiagonalGaussianRegularizer(torch.nn.Module):
|
|||||||
yield from ()
|
yield from ()
|
||||||
|
|
||||||
def forward(self, z: torch.Tensor) -> Tuple[torch.Tensor, dict]:
|
def forward(self, z: torch.Tensor) -> Tuple[torch.Tensor, dict]:
|
||||||
log = dict()
|
|
||||||
posterior = DiagonalGaussianDistribution(z)
|
posterior = DiagonalGaussianDistribution(z)
|
||||||
if self.sample:
|
if self.sample:
|
||||||
z = posterior.sample()
|
z = posterior.sample()
|
||||||
else:
|
else:
|
||||||
z = posterior.mode()
|
z = posterior.mode()
|
||||||
kl_loss = posterior.kl()
|
return z, None
|
||||||
kl_loss = torch.sum(kl_loss) / kl_loss.shape[0]
|
|
||||||
log["kl_loss"] = kl_loss
|
|
||||||
return z, log
|
|
||||||
|
|
||||||
|
|
||||||
class AbstractAutoencoder(torch.nn.Module):
|
class AbstractAutoencoder(torch.nn.Module):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user