Skip to content

Commit 37036d9

Browse files
committed
format code and avoid some warnings
1 parent c2d7c0c commit 37036d9

File tree

3 files changed

+46
-49
lines changed

3 files changed

+46
-49
lines changed

denoiser.hpp

+40-44
Original file line numberDiff line numberDiff line change
@@ -80,31 +80,30 @@ struct DiscreteSchedule : SigmaSchedule {
8080
https://research.nvidia.com/labs/toronto-ai/AlignYourSteps/howto.html
8181
*/
8282
struct AYSSchedule : SigmaSchedule {
83-
/* interp and linearInterp adapted from dpilger26's NumCpp library:
83+
/* interp and linear_interp adapted from dpilger26's NumCpp library:
8484
* https://github.com/dpilger26/NumCpp/tree/5e40aab74d14e257d65d3dc385c9ff9e2120c60e */
8585
constexpr double interp(double left, double right, double perc) noexcept {
8686
return (left * (1. - perc)) + (right * perc);
8787
}
8888

89-
/* This will make the assumption that the reference x and y values are
90-
* already sorted in ascending order because they are being generated as
89+
/* This will make the assumption that the reference x and y values are
90+
* already sorted in ascending order because they are being generated as
9191
* such in the calling function */
92-
std::vector<double> linearInterp(std::vector<float> new_x,
93-
const std::vector<float> ref_x, const std::vector<float> ref_y)
94-
{
92+
std::vector<double> linear_interp(std::vector<float> new_x,
93+
const std::vector<float> ref_x,
94+
const std::vector<float> ref_y) {
9595
const size_t len_x = new_x.size();
96-
size_t i = 0;
97-
size_t j = 0;
96+
size_t i = 0;
97+
size_t j = 0;
9898
std::vector<double> new_y(len_x);
9999

100-
if (ref_x.size() != ref_y.size()) {
100+
if (ref_x.size() != ref_y.size()) {
101101
LOG_ERROR("Linear Interoplation Failed: length mismatch");
102-
return new_y;
102+
return new_y;
103103
}
104104

105105
/* serves as the bounds checking for the below while loop */
106-
if ((new_x[0] < ref_x[0])
107-
|| (new_x[new_x.size() - 1] > ref_x[ref_x.size() - 1])) {
106+
if ((new_x[0] < ref_x[0]) || (new_x[new_x.size() - 1] > ref_x[ref_x.size() - 1])) {
108107
LOG_ERROR("Linear Interpolation Failed: bad bounds");
109108
return new_y;
110109
}
@@ -115,8 +114,7 @@ struct AYSSchedule : SigmaSchedule {
115114
continue;
116115
}
117116

118-
const double perc = static_cast<double>(new_x[i] - ref_x[j])
119-
/ static_cast<double>(ref_x[j + 1] - ref_x[j]);
117+
const double perc = static_cast<double>(new_x[i] - ref_x[j]) / static_cast<double>(ref_x[j + 1] - ref_x[j]);
120118

121119
new_y[i] = interp(ref_y[j], ref_y[j + 1], perc);
122120
i++;
@@ -125,8 +123,7 @@ struct AYSSchedule : SigmaSchedule {
125123
return new_y;
126124
}
127125

128-
std::vector<float> linearSpace(const float start, const float end,
129-
const size_t num_points) {
126+
std::vector<float> linear_space(const float start, const float end, const size_t num_points) {
130127
std::vector<float> result(num_points);
131128
const float inc = (end - start) / (static_cast<float>(num_points - 1));
132129

@@ -141,10 +138,10 @@ struct AYSSchedule : SigmaSchedule {
141138
return result;
142139
}
143140

144-
std::vector<float> logLinearInterpolation(std::vector<float> sigma_in,
145-
const size_t new_len) {
141+
std::vector<float> log_linear_interpolation(std::vector<float> sigma_in,
142+
const size_t new_len) {
146143
const size_t s_len = sigma_in.size();
147-
std::vector<float> x_vals = linearSpace(0.f, 1.f, s_len);
144+
std::vector<float> x_vals = linear_space(0.f, 1.f, s_len);
148145
std::vector<float> y_vals(s_len);
149146

150147
/* Reverses the input array to be ascending instead of descending,
@@ -153,8 +150,8 @@ struct AYSSchedule : SigmaSchedule {
153150
y_vals[i] = std::log(sigma_in[s_len - i - 1]);
154151
}
155152

156-
std::vector<float> new_x_vals = linearSpace(0.f, 1.f, new_len);
157-
std::vector<double> new_y_vals = linearInterp(new_x_vals, x_vals, y_vals);
153+
std::vector<float> new_x_vals = linear_space(0.f, 1.f, new_len);
154+
std::vector<double> new_y_vals = linear_interp(new_x_vals, x_vals, y_vals);
158155
std::vector<float> results(new_len);
159156

160157
for (size_t i = 0; i < new_len; i++) {
@@ -164,56 +161,55 @@ struct AYSSchedule : SigmaSchedule {
164161
return results;
165162
}
166163

167-
168164
std::vector<float> get_sigmas(uint32_t len) {
169165
const std::vector<float> noise_levels[] = {
170166
/* SD1.5 */
171-
{14.6146412293, 6.4745760956, 3.8636745985, 2.6946151520,
172-
1.8841921177, 1.3943805092, 0.9642583904, 0.6523686016,
173-
0.3977456272, 0.1515232662, 0.0291671582},
167+
{14.6146412293f, 6.4745760956f, 3.8636745985f, 2.6946151520f,
168+
1.8841921177f, 1.3943805092f, 0.9642583904f, 0.6523686016f,
169+
0.3977456272f, 0.1515232662f, 0.0291671582f},
174170
/* SDXL */
175-
{14.6146412293, 6.3184485287, 3.7681790315, 2.1811480769,
176-
1.3405244945, 0.8620721141, 0.5550693289, 0.3798540708,
177-
0.2332364134, 0.1114188177, 0.0291671582},
171+
{14.6146412293f, 6.3184485287f, 3.7681790315f, 2.1811480769f,
172+
1.3405244945f, 0.8620721141f, 0.5550693289f, 0.3798540708f,
173+
0.2332364134f, 0.1114188177f, 0.0291671582f},
178174
/* SVD */
179-
{700.00, 54.5, 15.886, 7.977, 4.248, 1.789, 0.981, 0.403,
180-
0.173, 0.034, 0.002},
175+
{700.00f, 54.5f, 15.886f, 7.977f, 4.248f, 1.789f, 0.981f, 0.403f,
176+
0.173f, 0.034f, 0.002f},
181177
};
182-
178+
183179
std::vector<float> inputs;
184180
std::vector<float> results(len + 1);
185-
181+
186182
switch (version) {
187183
case VERSION_2_x: /* fallthrough */
188-
LOG_WARN("AYS not designed for SD2.X models");
189-
case VERSION_1_x:
190-
LOG_INFO("AYS using SD1.5 noise levels");
184+
LOG_WARN("AYS not designed for SD2.X models");
185+
case VERSION_1_x:
186+
LOG_INFO("AYS using SD1.5 noise levels");
191187
inputs = noise_levels[0];
192188
break;
193189
case VERSION_XL:
194-
LOG_INFO("AYS using SDXL noise levels");
190+
LOG_INFO("AYS using SDXL noise levels");
195191
inputs = noise_levels[1];
196192
break;
197193
case VERSION_SVD:
198-
LOG_INFO("AYS using SVD noise levels");
194+
LOG_INFO("AYS using SVD noise levels");
199195
inputs = noise_levels[2];
200196
break;
201197
default:
202198
LOG_ERROR("Version not compatable with AYS scheduler");
203199
return results;
204200
}
205-
201+
206202
/* Stretches those pre-calculated reference levels out to the desired
207203
* size using log-linear interpolation */
208204
if ((len + 1) != inputs.size()) {
209-
results = logLinearInterpolation(inputs, len + 1);
205+
results = log_linear_interpolation(inputs, len + 1);
210206
} else {
211-
results = inputs;
212-
}
213-
207+
results = inputs;
208+
}
209+
214210
/* Not sure if this is strictly neccessary */
215211
results[len] = 0.0f;
216-
212+
217213
return results;
218214
}
219215
};
@@ -230,7 +226,7 @@ struct KarrasSchedule : SigmaSchedule {
230226

231227
float min_inv_rho = pow(sigma_min, (1.f / rho));
232228
float max_inv_rho = pow(sigma_max, (1.f / rho));
233-
for (uint32_t i = 0; i < n; i++) {
229+
for (uint32_t i = 0; i < n; i++) {
234230
// Eq. (5) from Karras et al 2022
235231
result[i] = pow(max_inv_rho + (float)i / ((float)n - 1.f) * (min_inv_rho - max_inv_rho), rho);
236232
}

model.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ bool ModelLoader::init_from_safetensors_file(const std::string& file_path, const
890890

891891
// ggml/src/ggml.c:2745
892892
if (n_dims < 1 || n_dims > GGML_MAX_DIMS) {
893+
LOG_ERROR("skip tensor '%s' with n_dims %d", name.c_str(), n_dims);
893894
continue;
894895
}
895896

stable-diffusion.cpp

+5-5
Original file line numberDiff line numberDiff line change
@@ -450,11 +450,11 @@ class StableDiffusionGGML {
450450
LOG_INFO("running with Karras schedule");
451451
denoiser->schedule = std::make_shared<KarrasSchedule>();
452452
break;
453-
case AYS:
454-
LOG_INFO("Running with Align-Your-Steps schedule");
455-
denoiser->schedule = std::make_shared<AYSSchedule>();
456-
denoiser->schedule->version = version;
457-
break;
453+
case AYS:
454+
LOG_INFO("Running with Align-Your-Steps schedule");
455+
denoiser->schedule = std::make_shared<AYSSchedule>();
456+
denoiser->schedule->version = version;
457+
break;
458458
case DEFAULT:
459459
// Don't touch anything.
460460
break;

0 commit comments

Comments
 (0)