🌐 AI搜索 & 代理 主页
Skip to content

Commit 7c3dd7e

Browse files
committed
use actual scheduler sigmas for ucache bounds
1 parent bbe73be commit 7c3dd7e

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

stable-diffusion.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,6 +1558,10 @@ class StableDiffusionGGML {
15581558
}
15591559
}
15601560

1561+
if (ucache_enabled) {
1562+
ucache_state.set_sigmas(sigmas);
1563+
}
1564+
15611565
size_t steps = sigmas.size() - 1;
15621566
struct ggml_tensor* x = ggml_dup_tensor(work_ctx, init_latent);
15631567
copy_ggml_tensor(x, init_latent);

ucache.hpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,26 @@ struct UCacheState {
126126
}
127127
}
128128

129+
void set_sigmas(const std::vector<float>& sigmas) {
130+
if (!initialized || sigmas.size() < 2) {
131+
return;
132+
}
133+
size_t n_steps = sigmas.size() - 1;
134+
135+
size_t start_step = static_cast<size_t>(config.start_percent * n_steps);
136+
size_t end_step = static_cast<size_t>(config.end_percent * n_steps);
137+
138+
if (start_step >= n_steps) start_step = n_steps - 1;
139+
if (end_step >= n_steps) end_step = n_steps - 1;
140+
141+
start_sigma = sigmas[start_step];
142+
end_sigma = sigmas[end_step];
143+
144+
if (start_sigma < end_sigma) {
145+
std::swap(start_sigma, end_sigma);
146+
}
147+
}
148+
129149
bool enabled() const {
130150
return initialized && config.enabled;
131151
}

0 commit comments

Comments
 (0)