mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-11-11 19:36:33 +00:00
refactor: split ggml extensions and move implementations to cpp files (#1945)
This commit is contained in:
1 parent
d8fb10c029
commit
31ab2b2e08
74 files changed
+4269
-3698
No files matched your search
@@ -1,7 +1,8 @@
|
||||
#ifndef __SD_MODEL_VAE_AUDIO_VAE_HPP__
|
||||
#define __SD_MODEL_VAE_AUDIO_VAE_HPP__
|
||||
|
||||
#include "core/ggml_extend.hpp"
|
||||
#include "core/ggml_runner.h"
|
||||
#include "core/util.h"
|
||||
|
||||
struct AudioVAERunner : public GGMLRunner {
|
||||
AudioVAERunner(ggml_backend_t backend,
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
#ifndef __SD_MODEL_VAE_AUTO_ENCODER_KL_HPP__
|
||||
#define __SD_MODEL_VAE_AUTO_ENCODER_KL_HPP__
|
||||
|
||||
#include <cinttypes>
|
||||
#include "core/ggml_tensor_utils.h"
|
||||
#include "model/vae/vae.hpp"
|
||||
|
||||
/*================================================== AutoEncoderKL ===================================================*/
|
||||
@@ -744,7 +746,7 @@ struct AutoEncoderKL : public VAE {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_graph(z, decode_graph);
|
||||
};
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), z.dim());
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), z.dim());
|
||||
}
|
||||
|
||||
sd::Tensor<float> gaussian_latent_sample(const sd::Tensor<float>& moments, std::shared_ptr<RNG> rng) {
|
||||
|
||||
@@ -825,9 +825,9 @@ namespace Hunyuan {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_graph(graph_input, decode_graph);
|
||||
};
|
||||
auto output = restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph,
|
||||
n_threads,
|
||||
false),
|
||||
auto output = restore_trailing_singleton_dims(GGMLRunner::compute(get_graph,
|
||||
n_threads,
|
||||
false),
|
||||
graph_input.dim());
|
||||
if (!output.empty() && input.dim() == 4) {
|
||||
output.squeeze_(2);
|
||||
|
||||
@@ -7,7 +7,12 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "core/ggml_extend.hpp"
|
||||
#include "core/ggml_extend.h"
|
||||
#include "core/ggml_extend_backend.h"
|
||||
#include "core/ggml_runner.h"
|
||||
#include "core/ggml_tensor_utils.h"
|
||||
#include "core/util.h"
|
||||
#include "model/common/ggml_block.hpp"
|
||||
#include "model/vae/audio_vae.hpp"
|
||||
#include "model_loader.h"
|
||||
#include "model_manager.h"
|
||||
@@ -1042,7 +1047,7 @@ namespace LTXV {
|
||||
ggml_build_forward_expand(gf, waveform);
|
||||
return gf;
|
||||
};
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), 4);
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), 4);
|
||||
int64_t t1 = ggml_time_ms();
|
||||
LOG_INFO("ltx audio vae decode completed, taking %.2fs", (t1 - t0) * 1.0f / 1000);
|
||||
return result;
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
#include <tuple>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include "core/ggml_extend_backend.h"
|
||||
#include "core/ggml_tensor_utils.h"
|
||||
|
||||
#include "model/diffusion/ltxv.hpp"
|
||||
#include "model/vae/vae.hpp"
|
||||
@@ -1348,7 +1350,7 @@ struct LTXVideoVAE : public VAE {
|
||||
static_cast<int>(tile.start),
|
||||
tile.overlap);
|
||||
};
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false),
|
||||
expected_dim);
|
||||
});
|
||||
|
||||
@@ -1405,7 +1407,7 @@ struct LTXVideoVAE : public VAE {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_graph(input, decode_graph);
|
||||
};
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), expected_dim);
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), expected_dim);
|
||||
if (result.empty()) {
|
||||
return {};
|
||||
}
|
||||
@@ -1418,7 +1420,7 @@ struct LTXVideoVAE : public VAE {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_latent_statistics_graph(z, normalize);
|
||||
};
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false),
|
||||
static_cast<size_t>(z.dim()));
|
||||
}
|
||||
|
||||
|
||||
@@ -490,7 +490,7 @@ namespace MageVAE {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_graph(input, decode_graph);
|
||||
};
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), input.dim());
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), input.dim());
|
||||
}
|
||||
|
||||
int get_encoder_output_channels(int input_channels) override {
|
||||
|
||||
@@ -480,7 +480,7 @@ namespace MiniMaxH3 {
|
||||
return graph;
|
||||
};
|
||||
auto result = restore_trailing_singleton_dims(
|
||||
GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
GGMLRunner::compute(get_graph, n_threads, false),
|
||||
4);
|
||||
int64_t t1 = ggml_time_ms();
|
||||
LOG_INFO("MiniMax-H3 audio VAE encode completed, taking %.2fs",
|
||||
@@ -500,7 +500,7 @@ namespace MiniMaxH3 {
|
||||
return graph;
|
||||
};
|
||||
auto result = restore_trailing_singleton_dims(
|
||||
GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
GGMLRunner::compute(get_graph, n_threads, false),
|
||||
4);
|
||||
int64_t t1 = ggml_time_ms();
|
||||
LOG_INFO("MiniMax-H3 audio VAE decode completed, taking %.2fs",
|
||||
|
||||
@@ -791,9 +791,9 @@ namespace MiniMaxH3VAE {
|
||||
return graph;
|
||||
};
|
||||
return restore_trailing_singleton_dims(
|
||||
GGMLRunner::compute<float>(get_graph,
|
||||
n_threads,
|
||||
false),
|
||||
GGMLRunner::compute(get_graph,
|
||||
n_threads,
|
||||
false),
|
||||
5);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
#ifndef __SD_MODEL_VAE_TAE_HPP__
|
||||
#define __SD_MODEL_VAE_TAE_HPP__
|
||||
|
||||
#include "core/ggml_extend.hpp"
|
||||
#include "core/ggml_extend.h"
|
||||
#include "core/ggml_runner.h"
|
||||
#include "core/rng.hpp"
|
||||
#include "core/util.h"
|
||||
#include "model.h"
|
||||
#include "model/common/ggml_block.hpp"
|
||||
|
||||
/*
|
||||
=================================== TinyAutoEncoder ===================================
|
||||
@@ -787,7 +791,7 @@ struct TinyImageAutoEncoder : public VAE {
|
||||
return build_graph(z_tensor, decode_graph);
|
||||
};
|
||||
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), z_tensor.dim());
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), z_tensor.dim());
|
||||
}
|
||||
};
|
||||
|
||||
@@ -872,7 +876,7 @@ struct TinyVideoAutoEncoder : public VAE {
|
||||
return build_graph(z_tensor, decode_graph);
|
||||
};
|
||||
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false), z_tensor.dim());
|
||||
return restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false), z_tensor.dim());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
#include "model/common/block.hpp"
|
||||
#include "model/vae/vae_tiling.hpp"
|
||||
#include "model_manager.h"
|
||||
#include "runtime/tiling.h"
|
||||
|
||||
struct VAE : public GGMLRunner {
|
||||
protected:
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
#include "core/ggml_extend_backend.h"
|
||||
#include "core/ggml_tensor_utils.h"
|
||||
|
||||
#include "model/common/block.hpp"
|
||||
#include "model/vae/vae.hpp"
|
||||
@@ -1427,7 +1429,7 @@ namespace WAN {
|
||||
return build_temporal_tile_graph(input_tile, static_cast<int>(tile.start));
|
||||
};
|
||||
return restore_trailing_singleton_dims(
|
||||
GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
GGMLRunner::compute(get_graph, n_threads, false),
|
||||
static_cast<size_t>(input.dim()));
|
||||
});
|
||||
|
||||
@@ -1446,7 +1448,7 @@ namespace WAN {
|
||||
auto get_graph = [&]() -> ggml_cgraph* {
|
||||
return build_graph(input.empty() ? z : input, decode_graph);
|
||||
};
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute<float>(get_graph, n_threads, false),
|
||||
auto result = restore_trailing_singleton_dims(GGMLRunner::compute(get_graph, n_threads, false),
|
||||
input.empty() ? z.dim() : input.dim());
|
||||
if (!result.empty() && z.dim() == 4) {
|
||||
result.squeeze_(2);
|
||||
|
||||
Reference in new issue
Block a user