mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 11:26:34 +00:00
feat: return generation metadata with core results (#2206)
This commit is contained in:
1 parent
b29cad540a
commit
a85db96aa5
37 files changed
+1528
-758
No files matched your search
+33
-9
@@ -1,4 +1,5 @@
|
||||
#include "generation.h"
|
||||
#include "generation_info.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cmath>
|
||||
@@ -1575,7 +1576,13 @@ namespace sd::pipeline {
|
||||
img_gen_params.ref_image_args = sd_vid_gen_params->ref_image_args;
|
||||
|
||||
sd->animatediff_num_frames = n_frames;
|
||||
bool ok = generate_image(sd, &img_gen_params, frames_out, num_frames_out);
|
||||
bool ok = false;
|
||||
try {
|
||||
ok = generate_image(sd, &img_gen_params, frames_out, num_frames_out);
|
||||
} catch (...) {
|
||||
sd->animatediff_num_frames = 0;
|
||||
throw;
|
||||
}
|
||||
sd->animatediff_num_frames = 0;
|
||||
return ok;
|
||||
}
|
||||
@@ -1585,14 +1592,24 @@ namespace sd::pipeline {
|
||||
sd_image_t** frames_out,
|
||||
int* num_frames_out,
|
||||
sd_audio_t** audio_out,
|
||||
int* fps_out) {
|
||||
int* fps_out,
|
||||
nlohmann::json* info_out) {
|
||||
if (info_out)
|
||||
*info_out = nlohmann::json();
|
||||
GenerationRequest request(sd, sd_vid_gen_params);
|
||||
const auto info = sd::generation_info(request, *sd_vid_gen_params);
|
||||
if (sd->config_->animatediff_loaded && sd_version_supports_animatediff(sd->version)) {
|
||||
LOG_INFO("AnimateDiff dispatch: %d frames, %dx%d",
|
||||
sd_vid_gen_params->video_frames, sd_vid_gen_params->width, sd_vid_gen_params->height);
|
||||
if (fps_out != nullptr) {
|
||||
*fps_out = std::max(1, sd_vid_gen_params->fps);
|
||||
}
|
||||
return generate_animatediff_video(sd, sd_vid_gen_params, frames_out, num_frames_out);
|
||||
auto params = *sd_vid_gen_params;
|
||||
params.seed = request.seed;
|
||||
const bool ok = generate_animatediff_video(sd, ¶ms, frames_out, num_frames_out);
|
||||
if (ok && info_out)
|
||||
*info_out = info;
|
||||
return ok;
|
||||
}
|
||||
|
||||
sd->reset_cancel_flag();
|
||||
@@ -1602,7 +1619,6 @@ namespace sd::pipeline {
|
||||
int64_t t0 = ggml_time_ms();
|
||||
sd->vae_tiling_params = sd_vid_gen_params->vae_tiling_params;
|
||||
sd->apply_circular_axes(sd_vid_gen_params->circular_x, sd_vid_gen_params->circular_y);
|
||||
GenerationRequest request(sd, sd_vid_gen_params);
|
||||
sd::ImagePreprocessor preprocessing(sd_vid_gen_params->image_preprocess.rules);
|
||||
sd_vid_gen_params_t processed_params = *sd_vid_gen_params;
|
||||
if (!preprocessing.prepare_inputs(processed_params, request.width, request.height))
|
||||
@@ -1734,9 +1750,9 @@ namespace sd::pipeline {
|
||||
embeds.img_uncond,
|
||||
sd::Tensor<float>(),
|
||||
0.f,
|
||||
sd_vid_gen_params->sample_params.guidance,
|
||||
request.guidance,
|
||||
plan.eta,
|
||||
sd_vid_gen_params->sample_params.shifted_timestep,
|
||||
request.shifted_timestep,
|
||||
plan.sample_method,
|
||||
sd->is_flow_denoiser(),
|
||||
plan.extra_sample_args,
|
||||
@@ -1846,7 +1862,7 @@ namespace sd::pipeline {
|
||||
std::vector<float> hires_sigma_sched =
|
||||
make_hires_sigma_schedule(sd,
|
||||
request.hires,
|
||||
sd_vid_gen_params->sample_params,
|
||||
request.sample_params,
|
||||
hires_sample_method,
|
||||
plan.sample_steps,
|
||||
sd->get_image_seq_len(hires_request.height, hires_request.width) * T,
|
||||
@@ -1873,9 +1889,9 @@ namespace sd::pipeline {
|
||||
embeds.img_uncond,
|
||||
sd::Tensor<float>(),
|
||||
0.f,
|
||||
sd_vid_gen_params->sample_params.guidance,
|
||||
request.guidance,
|
||||
hires_eta,
|
||||
sd_vid_gen_params->sample_params.shifted_timestep,
|
||||
request.shifted_timestep,
|
||||
hires_sample_method,
|
||||
sd->is_flow_denoiser(),
|
||||
plan.extra_sample_args,
|
||||
@@ -2007,6 +2023,14 @@ namespace sd::pipeline {
|
||||
generated_audio->sample_count = want_samples;
|
||||
}
|
||||
}
|
||||
if (info_out) {
|
||||
try {
|
||||
*info_out = info;
|
||||
} catch (...) {
|
||||
free_sd_audio(generated_audio);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
if (audio_out != nullptr) {
|
||||
*audio_out = generated_audio;
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user