mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-09-24 20:20:37 +00:00
fix: avoid narrowing conversion in SigVQ patch embedding and format code
This commit is contained in:
parent
187b2561ea
commit
b56c68617d
@ -193,16 +193,16 @@ namespace Qwen {
|
|||||||
class QwenImage21TransformerBlock : public GGMLBlock {
|
class QwenImage21TransformerBlock : public GGMLBlock {
|
||||||
public:
|
public:
|
||||||
QwenImage21TransformerBlock(const QwenImage21Config& config) {
|
QwenImage21TransformerBlock(const QwenImage21Config& config) {
|
||||||
blocks["img_norm1"] = std::make_shared<LayerNorm>(config.hidden_size, 1e-6f, false);
|
blocks["img_norm1"] = std::make_shared<LayerNorm>(config.hidden_size, 1e-6f, false);
|
||||||
blocks["img_norm2"] = std::make_shared<LayerNorm>(config.hidden_size, 1e-6f, false);
|
blocks["img_norm2"] = std::make_shared<LayerNorm>(config.hidden_size, 1e-6f, false);
|
||||||
blocks["attn"] = std::make_shared<QwenImage21Attention>(config);
|
blocks["attn"] = std::make_shared<QwenImage21Attention>(config);
|
||||||
if (config.fused_mlp) {
|
if (config.fused_mlp) {
|
||||||
blocks["img_mlp.gate_up"] = std::make_shared<Linear>(config.hidden_size, 2 * config.intermediate_size, false);
|
blocks["img_mlp.gate_up"] = std::make_shared<Linear>(config.hidden_size, 2 * config.intermediate_size, false);
|
||||||
} else {
|
} else {
|
||||||
blocks["img_mlp.proj"] = std::make_shared<Linear>(config.hidden_size, config.intermediate_size, false);
|
blocks["img_mlp.proj"] = std::make_shared<Linear>(config.hidden_size, config.intermediate_size, false);
|
||||||
blocks["img_mlp.gate_layer"] = std::make_shared<Linear>(config.hidden_size, config.intermediate_size, false);
|
blocks["img_mlp.gate_layer"] = std::make_shared<Linear>(config.hidden_size, config.intermediate_size, false);
|
||||||
}
|
}
|
||||||
blocks["img_mlp.out"] = std::make_shared<Linear>(config.intermediate_size, config.hidden_size, false);
|
blocks["img_mlp.out"] = std::make_shared<Linear>(config.intermediate_size, config.hidden_size, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
static ggml_tensor* modulate(ggml_context* ctx, ggml_tensor* x, ggml_tensor* params, int64_t prefix_length, bool gate = false) {
|
static ggml_tensor* modulate(ggml_context* ctx, ggml_tensor* x, ggml_tensor* params, int64_t prefix_length, bool gate = false) {
|
||||||
@ -220,12 +220,12 @@ namespace Qwen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ggml_tensor* forward(GGMLRunnerContext* ctx, ggml_tensor* x, const std::vector<ggml_tensor*>& modulation, ggml_tensor* pe, const QwenImage21Layout& layout, const std::vector<ggml_tensor*>& masks) {
|
ggml_tensor* forward(GGMLRunnerContext* ctx, ggml_tensor* x, const std::vector<ggml_tensor*>& modulation, ggml_tensor* pe, const QwenImage21Layout& layout, const std::vector<ggml_tensor*>& masks) {
|
||||||
auto h = std::dynamic_pointer_cast<LayerNorm>(blocks["img_norm1"])->forward(ctx, x);
|
auto h = std::dynamic_pointer_cast<LayerNorm>(blocks["img_norm1"])->forward(ctx, x);
|
||||||
h = modulate(ctx->ggml_ctx, h, modulation[0], layout.prefix_length);
|
h = modulate(ctx->ggml_ctx, h, modulation[0], layout.prefix_length);
|
||||||
h = std::dynamic_pointer_cast<QwenImage21Attention>(blocks["attn"])->forward(ctx, h, pe, layout.segments, masks);
|
h = std::dynamic_pointer_cast<QwenImage21Attention>(blocks["attn"])->forward(ctx, h, pe, layout.segments, masks);
|
||||||
x = ggml_add(ctx->ggml_ctx, x, modulate(ctx->ggml_ctx, h, modulation[1], layout.prefix_length, true));
|
x = ggml_add(ctx->ggml_ctx, x, modulate(ctx->ggml_ctx, h, modulation[1], layout.prefix_length, true));
|
||||||
h = std::dynamic_pointer_cast<LayerNorm>(blocks["img_norm2"])->forward(ctx, x);
|
h = std::dynamic_pointer_cast<LayerNorm>(blocks["img_norm2"])->forward(ctx, x);
|
||||||
h = modulate(ctx->ggml_ctx, h, modulation[2], layout.prefix_length);
|
h = modulate(ctx->ggml_ctx, h, modulation[2], layout.prefix_length);
|
||||||
ggml_tensor* gate;
|
ggml_tensor* gate;
|
||||||
auto fused = blocks.find("img_mlp.gate_up");
|
auto fused = blocks.find("img_mlp.gate_up");
|
||||||
if (fused != blocks.end()) {
|
if (fused != blocks.end()) {
|
||||||
@ -237,8 +237,8 @@ namespace Qwen {
|
|||||||
gate = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.gate_layer"])->forward(ctx, h);
|
gate = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.gate_layer"])->forward(ctx, h);
|
||||||
h = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.proj"])->forward(ctx, h);
|
h = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.proj"])->forward(ctx, h);
|
||||||
}
|
}
|
||||||
h = ggml_mul(ctx->ggml_ctx, h, ggml_silu(ctx->ggml_ctx, gate));
|
h = ggml_mul(ctx->ggml_ctx, h, ggml_silu(ctx->ggml_ctx, gate));
|
||||||
h = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.out"])->forward(ctx, h);
|
h = std::dynamic_pointer_cast<Linear>(blocks["img_mlp.out"])->forward(ctx, h);
|
||||||
return ggml_add(ctx->ggml_ctx, x, modulate(ctx->ggml_ctx, h, modulation[3], layout.prefix_length, true));
|
return ggml_add(ctx->ggml_ctx, x, modulate(ctx->ggml_ctx, h, modulation[3], layout.prefix_length, true));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@ -265,7 +265,7 @@ namespace LLaDAImageTE {
|
|||||||
|
|
||||||
struct SigVQConfig {
|
struct SigVQConfig {
|
||||||
int64_t image_size = 2048;
|
int64_t image_size = 2048;
|
||||||
int64_t patch_size = 16;
|
int patch_size = 16;
|
||||||
int64_t in_channels = 3;
|
int64_t in_channels = 3;
|
||||||
int64_t hidden_size = 1536;
|
int64_t hidden_size = 1536;
|
||||||
int64_t intermediate_size = 6144;
|
int64_t intermediate_size = 6144;
|
||||||
|
|||||||
@ -1070,11 +1070,11 @@ namespace WAN {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (version == VERSION_QWEN_IMAGE_2_1) {
|
if (version == VERSION_QWEN_IMAGE_2_1) {
|
||||||
wan2_2 = true;
|
wan2_2 = true;
|
||||||
dec_dim = 144;
|
dec_dim = 144;
|
||||||
z_dim = 64;
|
z_dim = 64;
|
||||||
input_channels = 4;
|
input_channels = 4;
|
||||||
dim_mult = {1, 2, 4, 8, 8};
|
dim_mult = {1, 2, 4, 8, 8};
|
||||||
}
|
}
|
||||||
|
|
||||||
if (is_2D) {
|
if (is_2D) {
|
||||||
|
|||||||
@ -147,7 +147,7 @@ bool ModelLoader::add_file_impl(const std::string& path, const std::string& pref
|
|||||||
}
|
}
|
||||||
if (tensor.index_in_zip < 0) {
|
if (tensor.index_in_zip < 0) {
|
||||||
const auto& stamp = physical_files[tensor.file_index];
|
const auto& stamp = physical_files[tensor.file_index];
|
||||||
if (tensor.offset > stamp.size || static_cast<uint64_t>(tensor.nbytes_to_read()) > stamp.size - tensor.offset) { //kcpp int8 fp8
|
if (tensor.offset > stamp.size || static_cast<uint64_t>(tensor.nbytes_to_read()) > stamp.size - tensor.offset) { // kcpp int8 fp8
|
||||||
LOG_ERROR("tensor '%s' extends beyond its model file", tensor.name.c_str());
|
LOG_ERROR("tensor '%s' extends beyond its model file", tensor.name.c_str());
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user