mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-10-02 19:07:55 -05:00
feat: add Ming-Image Design support (#2063)
This commit is contained in:
@@ -1369,6 +1369,42 @@ struct DiscreteFlowDenoiser : public Denoiser {
|
||||
}
|
||||
};
|
||||
|
||||
struct MingImageFlowDenoiser : DiscreteFlowDenoiser {
|
||||
float resolution_shift = std::exp(1.35f);
|
||||
|
||||
MingImageFlowDenoiser()
|
||||
: DiscreteFlowDenoiser(INFINITY) {}
|
||||
|
||||
float sigma_min() override { return 0.f; }
|
||||
float sigma_max() override { return 1.f; }
|
||||
|
||||
float t_to_sigma(float t) override {
|
||||
return time_snr_shift(std::isfinite(shift) ? shift : resolution_shift, (t + 1.f) / 1000.f);
|
||||
}
|
||||
|
||||
std::vector<float> get_sigmas(uint32_t n, int image_seq_len, scheduler_t scheduler, SDVersion version, const char* extra_sample_args = nullptr) override {
|
||||
const float tokens = static_cast<float>(image_seq_len) / 4.f;
|
||||
const float mu = tokens >= 4096.f ? 1.35f : 0.5f + (tokens - 256.f) * (1.15f - 0.5f) / (4096.f - 256.f);
|
||||
resolution_shift = std::exp(mu);
|
||||
if (scheduler != DISCRETE_SCHEDULER) {
|
||||
return DiscreteFlowDenoiser::get_sigmas(n, image_seq_len, scheduler, version, extra_sample_args);
|
||||
}
|
||||
if (n == 0) {
|
||||
return {};
|
||||
}
|
||||
const float factor = std::isfinite(shift) ? shift : resolution_shift;
|
||||
std::vector<float> sigmas;
|
||||
sigmas.reserve(n + 1);
|
||||
for (uint32_t i = 0; i < n; ++i) {
|
||||
const float t = n == 1 ? 1.f : 1.f - static_cast<float>(i) / static_cast<float>(n - 1);
|
||||
sigmas.push_back(time_snr_shift(factor, t));
|
||||
}
|
||||
// Upstream sets sigma_min to zero before linspace, then appends the terminal zero.
|
||||
sigmas.push_back(0.f);
|
||||
return sigmas;
|
||||
}
|
||||
};
|
||||
|
||||
struct H3AVFlowDenoiser : public DiscreteFlowDenoiser {
|
||||
int64_t video_channels;
|
||||
float audio_shift;
|
||||
@@ -1783,7 +1819,10 @@ static sd::Tensor<float> sample_euler(denoise_cb_t model,
|
||||
const std::vector<float>& sigmas) {
|
||||
int steps = static_cast<int>(sigmas.size()) - 1;
|
||||
for (int i = 0; i < steps; i++) {
|
||||
float sigma = sigmas[i];
|
||||
float sigma = sigmas[i];
|
||||
if (sigma == sigmas[i + 1]) {
|
||||
continue;
|
||||
}
|
||||
auto denoised_opt = model(x, sigma, i + 1);
|
||||
if (denoised_opt.pred.empty()) {
|
||||
return {};
|
||||
|
||||
Reference in New Issue
Block a user