Skip to content

Commit c242dd4

Browse files
committed
remove debug comments
1 parent 6f81e6b commit c242dd4

File tree

4 files changed

+43
-102
lines changed

4 files changed

+43
-102
lines changed

denoiser.hpp

Lines changed: 7 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -237,21 +237,14 @@ struct GITSSchedule : SigmaSchedule {
237237

238238
struct SGMUniformSchedule : SigmaSchedule {
239239
std::vector<float> get_sigmas(uint32_t n, float sigma_min_in, float sigma_max_in, t_to_sigma_t t_to_sigma_func) override {
240-
// This schedule's core logic is now handled directly in Denoiser::get_sigmas
241-
// to ensure correct access to both sigma_to_t and t_to_sigma.
242-
// This method is overridden to fulfill the virtual contract but ideally should not be
243-
// the primary execution path for SGMUniform when called from Denoiser::get_sigmas.
244-
// If it IS called, it means the Denoiser::get_sigmas logic wasn't triggered, which is unexpected.
245-
LOG_WARN("SGMUniformSchedule::get_sigmas was called directly. This might indicate an issue with Denoiser dispatch.");
246-
// Provide a default (potentially incorrect for SGMUniform's intent) or empty schedule to avoid crashes.
247-
// For safety, returning a simple discrete-like schedule in t-space if this is ever hit.
240+
248241
std::vector<float> result;
249242
if (n == 0) {
250243
result.push_back(0.0f);
251244
return result;
252245
}
253246
result.reserve(n + 1);
254-
int t_max = TIMESTEPS -1; // A common max t value
247+
int t_max = TIMESTEPS -1;
255248
float step = static_cast<float>(t_max) / static_cast<float>(n > 1 ? (n -1) : 1) ;
256249
for(uint32_t i=0; i<n; ++i) {
257250
result.push_back(t_to_sigma_func(t_max - step * i));
@@ -284,39 +277,27 @@ struct SimpleSchedule : SigmaSchedule {
284277
std::vector<float> result_sigmas;
285278

286279
if (n == 0) {
287-
return result_sigmas; // Return empty for n=0, consistent with DiscreteSchedule
280+
return result_sigmas;
288281
}
289282

290283
result_sigmas.reserve(n + 1);
291284

292-
// TIMESTEPS is the length of the model's internal sigmas array, typically 1000.
293-
// t_to_sigma(t) maps a timestep t (0 to TIMESTEPS-1) to its sigma value.
294285
int model_sigmas_len = TIMESTEPS;
295286

296-
// ss = len(s.sigmas) / steps in Python
297287
float step_factor = static_cast<float>(model_sigmas_len) / static_cast<float>(n);
298288

299289
for (uint32_t i = 0; i < n; ++i) {
300-
// Python: s.sigmas[-(1 + int(x * ss))]
301-
// x corresponds to i (0 to n-1)
302-
// int(x * ss) in Python is static_cast<int>(static_cast<float>(i) * step_factor)
303-
// The index -(1 + offset) means (model_sigmas_len - 1 - offset) from the start of a 0-indexed array.
290+
304291
int offset_from_start_of_py_array = static_cast<int>(static_cast<float>(i) * step_factor);
305292
int timestep_index = model_sigmas_len - 1 - offset_from_start_of_py_array;
306293

307-
// Ensure the index is within valid bounds [0, model_sigmas_len - 1]
308294
if (timestep_index < 0) {
309295
timestep_index = 0;
310296
}
311-
// No need for upper bound check like `timestep_index >= model_sigmas_len` because
312-
// max offset is for i=n-1: int((n-1)/n * model_sigmas_len) which is < model_sigmas_len.
313-
// So, model_sigmas_len - 1 - max_offset is >= 0 if model_sigmas_len/n >= 1.
314-
// If n > model_sigmas_len, then model_sigmas_len/n < 1, resulting in timestep_index potentially being <0,
315-
// which is handled by the clamp above.
316297

317298
result_sigmas.push_back(t_to_sigma(static_cast<float>(timestep_index)));
318299
}
319-
result_sigmas.push_back(0.0f); // Append the final zero sigma
300+
result_sigmas.push_back(0.0f);
320301
return result_sigmas;
321302
}
322303
};
@@ -334,7 +315,6 @@ struct Denoiser {
334315
virtual std::vector<float> get_sigmas(uint32_t n) {
335316
// Check if the current schedule is SGMUniformSchedule
336317
if (std::dynamic_pointer_cast<SGMUniformSchedule>(schedule)) {
337-
LOG_DEBUG("Denoiser::get_sigmas - Using SGM_UNIFORM specific logic");
338318
std::vector<float> sigs;
339319
sigs.reserve(n + 1);
340320

@@ -347,26 +327,22 @@ struct Denoiser {
347327
float start_t_val = this->sigma_to_t(this->sigma_max());
348328
float end_t_val = this->sigma_to_t(this->sigma_min());
349329

350-
// Python: torch.linspace(start, end, n + 1)[:-1]
351-
// This creates n points. The k-th point (0-indexed) is start_t_val + k * (end_t_val - start_t_val) / n.
352330
float dt_per_step;
353-
if (n > 0) { // Avoid division by zero if n=0, though covered by earlier check
331+
if (n > 0) {
354332
dt_per_step = (end_t_val - start_t_val) / static_cast<float>(n);
355333
} else {
356334
dt_per_step = 0.0f;
357335
}
358336

359-
360337
for (uint32_t i = 0; i < n; ++i) {
361338
float current_t = start_t_val + static_cast<float>(i) * dt_per_step;
362339
sigs.push_back(this->t_to_sigma(current_t));
363340
}
364341

365-
sigs.push_back(0.0f); // Append the final zero sigma
342+
sigs.push_back(0.0f);
366343
return sigs;
367344

368345
} else { // For all other schedules, use the existing virtual dispatch
369-
LOG_DEBUG("Denoiser::get_sigmas - Using general schedule dispatch for %s", typeid(*schedule.get()).name());
370346
auto bound_t_to_sigma = std::bind(&Denoiser::t_to_sigma, this, std::placeholders::_1);
371347
return schedule->get_sigmas(n, sigma_min(), sigma_max(), bound_t_to_sigma);
372348
}

examples/cli/main.cpp

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,10 @@ struct SDParams {
128128
int upscale_repeats = 1;
129129

130130
std::vector<int> skip_layers = {7, 8, 9};
131-
float slg_scale = 0.f; // Removed duplicate line
131+
float slg_scale = 0.f;
132132
float skip_layer_start = 0.01f;
133133
float skip_layer_end = 0.2f;
134-
int shifted_timestep = -1; // Keep the added parameter from previous step
134+
int shifted_timestep = -1;
135135
};
136136

137137
void print_params(SDParams params) {
@@ -248,7 +248,7 @@ void print_usage(int argc, const char* argv[]) {
248248
printf(" --control-net-cpu keep controlnet in cpu (for low vram)\n");
249249
printf(" --canny apply canny preprocessor (edge detection)\n");
250250
printf(" --color Colors the logging tags according to level\n");
251-
printf(" --timestep-shift N shift timestep for SDXL models (NitroFusion paper, default: -1 off, N between 1 and 1000)\n");
251+
printf(" --timestep-shift N shift timestep for NitroFusion models, default: -1 off, recommended N for NitroSD-Realism around 250 and 500 for NitroSD-Vibrant\n");
252252
printf(" -v, --verbose print extra info\n");
253253
}
254254

@@ -539,15 +539,14 @@ void parse_args(int argc, const char** argv, SDParams& params) {
539539
}
540540
const char* schedule_selected = argv[i];
541541
int schedule_found = -1;
542-
// N_SCHEDULES will be updated by the .h change, so this loop limit is fine
543542
for (int d = 0; d < N_SCHEDULES; d++) {
544543
if (!strcmp(schedule_selected, schedule_str[d])) {
545544
schedule_found = d;
546545
}
547546
}
548547
if (schedule_found == -1) {
549548
fprintf(stderr, "error: invalid schedule %s, must be one of [discrete, karras, exponential, ays, gits, sgm_uniform, simple]\n", schedule_selected);
550-
exit(1); // Exit directly as invalid_arg only triggers at the end
549+
exit(1);
551550
}
552551
params.schedule = (schedule_t)schedule_found;
553552
} else if (arg == "-s" || arg == "--seed") {
@@ -635,7 +634,7 @@ void parse_args(int argc, const char** argv, SDParams& params) {
635634
break;
636635
}
637636
params.skip_layer_end = std::stof(argv[i]);
638-
} else if (arg == "--timestep-shift") { // Added block
637+
} else if (arg == "--timestep-shift") {
639638
if (++i >= argc) {
640639
invalid_arg = true;
641640
break;
@@ -984,7 +983,7 @@ int main(int argc, const char* argv[]) {
984983
params.slg_scale,
985984
params.skip_layer_start,
986985
params.skip_layer_end,
987-
params.shifted_timestep); // Passed parameter
986+
params.shifted_timestep);
988987
} else {
989988
sd_image_t input_image = {(uint32_t)params.width,
990989
(uint32_t)params.height,
@@ -1054,7 +1053,7 @@ int main(int argc, const char* argv[]) {
10541053
params.slg_scale,
10551054
params.skip_layer_start,
10561055
params.skip_layer_end,
1057-
params.shifted_timestep); // Passed parameter
1056+
params.shifted_timestep);
10581057
}
10591058
}
10601059

model.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,6 @@ std::string convert_open_clip_to_hf_clip(const std::string& name) {
185185
new_name = new_name.substr(strlen("conditioner.embedders.0."));
186186
} else if (starts_with(new_name, "conditioner.embedders.1.")) {
187187
prefix = "cond_stage_model.1.";
188-
// Corrected the substring length to match the prefix being checked
189188
new_name = new_name.substr(strlen("conditioner.embedders.1."));
190189
} else if (starts_with(new_name, "cond_stage_model.")) {
191190
prefix = "cond_stage_model.";
@@ -194,8 +193,6 @@ std::string convert_open_clip_to_hf_clip(const std::string& name) {
194193
prefix = new_name.substr(0, new_name.size() - strlen("vision_model.visual_projection.weight"));
195194
new_name = prefix + "visual_projection.weight";
196195
return new_name;
197-
// This specific case seems less common or might be handled implicitly later,
198-
// but we keep the original logic for now. If issues arise, review if this mapping is needed.
199196
} else if (ends_with(new_name, "transformer.text_projection.weight")) {
200197
prefix = new_name.substr(0, new_name.size() - strlen("transformer.text_projection.weight"));
201198
new_name = prefix + "transformer.text_model.text_projection";
@@ -204,13 +201,11 @@ std::string convert_open_clip_to_hf_clip(const std::string& name) {
204201
return new_name;
205202
}
206203

207-
// Specific handling for text_projection variants before generic map lookup
208204
if (new_name == "model.text_projection.weight" || new_name == "model.text_projection") {
209205
new_name = "transformer.text_model.text_projection";
210-
} else if (open_clip_to_hf_clip_model.count(new_name)) { // Use .count() for safety
206+
} else if (open_clip_to_hf_clip_model.count(new_name)) {
211207
new_name = open_clip_to_hf_clip_model[new_name];
212208
}
213-
// Note: The specific handling above takes precedence over the map for this tensor.
214209

215210
std::string open_clip_resblock_prefix = "model.transformer.resblocks.";
216211
std::string hf_clip_resblock_prefix = "transformer.text_model.encoder.layers.";

0 commit comments

Comments
 (0)