Skip to content

Commit 1c702e1

Browse files
committed
refactor: remove DDIM standalone implementation
It is equivalent to Euler Ancestral with the Simple scheduler.
1 parent 51c5fb8 commit 1c702e1

1 file changed

Lines changed: 2 additions & 31 deletions

File tree

src/denoiser.hpp

Lines changed: 2 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,36 +1501,6 @@ static sd::Tensor<float> sample_er_sde(denoise_cb_t model,
15011501
return x;
15021502
}
15031503

1504-
static sd::Tensor<float> sample_ddim_trailing(denoise_cb_t model,
1505-
sd::Tensor<float> x,
1506-
const std::vector<float>& sigmas,
1507-
std::shared_ptr<RNG> rng,
1508-
float eta) {
1509-
int steps = static_cast<int>(sigmas.size()) - 1;
1510-
for (int i = 0; i < steps; i++) {
1511-
float sigma = sigmas[i];
1512-
float sigma_to = sigmas[i + 1];
1513-
1514-
auto denoised_opt = model(x, sigma, i + 1);
1515-
if (denoised_opt.empty()) {
1516-
return {};
1517-
}
1518-
sd::Tensor<float> denoised = std::move(denoised_opt);
1519-
sd::Tensor<float> d = (x - denoised) / sigma;
1520-
if (eta == 0.f) {
1521-
x += d * (sigma_to - sigma);
1522-
} else {
1523-
auto [sigma_down, sigma_up] = get_ancestral_step(sigma, sigma_to, eta);
1524-
float sigma_ratio = sigma_down / sigma;
1525-
x = sigma_ratio * x + (1.0f - sigma_ratio) * denoised;
1526-
if (sigma_up > 0.f) {
1527-
x += sd::Tensor<float>::randn_like(x, rng) * sigma_up;
1528-
}
1529-
}
1530-
}
1531-
return x;
1532-
}
1533-
15341504
static sd::Tensor<float> sample_tcd(denoise_cb_t model,
15351505
sd::Tensor<float> x,
15361506
const std::vector<float>& sigmas,
@@ -1636,7 +1606,8 @@ static sd::Tensor<float> sample_k_diffusion(sample_method_t method,
16361606
case ER_SDE_SAMPLE_METHOD:
16371607
return sample_er_sde(model, std::move(x), sigmas, rng, is_flow_denoiser, eta);
16381608
case DDIM_TRAILING_SAMPLE_METHOD:
1639-
return sample_ddim_trailing(model, std::move(x), sigmas, rng, eta);
1609+
// DDIM is equivalent to Euler Ancestral with the Simple scheduler
1610+
return sample_euler_ancestral(model, std::move(x), sigmas, rng, is_flow_denoiser, eta);
16401611
case TCD_SAMPLE_METHOD:
16411612
return sample_tcd(model, std::move(x), sigmas, rng, eta);
16421613
default:

0 commit comments

Comments
 (0)