mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-03-31 05:39:42 +00:00
refactor: move VAE tiling parameters to SDGenerationParams (#1261)
This commit is contained in:
parent
8f2967c006
commit
02dd5e5dd2
@ -750,7 +750,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
gen_params.pm_id_embed_path.c_str(),
|
gen_params.pm_id_embed_path.c_str(),
|
||||||
gen_params.pm_style_strength,
|
gen_params.pm_style_strength,
|
||||||
}, // pm_params
|
}, // pm_params
|
||||||
ctx_params.vae_tiling_params,
|
gen_params.vae_tiling_params,
|
||||||
gen_params.cache_params,
|
gen_params.cache_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -776,7 +776,7 @@ int main(int argc, const char* argv[]) {
|
|||||||
gen_params.seed,
|
gen_params.seed,
|
||||||
gen_params.video_frames,
|
gen_params.video_frames,
|
||||||
gen_params.vace_strength,
|
gen_params.vace_strength,
|
||||||
ctx_params.vae_tiling_params,
|
gen_params.vae_tiling_params,
|
||||||
gen_params.cache_params,
|
gen_params.cache_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -475,8 +475,7 @@ struct SDContextParams {
|
|||||||
prediction_t prediction = PREDICTION_COUNT;
|
prediction_t prediction = PREDICTION_COUNT;
|
||||||
lora_apply_mode_t lora_apply_mode = LORA_APPLY_AUTO;
|
lora_apply_mode_t lora_apply_mode = LORA_APPLY_AUTO;
|
||||||
|
|
||||||
sd_tiling_params_t vae_tiling_params = {false, 0, 0, 0.5f, 0.0f, 0.0f};
|
bool force_sdxl_vae_conv_scale = false;
|
||||||
bool force_sdxl_vae_conv_scale = false;
|
|
||||||
|
|
||||||
float flow_shift = INFINITY;
|
float flow_shift = INFINITY;
|
||||||
|
|
||||||
@ -576,18 +575,9 @@ struct SDContextParams {
|
|||||||
&chroma_t5_mask_pad},
|
&chroma_t5_mask_pad},
|
||||||
};
|
};
|
||||||
|
|
||||||
options.float_options = {
|
options.float_options = {};
|
||||||
{"",
|
|
||||||
"--vae-tile-overlap",
|
|
||||||
"tile overlap for vae tiling, in fraction of tile size (default: 0.5)",
|
|
||||||
&vae_tiling_params.target_overlap},
|
|
||||||
};
|
|
||||||
|
|
||||||
options.bool_options = {
|
options.bool_options = {
|
||||||
{"",
|
|
||||||
"--vae-tiling",
|
|
||||||
"process vae in tiles to reduce memory usage",
|
|
||||||
true, &vae_tiling_params.enabled},
|
|
||||||
{"",
|
{"",
|
||||||
"--force-sdxl-vae-conv-scale",
|
"--force-sdxl-vae-conv-scale",
|
||||||
"force use of conv scale on sdxl vae",
|
"force use of conv scale on sdxl vae",
|
||||||
@ -724,52 +714,6 @@ struct SDContextParams {
|
|||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
auto on_tile_size_arg = [&](int argc, const char** argv, int index) {
|
|
||||||
if (++index >= argc) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
std::string tile_size_str = argv[index];
|
|
||||||
size_t x_pos = tile_size_str.find('x');
|
|
||||||
try {
|
|
||||||
if (x_pos != std::string::npos) {
|
|
||||||
std::string tile_x_str = tile_size_str.substr(0, x_pos);
|
|
||||||
std::string tile_y_str = tile_size_str.substr(x_pos + 1);
|
|
||||||
vae_tiling_params.tile_size_x = std::stoi(tile_x_str);
|
|
||||||
vae_tiling_params.tile_size_y = std::stoi(tile_y_str);
|
|
||||||
} else {
|
|
||||||
vae_tiling_params.tile_size_x = vae_tiling_params.tile_size_y = std::stoi(tile_size_str);
|
|
||||||
}
|
|
||||||
} catch (const std::invalid_argument&) {
|
|
||||||
return -1;
|
|
||||||
} catch (const std::out_of_range&) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
auto on_relative_tile_size_arg = [&](int argc, const char** argv, int index) {
|
|
||||||
if (++index >= argc) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
std::string rel_size_str = argv[index];
|
|
||||||
size_t x_pos = rel_size_str.find('x');
|
|
||||||
try {
|
|
||||||
if (x_pos != std::string::npos) {
|
|
||||||
std::string rel_x_str = rel_size_str.substr(0, x_pos);
|
|
||||||
std::string rel_y_str = rel_size_str.substr(x_pos + 1);
|
|
||||||
vae_tiling_params.rel_size_x = std::stof(rel_x_str);
|
|
||||||
vae_tiling_params.rel_size_y = std::stof(rel_y_str);
|
|
||||||
} else {
|
|
||||||
vae_tiling_params.rel_size_x = vae_tiling_params.rel_size_y = std::stof(rel_size_str);
|
|
||||||
}
|
|
||||||
} catch (const std::invalid_argument&) {
|
|
||||||
return -1;
|
|
||||||
} catch (const std::out_of_range&) {
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
return 1;
|
|
||||||
};
|
|
||||||
|
|
||||||
options.manual_options = {
|
options.manual_options = {
|
||||||
{"",
|
{"",
|
||||||
"--type",
|
"--type",
|
||||||
@ -796,14 +740,6 @@ struct SDContextParams {
|
|||||||
"but it usually offers faster inference speed and, in some cases, lower memory usage. "
|
"but it usually offers faster inference speed and, in some cases, lower memory usage. "
|
||||||
"The at_runtime mode, on the other hand, is exactly the opposite.",
|
"The at_runtime mode, on the other hand, is exactly the opposite.",
|
||||||
on_lora_apply_mode_arg},
|
on_lora_apply_mode_arg},
|
||||||
{"",
|
|
||||||
"--vae-tile-size",
|
|
||||||
"tile size for vae tiling, format [X]x[Y] (default: 32x32)",
|
|
||||||
on_tile_size_arg},
|
|
||||||
{"",
|
|
||||||
"--vae-relative-tile-size",
|
|
||||||
"relative tile size for vae tiling, format [X]x[Y], in fraction of image size if < 1, in number of tiles per dim if >=1 (overrides --vae-tile-size)",
|
|
||||||
on_relative_tile_size_arg},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return options;
|
return options;
|
||||||
@ -917,13 +853,6 @@ struct SDContextParams {
|
|||||||
<< " chroma_t5_mask_pad: " << chroma_t5_mask_pad << ",\n"
|
<< " chroma_t5_mask_pad: " << chroma_t5_mask_pad << ",\n"
|
||||||
<< " prediction: " << sd_prediction_name(prediction) << ",\n"
|
<< " prediction: " << sd_prediction_name(prediction) << ",\n"
|
||||||
<< " lora_apply_mode: " << sd_lora_apply_mode_name(lora_apply_mode) << ",\n"
|
<< " lora_apply_mode: " << sd_lora_apply_mode_name(lora_apply_mode) << ",\n"
|
||||||
<< " vae_tiling_params: { "
|
|
||||||
<< vae_tiling_params.enabled << ", "
|
|
||||||
<< vae_tiling_params.tile_size_x << ", "
|
|
||||||
<< vae_tiling_params.tile_size_y << ", "
|
|
||||||
<< vae_tiling_params.target_overlap << ", "
|
|
||||||
<< vae_tiling_params.rel_size_x << ", "
|
|
||||||
<< vae_tiling_params.rel_size_y << " },\n"
|
|
||||||
<< " force_sdxl_vae_conv_scale: " << (force_sdxl_vae_conv_scale ? "true" : "false") << "\n"
|
<< " force_sdxl_vae_conv_scale: " << (force_sdxl_vae_conv_scale ? "true" : "false") << "\n"
|
||||||
<< "}";
|
<< "}";
|
||||||
return oss.str();
|
return oss.str();
|
||||||
@ -1061,6 +990,8 @@ struct SDGenerationParams {
|
|||||||
|
|
||||||
int64_t seed = 42;
|
int64_t seed = 42;
|
||||||
|
|
||||||
|
sd_tiling_params_t vae_tiling_params = {false, 0, 0, 0.5f, 0.0f, 0.0f};
|
||||||
|
|
||||||
// Photo Maker
|
// Photo Maker
|
||||||
std::string pm_id_images_dir;
|
std::string pm_id_images_dir;
|
||||||
std::string pm_id_embed_path;
|
std::string pm_id_embed_path;
|
||||||
@ -1251,6 +1182,10 @@ struct SDGenerationParams {
|
|||||||
"--vace-strength",
|
"--vace-strength",
|
||||||
"wan vace strength",
|
"wan vace strength",
|
||||||
&vace_strength},
|
&vace_strength},
|
||||||
|
{"",
|
||||||
|
"--vae-tile-overlap",
|
||||||
|
"tile overlap for vae tiling, in fraction of tile size (default: 0.5)",
|
||||||
|
&vae_tiling_params.target_overlap},
|
||||||
};
|
};
|
||||||
|
|
||||||
options.bool_options = {
|
options.bool_options = {
|
||||||
@ -1264,6 +1199,10 @@ struct SDGenerationParams {
|
|||||||
"disable auto resize of ref images",
|
"disable auto resize of ref images",
|
||||||
false,
|
false,
|
||||||
&auto_resize_ref_image},
|
&auto_resize_ref_image},
|
||||||
|
{"",
|
||||||
|
"--vae-tiling",
|
||||||
|
"process vae in tiles to reduce memory usage",
|
||||||
|
true, &vae_tiling_params.enabled},
|
||||||
};
|
};
|
||||||
|
|
||||||
auto on_seed_arg = [&](int argc, const char** argv, int index) {
|
auto on_seed_arg = [&](int argc, const char** argv, int index) {
|
||||||
@ -1460,6 +1399,52 @@ struct SDGenerationParams {
|
|||||||
return 1;
|
return 1;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
auto on_tile_size_arg = [&](int argc, const char** argv, int index) {
|
||||||
|
if (++index >= argc) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::string tile_size_str = argv[index];
|
||||||
|
size_t x_pos = tile_size_str.find('x');
|
||||||
|
try {
|
||||||
|
if (x_pos != std::string::npos) {
|
||||||
|
std::string tile_x_str = tile_size_str.substr(0, x_pos);
|
||||||
|
std::string tile_y_str = tile_size_str.substr(x_pos + 1);
|
||||||
|
vae_tiling_params.tile_size_x = std::stoi(tile_x_str);
|
||||||
|
vae_tiling_params.tile_size_y = std::stoi(tile_y_str);
|
||||||
|
} else {
|
||||||
|
vae_tiling_params.tile_size_x = vae_tiling_params.tile_size_y = std::stoi(tile_size_str);
|
||||||
|
}
|
||||||
|
} catch (const std::invalid_argument&) {
|
||||||
|
return -1;
|
||||||
|
} catch (const std::out_of_range&) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
|
auto on_relative_tile_size_arg = [&](int argc, const char** argv, int index) {
|
||||||
|
if (++index >= argc) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
std::string rel_size_str = argv[index];
|
||||||
|
size_t x_pos = rel_size_str.find('x');
|
||||||
|
try {
|
||||||
|
if (x_pos != std::string::npos) {
|
||||||
|
std::string rel_x_str = rel_size_str.substr(0, x_pos);
|
||||||
|
std::string rel_y_str = rel_size_str.substr(x_pos + 1);
|
||||||
|
vae_tiling_params.rel_size_x = std::stof(rel_x_str);
|
||||||
|
vae_tiling_params.rel_size_y = std::stof(rel_y_str);
|
||||||
|
} else {
|
||||||
|
vae_tiling_params.rel_size_x = vae_tiling_params.rel_size_y = std::stof(rel_size_str);
|
||||||
|
}
|
||||||
|
} catch (const std::invalid_argument&) {
|
||||||
|
return -1;
|
||||||
|
} catch (const std::out_of_range&) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
return 1;
|
||||||
|
};
|
||||||
|
|
||||||
options.manual_options = {
|
options.manual_options = {
|
||||||
{"-s",
|
{"-s",
|
||||||
"--seed",
|
"--seed",
|
||||||
@ -1511,6 +1496,14 @@ struct SDGenerationParams {
|
|||||||
"--scm-policy",
|
"--scm-policy",
|
||||||
"SCM policy: 'dynamic' (default) or 'static'",
|
"SCM policy: 'dynamic' (default) or 'static'",
|
||||||
on_scm_policy_arg},
|
on_scm_policy_arg},
|
||||||
|
{"",
|
||||||
|
"--vae-tile-size",
|
||||||
|
"tile size for vae tiling, format [X]x[Y] (default: 32x32)",
|
||||||
|
on_tile_size_arg},
|
||||||
|
{"",
|
||||||
|
"--vae-relative-tile-size",
|
||||||
|
"relative tile size for vae tiling, format [X]x[Y], in fraction of image size if < 1, in number of tiles per dim if >=1 (overrides --vae-tile-size)",
|
||||||
|
on_relative_tile_size_arg},
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1946,6 +1939,13 @@ struct SDGenerationParams {
|
|||||||
<< " seed: " << seed << ",\n"
|
<< " seed: " << seed << ",\n"
|
||||||
<< " upscale_repeats: " << upscale_repeats << ",\n"
|
<< " upscale_repeats: " << upscale_repeats << ",\n"
|
||||||
<< " upscale_tile_size: " << upscale_tile_size << ",\n"
|
<< " upscale_tile_size: " << upscale_tile_size << ",\n"
|
||||||
|
<< " vae_tiling_params: { "
|
||||||
|
<< vae_tiling_params.enabled << ", "
|
||||||
|
<< vae_tiling_params.tile_size_x << ", "
|
||||||
|
<< vae_tiling_params.tile_size_y << ", "
|
||||||
|
<< vae_tiling_params.target_overlap << ", "
|
||||||
|
<< vae_tiling_params.rel_size_x << ", "
|
||||||
|
<< vae_tiling_params.rel_size_y << " },\n"
|
||||||
<< "}";
|
<< "}";
|
||||||
free(sample_params_str);
|
free(sample_params_str);
|
||||||
free(high_noise_sample_params_str);
|
free(high_noise_sample_params_str);
|
||||||
|
|||||||
@ -525,7 +525,7 @@ int main(int argc, const char** argv) {
|
|||||||
gen_params.pm_id_embed_path.c_str(),
|
gen_params.pm_id_embed_path.c_str(),
|
||||||
gen_params.pm_style_strength,
|
gen_params.pm_style_strength,
|
||||||
}, // pm_params
|
}, // pm_params
|
||||||
ctx_params.vae_tiling_params,
|
gen_params.vae_tiling_params,
|
||||||
gen_params.cache_params,
|
gen_params.cache_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -772,7 +772,7 @@ int main(int argc, const char** argv) {
|
|||||||
gen_params.pm_id_embed_path.c_str(),
|
gen_params.pm_id_embed_path.c_str(),
|
||||||
gen_params.pm_style_strength,
|
gen_params.pm_style_strength,
|
||||||
}, // pm_params
|
}, // pm_params
|
||||||
ctx_params.vae_tiling_params,
|
gen_params.vae_tiling_params,
|
||||||
gen_params.cache_params,
|
gen_params.cache_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -1088,7 +1088,7 @@ int main(int argc, const char** argv) {
|
|||||||
gen_params.pm_id_embed_path.c_str(),
|
gen_params.pm_id_embed_path.c_str(),
|
||||||
gen_params.pm_style_strength,
|
gen_params.pm_style_strength,
|
||||||
}, // pm_params
|
}, // pm_params
|
||||||
ctx_params.vae_tiling_params,
|
gen_params.vae_tiling_params,
|
||||||
gen_params.cache_params,
|
gen_params.cache_params,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user