style: format code
This commit is contained in:
parent
d08d7fa632
commit
c837c5d9cc
@ -10,8 +10,8 @@ struct SDCondition {
|
||||
struct ggml_tensor* c_concat = NULL;
|
||||
|
||||
SDCondition() = default;
|
||||
SDCondition(struct ggml_tensor* c_crossattn, struct ggml_tensor* c_vector, struct ggml_tensor* c_concat) :
|
||||
c_crossattn(c_crossattn), c_vector(c_vector), c_concat(c_concat) {}
|
||||
SDCondition(struct ggml_tensor* c_crossattn, struct ggml_tensor* c_vector, struct ggml_tensor* c_concat)
|
||||
: c_crossattn(c_crossattn), c_vector(c_vector), c_concat(c_concat) {}
|
||||
};
|
||||
|
||||
struct Conditioner {
|
||||
@ -978,7 +978,6 @@ struct SD3CLIPEmbedder : public Conditioner {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct FluxCLIPEmbedder : public Conditioner {
|
||||
ggml_type wtype;
|
||||
CLIPTokenizer clip_l_tokenizer;
|
||||
|
@ -351,7 +351,6 @@ struct DiscreteFlowDenoiser : public Denoiser {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
float flux_time_shift(float mu, float sigma, float t) {
|
||||
return std::exp(mu) / (std::exp(mu) + std::pow((1.0 / t - 1.0), sigma));
|
||||
}
|
||||
|
@ -1,9 +1,9 @@
|
||||
#ifndef __DIFFUSION_MODEL_H__
|
||||
#define __DIFFUSION_MODEL_H__
|
||||
|
||||
#include "flux.hpp"
|
||||
#include "mmdit.hpp"
|
||||
#include "unet.hpp"
|
||||
#include "flux.hpp"
|
||||
|
||||
struct DiffusionModel {
|
||||
virtual void compute(int n_threads,
|
||||
@ -124,7 +124,6 @@ struct MMDiTModel : public DiffusionModel {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct FluxModel : public DiffusionModel {
|
||||
Flux::FluxRunner flux;
|
||||
|
||||
|
26
flux.hpp
26
flux.hpp
@ -53,7 +53,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct QKNorm : public GGMLBlock {
|
||||
public:
|
||||
QKNorm(int64_t dim) {
|
||||
@ -146,7 +145,6 @@ public:
|
||||
auto qkv_proj = std::dynamic_pointer_cast<Linear>(blocks["qkv"]);
|
||||
auto norm = std::dynamic_pointer_cast<QKNorm>(blocks["norm"]);
|
||||
|
||||
|
||||
auto qkv = qkv_proj->forward(ctx, x);
|
||||
auto qkv_vec = split_qkv(ctx, qkv);
|
||||
int64_t head_dim = qkv_vec[0]->ne[0] / num_heads;
|
||||
@ -176,7 +174,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct ModulationOut {
|
||||
ggml_tensor* shift = NULL;
|
||||
ggml_tensor* scale = NULL;
|
||||
@ -190,8 +187,10 @@ struct Modulation : public GGMLBlock {
|
||||
public:
|
||||
bool is_double;
|
||||
int multiplier;
|
||||
|
||||
public:
|
||||
Modulation(int64_t dim, bool is_double): is_double(is_double) {
|
||||
Modulation(int64_t dim, bool is_double)
|
||||
: is_double(is_double) {
|
||||
multiplier = is_double ? 6 : 3;
|
||||
blocks["lin"] = std::shared_ptr<GGMLBlock>(new Linear(dim, dim * multiplier));
|
||||
}
|
||||
@ -289,7 +288,6 @@ public:
|
||||
auto txt_mlp_0 = std::dynamic_pointer_cast<Linear>(blocks["txt_mlp.0"]);
|
||||
auto txt_mlp_2 = std::dynamic_pointer_cast<Linear>(blocks["txt_mlp.2"]);
|
||||
|
||||
|
||||
auto img_mods = img_mod->forward(ctx, vec);
|
||||
ModulationOut img_mod1 = img_mods[0];
|
||||
ModulationOut img_mod2 = img_mods[1];
|
||||
@ -361,18 +359,18 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct SingleStreamBlock : public GGMLBlock {
|
||||
public:
|
||||
int64_t num_heads;
|
||||
int64_t hidden_size;
|
||||
int64_t mlp_hidden_dim;
|
||||
|
||||
public:
|
||||
SingleStreamBlock(int64_t hidden_size,
|
||||
int64_t num_heads,
|
||||
float mlp_ratio = 4.0f,
|
||||
float qk_scale = 0.f) :
|
||||
hidden_size(hidden_size), num_heads(num_heads) {
|
||||
float qk_scale = 0.f)
|
||||
: hidden_size(hidden_size), num_heads(num_heads) {
|
||||
int64_t head_dim = hidden_size / num_heads;
|
||||
float scale = qk_scale;
|
||||
if (scale <= 0.f) {
|
||||
@ -445,7 +443,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct LastLayer : public GGMLBlock {
|
||||
public:
|
||||
LastLayer(int64_t hidden_size,
|
||||
@ -497,7 +494,6 @@ struct FluxParams {
|
||||
bool guidance_embed = true;
|
||||
};
|
||||
|
||||
|
||||
struct Flux : public GGMLBlock {
|
||||
public:
|
||||
std::vector<float> linspace(float start, float end, int num) {
|
||||
@ -609,9 +605,9 @@ public:
|
||||
// std::cout << trans_ids[0][i] << " " << trans_ids[1][i] << " " << trans_ids[2][i] << std::endl;
|
||||
}
|
||||
|
||||
|
||||
int emb_dim = 0;
|
||||
for (int d : axes_dim) emb_dim += d / 2;
|
||||
for (int d : axes_dim)
|
||||
emb_dim += d / 2;
|
||||
|
||||
std::vector<std::vector<float>> emb(bs * pos_len, std::vector<float>(emb_dim * 2 * 2, 0.0));
|
||||
int offset = 0;
|
||||
@ -629,10 +625,12 @@ public:
|
||||
|
||||
return flatten(emb);
|
||||
}
|
||||
|
||||
public:
|
||||
FluxParams params;
|
||||
Flux() {}
|
||||
Flux(FluxParams params) : params(params) {
|
||||
Flux(FluxParams params)
|
||||
: params(params) {
|
||||
int64_t out_channels = params.in_channels;
|
||||
int64_t pe_dim = params.hidden_size / params.num_heads;
|
||||
|
||||
@ -802,7 +800,6 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct FluxRunner : public GGMLRunner {
|
||||
public:
|
||||
FluxParams flux_params;
|
||||
@ -853,7 +850,6 @@ public:
|
||||
// pe->data = NULL;
|
||||
set_backend_tensor_data(pe, pe_vec.data());
|
||||
|
||||
|
||||
struct ggml_tensor* out = flux.forward(compute_ctx,
|
||||
x,
|
||||
timesteps,
|
||||
|
@ -1427,7 +1427,6 @@ ggml_type ModelLoader::get_conditioner_wtype() {
|
||||
return GGML_TYPE_COUNT;
|
||||
}
|
||||
|
||||
|
||||
ggml_type ModelLoader::get_diffusion_model_wtype() {
|
||||
for (auto& tensor_storage : tensor_storages) {
|
||||
if (is_unused_tensor(tensor_storage.name)) {
|
||||
|
@ -74,7 +74,6 @@ public:
|
||||
ggml_type diffusion_model_wtype = GGML_TYPE_COUNT;
|
||||
ggml_type vae_wtype = GGML_TYPE_COUNT;
|
||||
|
||||
|
||||
SDVersion version;
|
||||
bool vae_decode_only = false;
|
||||
bool free_params_immediately = false;
|
||||
|
Loading…
Reference in New Issue
Block a user