stable-diffusion.cpp icon indicating copy to clipboard operation
stable-diffusion.cpp copied to clipboard

Fixed random generator

Open wonkyoc opened this issue 1 year ago • 2 comments

The current random generator is fixed by the designated seed number (default: 42). Although this is fine with generating a latent image, it is quite not right for ancestral sampling. The ancestral sampling adds a random noise at every step, but due to the fixed seed, every execution generates the same image, which should not happen.

wonkyoc avatar May 16 '24 02:05 wonkyoc

and all reproducibility will gone... 👎

SA-j00u avatar May 16 '24 09:05 SA-j00u

Looking at rng.hpp and the de-noising code I believe this is already implemented correctly. Euler_a and dpm++2s_a get their random noise using the ggml_tensor_set_f32_randn function which sources it's rng from the RNG randn class method which in turn uses the base seed. Therefore, each de-noising step is "random" relative to each other de-noising step, but deterministic to the overall seed which I believe is the desired behavior.

grauho avatar May 16 '24 11:05 grauho