chore: clear the msvc compilation warning
This commit is contained in:
parent
3001c23f7d
commit
3bf1665885
4
rng.h
4
rng.h
@ -16,7 +16,7 @@ class STDDefaultRNG : public RNG {
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
void manual_seed(uint64_t seed) {
|
void manual_seed(uint64_t seed) {
|
||||||
generator.seed(seed);
|
generator.seed((unsigned int)seed);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<float> randn(uint32_t n) {
|
std::vector<float> randn(uint32_t n) {
|
||||||
@ -24,7 +24,7 @@ class STDDefaultRNG : public RNG {
|
|||||||
float mean = 0.0;
|
float mean = 0.0;
|
||||||
float stddev = 1.0;
|
float stddev = 1.0;
|
||||||
std::normal_distribution<float> distribution(mean, stddev);
|
std::normal_distribution<float> distribution(mean, stddev);
|
||||||
for (int i = 0; i < n; i++) {
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
float random_number = distribution(generator);
|
float random_number = distribution(generator);
|
||||||
result.push_back(random_number);
|
result.push_back(random_number);
|
||||||
}
|
}
|
||||||
|
18
rng_philox.h
18
rng_philox.h
@ -16,8 +16,8 @@ class PhiloxRNG : public RNG {
|
|||||||
private:
|
private:
|
||||||
std::vector<uint32_t> philox_m = {0xD2511F53, 0xCD9E8D57};
|
std::vector<uint32_t> philox_m = {0xD2511F53, 0xCD9E8D57};
|
||||||
std::vector<uint32_t> philox_w = {0x9E3779B9, 0xBB67AE85};
|
std::vector<uint32_t> philox_w = {0x9E3779B9, 0xBB67AE85};
|
||||||
float two_pow32_inv = 2.3283064e-10;
|
float two_pow32_inv = 2.3283064e-10f;
|
||||||
float two_pow32_inv_2pi = 2.3283064e-10 * 6.2831855;
|
float two_pow32_inv_2pi = 2.3283064e-10f * 6.2831855f;
|
||||||
|
|
||||||
std::vector<uint32_t> uint32(uint64_t x) {
|
std::vector<uint32_t> uint32(uint64_t x) {
|
||||||
std::vector<uint32_t> result(2);
|
std::vector<uint32_t> result(2);
|
||||||
@ -27,10 +27,10 @@ class PhiloxRNG : public RNG {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::vector<uint32_t>> uint32(const std::vector<uint64_t>& x) {
|
std::vector<std::vector<uint32_t>> uint32(const std::vector<uint64_t>& x) {
|
||||||
int N = x.size();
|
uint32_t N = (uint32_t)x.size();
|
||||||
std::vector<std::vector<uint32_t>> result(2, std::vector<uint32_t>(N));
|
std::vector<std::vector<uint32_t>> result(2, std::vector<uint32_t>(N));
|
||||||
|
|
||||||
for (int i = 0; i < N; ++i) {
|
for (uint32_t i = 0; i < N; ++i) {
|
||||||
result[0][i] = static_cast<uint32_t>(x[i] & 0xFFFFFFFF);
|
result[0][i] = static_cast<uint32_t>(x[i] & 0xFFFFFFFF);
|
||||||
result[1][i] = static_cast<uint32_t>(x[i] >> 32);
|
result[1][i] = static_cast<uint32_t>(x[i] >> 32);
|
||||||
}
|
}
|
||||||
@ -41,7 +41,7 @@ class PhiloxRNG : public RNG {
|
|||||||
// A single round of the Philox 4x32 random number generator.
|
// A single round of the Philox 4x32 random number generator.
|
||||||
void philox4_round(std::vector<std::vector<uint32_t>>& counter,
|
void philox4_round(std::vector<std::vector<uint32_t>>& counter,
|
||||||
const std::vector<std::vector<uint32_t>>& key) {
|
const std::vector<std::vector<uint32_t>>& key) {
|
||||||
uint32_t N = counter[0].size();
|
uint32_t N = (uint32_t)counter[0].size();
|
||||||
for (uint32_t i = 0; i < N; i++) {
|
for (uint32_t i = 0; i < N; i++) {
|
||||||
std::vector<uint32_t> v1 = uint32(static_cast<uint64_t>(counter[0][i]) * static_cast<uint64_t>(philox_m[0]));
|
std::vector<uint32_t> v1 = uint32(static_cast<uint64_t>(counter[0][i]) * static_cast<uint64_t>(philox_m[0]));
|
||||||
std::vector<uint32_t> v2 = uint32(static_cast<uint64_t>(counter[2][i]) * static_cast<uint64_t>(philox_m[1]));
|
std::vector<uint32_t> v2 = uint32(static_cast<uint64_t>(counter[2][i]) * static_cast<uint64_t>(philox_m[1]));
|
||||||
@ -63,7 +63,7 @@ class PhiloxRNG : public RNG {
|
|||||||
std::vector<std::vector<uint32_t>> philox4_32(std::vector<std::vector<uint32_t>>& counter,
|
std::vector<std::vector<uint32_t>> philox4_32(std::vector<std::vector<uint32_t>>& counter,
|
||||||
std::vector<std::vector<uint32_t>>& key,
|
std::vector<std::vector<uint32_t>>& key,
|
||||||
int rounds = 10) {
|
int rounds = 10) {
|
||||||
uint32_t N = counter[0].size();
|
uint32_t N = (uint32_t)counter[0].size();
|
||||||
for (int i = 0; i < rounds - 1; ++i) {
|
for (int i = 0; i < rounds - 1; ++i) {
|
||||||
philox4_round(counter, key);
|
philox4_round(counter, key);
|
||||||
|
|
||||||
@ -81,7 +81,7 @@ class PhiloxRNG : public RNG {
|
|||||||
float u = x * two_pow32_inv + two_pow32_inv / 2;
|
float u = x * two_pow32_inv + two_pow32_inv / 2;
|
||||||
float v = y * two_pow32_inv_2pi + two_pow32_inv_2pi / 2;
|
float v = y * two_pow32_inv_2pi + two_pow32_inv_2pi / 2;
|
||||||
|
|
||||||
float s = sqrt(-2.0 * log(u));
|
float s = sqrt(-2.0f * log(u));
|
||||||
|
|
||||||
float r1 = s * sin(v);
|
float r1 = s * sin(v);
|
||||||
return r1;
|
return r1;
|
||||||
@ -115,8 +115,8 @@ class PhiloxRNG : public RNG {
|
|||||||
std::vector<std::vector<uint32_t>> g = philox4_32(counter, key_uint32);
|
std::vector<std::vector<uint32_t>> g = philox4_32(counter, key_uint32);
|
||||||
|
|
||||||
std::vector<float> result;
|
std::vector<float> result;
|
||||||
for (int i = 0; i < n; ++i) {
|
for (uint32_t i = 0; i < n; ++i) {
|
||||||
result.push_back(box_muller(g[0][i], g[1][i]));
|
result.push_back(box_muller((float)g[0][i], (float)g[1][i]));
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
#include "rng_philox.h"
|
#include "rng_philox.h"
|
||||||
#include "stable-diffusion.h"
|
#include "stable-diffusion.h"
|
||||||
|
|
||||||
#define EPS 1e-05
|
#define EPS 1e-05f
|
||||||
|
|
||||||
static SDLogLevel log_level = SDLogLevel::INFO;
|
static SDLogLevel log_level = SDLogLevel::INFO;
|
||||||
|
|
||||||
@ -122,9 +122,9 @@ ggml_tensor* load_tensor_from_file(ggml_context* ctx, const std::string& file_pa
|
|||||||
}
|
}
|
||||||
|
|
||||||
void ggml_tensor_set_f32_randn(struct ggml_tensor* tensor, std::shared_ptr<RNG> rng) {
|
void ggml_tensor_set_f32_randn(struct ggml_tensor* tensor, std::shared_ptr<RNG> rng) {
|
||||||
uint32_t n = ggml_nelements(tensor);
|
uint32_t n = (uint32_t)ggml_nelements(tensor);
|
||||||
std::vector<float> random_numbers = rng->randn(n);
|
std::vector<float> random_numbers = rng->randn(n);
|
||||||
for (int i = 0; i < n; i++) {
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
ggml_set_f32_1d(tensor, i, random_numbers[i]);
|
ggml_set_f32_1d(tensor, i, random_numbers[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -438,12 +438,12 @@ std::vector<std::pair<std::string, float>> parse_prompt_attention(const std::str
|
|||||||
std::string weight = m[1];
|
std::string weight = m[1];
|
||||||
|
|
||||||
if (text == "(") {
|
if (text == "(") {
|
||||||
round_brackets.push_back(res.size());
|
round_brackets.push_back((int)res.size());
|
||||||
} else if (text == "[") {
|
} else if (text == "[") {
|
||||||
square_brackets.push_back(res.size());
|
square_brackets.push_back((int)res.size());
|
||||||
} else if (!weight.empty()) {
|
} else if (!weight.empty()) {
|
||||||
if (!round_brackets.empty()) {
|
if (!round_brackets.empty()) {
|
||||||
multiply_range(round_brackets.back(), std::stod(weight));
|
multiply_range(round_brackets.back(), std::stof(weight));
|
||||||
round_brackets.pop_back();
|
round_brackets.pop_back();
|
||||||
}
|
}
|
||||||
} else if (text == ")" && !round_brackets.empty()) {
|
} else if (text == ")" && !round_brackets.empty()) {
|
||||||
@ -2707,13 +2707,13 @@ struct DiscreteSchedule : SigmaSchedule {
|
|||||||
if (n == 0) {
|
if (n == 0) {
|
||||||
return result;
|
return result;
|
||||||
} else if (n == 1) {
|
} else if (n == 1) {
|
||||||
result.push_back(t_to_sigma(t_max));
|
result.push_back(t_to_sigma((float)t_max));
|
||||||
result.push_back(0);
|
result.push_back(0);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
float step = static_cast<float>(t_max) / static_cast<float>(n - 1);
|
float step = static_cast<float>(t_max) / static_cast<float>(n - 1);
|
||||||
for (int i = 0; i < n; ++i) {
|
for (uint32_t i = 0; i < n; ++i) {
|
||||||
float t = t_max - step * i;
|
float t = t_max - step * i;
|
||||||
result.push_back(t_to_sigma(t));
|
result.push_back(t_to_sigma(t));
|
||||||
}
|
}
|
||||||
@ -2726,17 +2726,17 @@ struct KarrasSchedule : SigmaSchedule {
|
|||||||
std::vector<float> get_sigmas(uint32_t n) {
|
std::vector<float> get_sigmas(uint32_t n) {
|
||||||
// These *COULD* be function arguments here,
|
// These *COULD* be function arguments here,
|
||||||
// but does anybody ever bother to touch them?
|
// but does anybody ever bother to touch them?
|
||||||
float sigma_min = 0.1;
|
float sigma_min = 0.1f;
|
||||||
float sigma_max = 10.;
|
float sigma_max = 10.f;
|
||||||
float rho = 7.;
|
float rho = 7.f;
|
||||||
|
|
||||||
std::vector<float> result(n + 1);
|
std::vector<float> result(n + 1);
|
||||||
|
|
||||||
float min_inv_rho = pow(sigma_min, (1. / rho));
|
float min_inv_rho = pow(sigma_min, (1.f / rho));
|
||||||
float max_inv_rho = pow(sigma_max, (1. / rho));
|
float max_inv_rho = pow(sigma_max, (1.f / rho));
|
||||||
for (int i = 0; i < n; i++) {
|
for (uint32_t i = 0; i < n; i++) {
|
||||||
// Eq. (5) from Karras et al 2022
|
// Eq. (5) from Karras et al 2022
|
||||||
result[i] = pow(max_inv_rho + (float)i / ((float)n - 1.) * (min_inv_rho - max_inv_rho), rho);
|
result[i] = pow(max_inv_rho + (float)i / ((float)n - 1.f) * (min_inv_rho - max_inv_rho), rho);
|
||||||
}
|
}
|
||||||
result[n] = 0.;
|
result[n] = 0.;
|
||||||
return result;
|
return result;
|
||||||
@ -3748,7 +3748,7 @@ class StableDiffusionGGML {
|
|||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// DPM-Solver-2
|
// DPM-Solver-2
|
||||||
float sigma_mid = exp(0.5 * (log(sigmas[i]) + log(sigmas[i + 1])));
|
float sigma_mid = exp(0.5f * (log(sigmas[i]) + log(sigmas[i + 1])));
|
||||||
float dt_1 = sigma_mid - sigmas[i];
|
float dt_1 = sigma_mid - sigmas[i];
|
||||||
float dt_2 = sigmas[i + 1] - sigmas[i];
|
float dt_2 = sigmas[i + 1] - sigmas[i];
|
||||||
|
|
||||||
@ -3811,7 +3811,7 @@ class StableDiffusionGGML {
|
|||||||
float t = t_fn(sigmas[i]);
|
float t = t_fn(sigmas[i]);
|
||||||
float t_next = t_fn(sigma_down);
|
float t_next = t_fn(sigma_down);
|
||||||
float h = t_next - t;
|
float h = t_next - t;
|
||||||
float s = t + 0.5 * h;
|
float s = t + 0.5f * h;
|
||||||
|
|
||||||
float* vec_d = (float*)d->data;
|
float* vec_d = (float*)d->data;
|
||||||
float* vec_x = (float*)x->data;
|
float* vec_x = (float*)x->data;
|
||||||
@ -3820,7 +3820,7 @@ class StableDiffusionGGML {
|
|||||||
|
|
||||||
// First half-step
|
// First half-step
|
||||||
for (int j = 0; j < ggml_nelements(x); j++) {
|
for (int j = 0; j < ggml_nelements(x); j++) {
|
||||||
vec_x2[j] = (sigma_fn(s) / sigma_fn(t)) * vec_x[j] - (exp(-h * 0.5) - 1) * vec_denoised[j];
|
vec_x2[j] = (sigma_fn(s) / sigma_fn(t)) * vec_x[j] - (exp(-h * 0.5f) - 1) * vec_denoised[j];
|
||||||
}
|
}
|
||||||
|
|
||||||
denoise(x2, sigmas[i + 1], i + 1);
|
denoise(x2, sigmas[i + 1], i + 1);
|
||||||
@ -3862,7 +3862,7 @@ class StableDiffusionGGML {
|
|||||||
float t_next = t_fn(sigmas[i + 1]);
|
float t_next = t_fn(sigmas[i + 1]);
|
||||||
float h = t_next - t;
|
float h = t_next - t;
|
||||||
float a = sigmas[i + 1] / sigmas[i];
|
float a = sigmas[i + 1] / sigmas[i];
|
||||||
float b = exp(-h) - 1.;
|
float b = exp(-h) - 1.f;
|
||||||
float* vec_x = (float*)x->data;
|
float* vec_x = (float*)x->data;
|
||||||
float* vec_denoised = (float*)denoised->data;
|
float* vec_denoised = (float*)denoised->data;
|
||||||
float* vec_old_denoised = (float*)old_denoised->data;
|
float* vec_old_denoised = (float*)old_denoised->data;
|
||||||
@ -3876,7 +3876,7 @@ class StableDiffusionGGML {
|
|||||||
float h_last = t - t_fn(sigmas[i - 1]);
|
float h_last = t - t_fn(sigmas[i - 1]);
|
||||||
float r = h_last / h;
|
float r = h_last / h;
|
||||||
for (int j = 0; j < ggml_nelements(x); j++) {
|
for (int j = 0; j < ggml_nelements(x); j++) {
|
||||||
float denoised_d = (1. + 1. / (2. * r)) * vec_denoised[j] - (1. / (2. * r)) * vec_old_denoised[j];
|
float denoised_d = (1.f + 1.f / (2.f * r)) * vec_denoised[j] - (1.f / (2.f * r)) * vec_old_denoised[j];
|
||||||
vec_x[j] = a * vec_x[j] - b * denoised_d;
|
vec_x[j] = a * vec_x[j] - b * denoised_d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -3910,7 +3910,7 @@ class StableDiffusionGGML {
|
|||||||
|
|
||||||
if (i == 0 || sigmas[i + 1] == 0) {
|
if (i == 0 || sigmas[i + 1] == 0) {
|
||||||
// Simpler step for the edge cases
|
// Simpler step for the edge cases
|
||||||
float b = exp(-h) - 1.;
|
float b = exp(-h) - 1.f;
|
||||||
for (int j = 0; j < ggml_nelements(x); j++) {
|
for (int j = 0; j < ggml_nelements(x); j++) {
|
||||||
vec_x[j] = a * vec_x[j] - b * vec_denoised[j];
|
vec_x[j] = a * vec_x[j] - b * vec_denoised[j];
|
||||||
}
|
}
|
||||||
@ -3919,10 +3919,10 @@ class StableDiffusionGGML {
|
|||||||
float h_min = std::min(h_last, h);
|
float h_min = std::min(h_last, h);
|
||||||
float h_max = std::max(h_last, h);
|
float h_max = std::max(h_last, h);
|
||||||
float r = h_max / h_min;
|
float r = h_max / h_min;
|
||||||
float h_d = (h_max + h_min) / 2.;
|
float h_d = (h_max + h_min) / 2.f;
|
||||||
float b = exp(-h_d) - 1.;
|
float b = exp(-h_d) - 1.f;
|
||||||
for (int j = 0; j < ggml_nelements(x); j++) {
|
for (int j = 0; j < ggml_nelements(x); j++) {
|
||||||
float denoised_d = (1. + 1. / (2. * r)) * vec_denoised[j] - (1. / (2. * r)) * vec_old_denoised[j];
|
float denoised_d = (1.f + 1.f / (2.f * r)) * vec_denoised[j] - (1.f / (2.f * r)) * vec_old_denoised[j];
|
||||||
vec_x[j] = a * vec_x[j] - b * denoised_d;
|
vec_x[j] = a * vec_x[j] - b * denoised_d;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user