divamgupta / stable-diffusion-tensorflow

Stable Diffusion in TensorFlow / Keras
Other
1.57k stars 227 forks source link

fix random seeding of latent #27

Closed matpalm closed 1 year ago

matpalm commented 1 year ago

for whatever reason tf.random.normal doesn't honour the passed seed...

e.g. consider the following...

>>> import numpy as np
>>> import tensorflow as tf
>>> np.sum(tf.random.normal((1,2,3,4), seed=123))
2.359888
>>> np.sum(tf.random.normal((1,2,3,4), seed=123))
-0.19422567

this means the current latents generated aren't seeded. switching to numpy, which is fine here since the initial latents aren't in the TF graph at all, fixes things.

matpalm commented 1 year ago

apprently this is the expected behaviour of tf.random.normal !!!

https://twitter.com/fchollet/status/1572725572937322497

divamgupta commented 1 year ago

Thanks for the PR. Could you replace the other tf.random.normal call as well?

matpalm commented 1 year ago

the noise one? that's actually not being used ( see https://github.com/divamgupta/stable-diffusion-tensorflow/issues/21 ) i'd recommend removing it completely...

matpalm commented 1 year ago

oh. oops. pushed that matmul change to the wrong branch. muddies this PR but it's a thing to do anyways to be honest

matpalm commented 1 year ago

superseded by https://github.com/divamgupta/stable-diffusion-tensorflow/pull/32