okami.mom/strata
git clone https://git.nkp.pet/okami.mom/strata
150c2394f
main
1// strata_philox_rng.hpp - the RNG sd-cli uses with --model-args strata_noise=1: stable-diffusion.cpp's PhiloxRNG 2// (--rng cuda) stream as its Linux x86 build makes it, computed by strata_noise.hpp on every operating system and CPU. 3// Same interface and the same counter handling as PhiloxRNG in src/core/rng_philox.hpp: the k-th randn() call after 4// manual_seed uses Philox offset k. tools/image/sdcpp_noise/apply.py puts this file and strata_noise.hpp into 5// src/core/ of a stable-diffusion.cpp checkout and hooks it into StableDiffusionGGML::init. 6#pragma once 7 8#include <memory> 9#include <string> 10#include <vector> 11 12#include "core/rng.hpp" 13#include "core/strata_noise.hpp" 14#include "core/util.h" 15 16namespace strata_noise { 17// true when the model args ("a=1,b=2" or "a=1;b=2", sd.cpp's key=value list) hold strata_noise=1 18static inline bool requested (const char * model_args ) { 19for (const auto & [key ,value ] :parse_key_value_args (model_args ,"model arg" )) { 20if (key == "strata_noise" && value == "1" ) { 21return true; 22 } 23 } 24return false; 25} 26}// namespace strata_noise 27 28class StrataPhiloxRNG :public RNG { 29private : 30uint64_t seed = 0 ; 31uint32_t offset = 0 ; 32 33public : 34StrataPhiloxRNG (uint64_t seed = 0 ) :seed (seed ) {} 35 36 std::shared_ptr < RNG > clone ()const override { 37return std::make_shared < StrataPhiloxRNG > (* this ); 38 } 39 40void manual_seed (uint64_t s )override { 41seed = s ; 42offset = 0 ; 43 } 44 45 std::vector < float > randn (uint32_t n )override { 46 std::vector < float > r = strata_noise::randn (seed ,n ,offset ); 47offset += 1 ; 48return r ; 49 } 50};