mirror of
https://github.com/leejet/stable-diffusion.cpp.git
synced 2026-08-10 06:07:58 +00:00
format code
This commit is contained in:
parent
4aafb2981e
commit
dc431105b3
@ -397,7 +397,7 @@ namespace MiniMaxH3 {
|
|||||||
config.attention_head_dim,
|
config.attention_head_dim,
|
||||||
config.qk_norm_eps);
|
config.qk_norm_eps);
|
||||||
blocks["mlp"] = std::make_shared<MLP>(config.hidden_size,
|
blocks["mlp"] = std::make_shared<MLP>(config.hidden_size,
|
||||||
config.ffn_hidden_size);
|
config.ffn_hidden_size);
|
||||||
blocks["adaln_proj"] = std::make_shared<AdaLayerNormModulation>(config.time_embed_dim,
|
blocks["adaln_proj"] = std::make_shared<AdaLayerNormModulation>(config.time_embed_dim,
|
||||||
config.hidden_size,
|
config.hidden_size,
|
||||||
6,
|
6,
|
||||||
@ -561,7 +561,7 @@ namespace MiniMaxH3 {
|
|||||||
1);
|
1);
|
||||||
ggml_tensor* angles = nullptr;
|
ggml_tensor* angles = nullptr;
|
||||||
for (int axis = 0; axis < 3; ++axis) {
|
for (int axis = 0; axis < 3; ++axis) {
|
||||||
auto pos = ggml_ext_slice(ctx->ggml_ctx, position_ids, 0, axis, axis + 1);
|
auto pos = ggml_ext_slice(ctx->ggml_ctx, position_ids, 0, axis, axis + 1);
|
||||||
auto expanded_inv = ggml_repeat_4d(ctx->ggml_ctx,
|
auto expanded_inv = ggml_repeat_4d(ctx->ggml_ctx,
|
||||||
inv,
|
inv,
|
||||||
inv->ne[0],
|
inv->ne[0],
|
||||||
@ -569,7 +569,7 @@ namespace MiniMaxH3 {
|
|||||||
1,
|
1,
|
||||||
1);
|
1);
|
||||||
auto a = ggml_mul(ctx->ggml_ctx, expanded_inv, pos);
|
auto a = ggml_mul(ctx->ggml_ctx, expanded_inv, pos);
|
||||||
angles = angles == nullptr ? a : ggml_concat(ctx->ggml_ctx, angles, a, 0);
|
angles = angles == nullptr ? a : ggml_concat(ctx->ggml_ctx, angles, a, 0);
|
||||||
}
|
}
|
||||||
auto c = ggml_reshape_4d(ctx->ggml_ctx, ggml_cos(ctx->ggml_ctx, angles), 1, angles->ne[0], angles->ne[1], 1);
|
auto c = ggml_reshape_4d(ctx->ggml_ctx, ggml_cos(ctx->ggml_ctx, angles), 1, angles->ne[0], angles->ne[1], 1);
|
||||||
auto s = ggml_reshape_4d(ctx->ggml_ctx, ggml_sin(ctx->ggml_ctx, angles), 1, angles->ne[0], angles->ne[1], 1);
|
auto s = ggml_reshape_4d(ctx->ggml_ctx, ggml_sin(ctx->ggml_ctx, angles), 1, angles->ne[0], angles->ne[1], 1);
|
||||||
@ -756,17 +756,17 @@ namespace MiniMaxH3 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static PackedSequenceLayout build_layout(int64_t text_len,
|
static PackedSequenceLayout build_layout(int64_t text_len,
|
||||||
int64_t latent_t,
|
int64_t latent_t,
|
||||||
int64_t latent_h,
|
int64_t latent_h,
|
||||||
int64_t latent_w,
|
int64_t latent_w,
|
||||||
int64_t audio_t,
|
int64_t audio_t,
|
||||||
const std::vector<sd::Tensor<float>>& condition_videos,
|
const std::vector<sd::Tensor<float>>& condition_videos,
|
||||||
const std::vector<sd::Tensor<float>>& condition_audios,
|
const std::vector<sd::Tensor<float>>& condition_audios,
|
||||||
const sd::Tensor<int32_t>& keyframe_indices,
|
const sd::Tensor<int32_t>& keyframe_indices,
|
||||||
const std::vector<MiniMaxH3ReferenceBlock>& reference_blocks,
|
const std::vector<MiniMaxH3ReferenceBlock>& reference_blocks,
|
||||||
const sd::Tensor<int32_t>& text_tags,
|
const sd::Tensor<int32_t>& text_tags,
|
||||||
float video_t,
|
float video_t,
|
||||||
float audio_timestep) {
|
float audio_timestep) {
|
||||||
PackedSequenceLayout layout;
|
PackedSequenceLayout layout;
|
||||||
float sqrt_area = std::sqrt(static_cast<float>(latent_h * latent_w));
|
float sqrt_area = std::sqrt(static_cast<float>(latent_h * latent_w));
|
||||||
auto h_axis = spatial_axis(latent_h, sqrt_area);
|
auto h_axis = spatial_axis(latent_h, sqrt_area);
|
||||||
|
|||||||
@ -397,14 +397,14 @@ namespace MiniMaxH3 {
|
|||||||
ggml_mul(ctx->ggml_ctx, latent, std),
|
ggml_mul(ctx->ggml_ctx, latent, std),
|
||||||
mean);
|
mean);
|
||||||
|
|
||||||
auto dec_in = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["dec_in_proj"]);
|
auto dec_in = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["dec_in_proj"]);
|
||||||
auto decoder = std::dynamic_pointer_cast<BigVGAN>(blocks["decoder"]);
|
auto decoder = std::dynamic_pointer_cast<BigVGAN>(blocks["decoder"]);
|
||||||
int64_t streams = latent->ne[2] * latent->ne[3];
|
int64_t streams = latent->ne[2] * latent->ne[3];
|
||||||
latent = ggml_reshape_3d(ctx->ggml_ctx,
|
latent = ggml_reshape_3d(ctx->ggml_ctx,
|
||||||
latent,
|
latent,
|
||||||
latent->ne[0],
|
latent->ne[0],
|
||||||
latent->ne[1],
|
latent->ne[1],
|
||||||
streams);
|
streams);
|
||||||
ggml_tensor* waveform = nullptr;
|
ggml_tensor* waveform = nullptr;
|
||||||
for (int64_t stream = 0; stream < streams; ++stream) {
|
for (int64_t stream = 0; stream < streams; ++stream) {
|
||||||
auto stream_latent = ggml_ext_slice(ctx->ggml_ctx, latent, 2, stream, stream + 1);
|
auto stream_latent = ggml_ext_slice(ctx->ggml_ctx, latent, 2, stream, stream + 1);
|
||||||
|
|||||||
@ -86,14 +86,14 @@ namespace MiniMaxH3VAE {
|
|||||||
frame->ne[1],
|
frame->ne[1],
|
||||||
num_channels,
|
num_channels,
|
||||||
batch_size);
|
batch_size);
|
||||||
frame = GroupNorm::forward(ctx, frame);
|
frame = GroupNorm::forward(ctx, frame);
|
||||||
frame = ggml_reshape_4d(ctx->ggml_ctx,
|
frame = ggml_reshape_4d(ctx->ggml_ctx,
|
||||||
frame,
|
frame,
|
||||||
frame->ne[0],
|
frame->ne[0],
|
||||||
frame->ne[1],
|
frame->ne[1],
|
||||||
1,
|
1,
|
||||||
num_channels * batch_size);
|
num_channels * batch_size);
|
||||||
result = result == nullptr ? frame : ggml_concat(ctx->ggml_ctx, result, frame, 2);
|
result = result == nullptr ? frame : ggml_concat(ctx->ggml_ctx, result, frame, 2);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
@ -257,49 +257,49 @@ namespace MiniMaxH3VAE {
|
|||||||
ggml_tensor* forward(GGMLRunnerContext* ctx,
|
ggml_tensor* forward(GGMLRunnerContext* ctx,
|
||||||
ggml_tensor* x,
|
ggml_tensor* x,
|
||||||
ggml_tensor* pe) {
|
ggml_tensor* pe) {
|
||||||
auto to_qkv = std::dynamic_pointer_cast<Linear>(blocks["to_qkv"]);
|
auto to_qkv = std::dynamic_pointer_cast<Linear>(blocks["to_qkv"]);
|
||||||
auto to_out = std::dynamic_pointer_cast<Linear>(blocks["to_out"]);
|
auto to_out = std::dynamic_pointer_cast<Linear>(blocks["to_out"]);
|
||||||
auto qkv_projection = to_qkv->forward(ctx, x);
|
auto qkv_projection = to_qkv->forward(ctx, x);
|
||||||
int64_t sequence = x->ne[1];
|
int64_t sequence = x->ne[1];
|
||||||
int64_t batch_size = x->ne[2] * x->ne[3];
|
int64_t batch_size = x->ne[2] * x->ne[3];
|
||||||
qkv_projection = ggml_reshape_4d(ctx->ggml_ctx,
|
qkv_projection = ggml_reshape_4d(ctx->ggml_ctx,
|
||||||
qkv_projection,
|
qkv_projection,
|
||||||
3 * head_dim,
|
3 * head_dim,
|
||||||
num_head,
|
num_head,
|
||||||
sequence,
|
sequence,
|
||||||
batch_size);
|
batch_size);
|
||||||
auto qkv = ggml_ext_chunk(ctx->ggml_ctx, qkv_projection, 3, 0);
|
auto qkv = ggml_ext_chunk(ctx->ggml_ctx, qkv_projection, 3, 0);
|
||||||
auto q = ggml_reshape_4d(ctx->ggml_ctx,
|
auto q = ggml_reshape_4d(ctx->ggml_ctx,
|
||||||
qkv[0],
|
qkv[0],
|
||||||
head_dim,
|
head_dim,
|
||||||
num_head,
|
num_head,
|
||||||
sequence,
|
sequence,
|
||||||
batch_size);
|
batch_size);
|
||||||
auto k = ggml_reshape_4d(ctx->ggml_ctx,
|
auto k = ggml_reshape_4d(ctx->ggml_ctx,
|
||||||
qkv[1],
|
qkv[1],
|
||||||
head_dim,
|
head_dim,
|
||||||
num_head,
|
num_head,
|
||||||
sequence,
|
sequence,
|
||||||
batch_size);
|
batch_size);
|
||||||
auto v = ggml_reshape_4d(ctx->ggml_ctx,
|
auto v = ggml_reshape_4d(ctx->ggml_ctx,
|
||||||
qkv[2],
|
qkv[2],
|
||||||
head_dim,
|
head_dim,
|
||||||
num_head,
|
num_head,
|
||||||
sequence,
|
sequence,
|
||||||
batch_size);
|
batch_size);
|
||||||
q = ggml_rms_norm(ctx->ggml_ctx, q, 1e-5f);
|
q = ggml_rms_norm(ctx->ggml_ctx, q, 1e-5f);
|
||||||
k = ggml_rms_norm(ctx->ggml_ctx, k, 1e-5f);
|
k = ggml_rms_norm(ctx->ggml_ctx, k, 1e-5f);
|
||||||
q = apply_partial_rope(ctx->ggml_ctx, q, pe);
|
q = apply_partial_rope(ctx->ggml_ctx, q, pe);
|
||||||
k = apply_partial_rope(ctx->ggml_ctx, k, pe);
|
k = apply_partial_rope(ctx->ggml_ctx, k, pe);
|
||||||
auto out = ggml_ext_attention_ext(ctx->ggml_ctx,
|
auto out = ggml_ext_attention_ext(ctx->ggml_ctx,
|
||||||
ctx->backend,
|
ctx->backend,
|
||||||
q,
|
q,
|
||||||
k,
|
k,
|
||||||
v,
|
v,
|
||||||
num_head,
|
num_head,
|
||||||
nullptr,
|
nullptr,
|
||||||
true,
|
true,
|
||||||
ctx->flash_attn_enabled);
|
ctx->flash_attn_enabled);
|
||||||
return to_out->forward(ctx, out);
|
return to_out->forward(ctx, out);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user