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.qk_norm_eps);
|
||||
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,
|
||||
config.hidden_size,
|
||||
6,
|
||||
@ -561,7 +561,7 @@ namespace MiniMaxH3 {
|
||||
1);
|
||||
ggml_tensor* angles = nullptr;
|
||||
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,
|
||||
inv,
|
||||
inv->ne[0],
|
||||
@ -569,7 +569,7 @@ namespace MiniMaxH3 {
|
||||
1,
|
||||
1);
|
||||
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 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,
|
||||
int64_t latent_t,
|
||||
int64_t latent_h,
|
||||
int64_t latent_w,
|
||||
int64_t audio_t,
|
||||
const std::vector<sd::Tensor<float>>& condition_videos,
|
||||
const std::vector<sd::Tensor<float>>& condition_audios,
|
||||
const sd::Tensor<int32_t>& keyframe_indices,
|
||||
const std::vector<MiniMaxH3ReferenceBlock>& reference_blocks,
|
||||
const sd::Tensor<int32_t>& text_tags,
|
||||
float video_t,
|
||||
float audio_timestep) {
|
||||
int64_t latent_t,
|
||||
int64_t latent_h,
|
||||
int64_t latent_w,
|
||||
int64_t audio_t,
|
||||
const std::vector<sd::Tensor<float>>& condition_videos,
|
||||
const std::vector<sd::Tensor<float>>& condition_audios,
|
||||
const sd::Tensor<int32_t>& keyframe_indices,
|
||||
const std::vector<MiniMaxH3ReferenceBlock>& reference_blocks,
|
||||
const sd::Tensor<int32_t>& text_tags,
|
||||
float video_t,
|
||||
float audio_timestep) {
|
||||
PackedSequenceLayout layout;
|
||||
float sqrt_area = std::sqrt(static_cast<float>(latent_h * latent_w));
|
||||
auto h_axis = spatial_axis(latent_h, sqrt_area);
|
||||
|
||||
@ -397,14 +397,14 @@ namespace MiniMaxH3 {
|
||||
ggml_mul(ctx->ggml_ctx, latent, std),
|
||||
mean);
|
||||
|
||||
auto dec_in = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["dec_in_proj"]);
|
||||
auto decoder = std::dynamic_pointer_cast<BigVGAN>(blocks["decoder"]);
|
||||
int64_t streams = latent->ne[2] * latent->ne[3];
|
||||
latent = ggml_reshape_3d(ctx->ggml_ctx,
|
||||
latent,
|
||||
latent->ne[0],
|
||||
latent->ne[1],
|
||||
streams);
|
||||
auto dec_in = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["dec_in_proj"]);
|
||||
auto decoder = std::dynamic_pointer_cast<BigVGAN>(blocks["decoder"]);
|
||||
int64_t streams = latent->ne[2] * latent->ne[3];
|
||||
latent = ggml_reshape_3d(ctx->ggml_ctx,
|
||||
latent,
|
||||
latent->ne[0],
|
||||
latent->ne[1],
|
||||
streams);
|
||||
ggml_tensor* waveform = nullptr;
|
||||
for (int64_t stream = 0; stream < streams; ++stream) {
|
||||
auto stream_latent = ggml_ext_slice(ctx->ggml_ctx, latent, 2, stream, stream + 1);
|
||||
|
||||
@ -86,14 +86,14 @@ namespace MiniMaxH3VAE {
|
||||
frame->ne[1],
|
||||
num_channels,
|
||||
batch_size);
|
||||
frame = GroupNorm::forward(ctx, frame);
|
||||
frame = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
frame,
|
||||
frame->ne[0],
|
||||
frame->ne[1],
|
||||
1,
|
||||
num_channels * batch_size);
|
||||
result = result == nullptr ? frame : ggml_concat(ctx->ggml_ctx, result, frame, 2);
|
||||
frame = GroupNorm::forward(ctx, frame);
|
||||
frame = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
frame,
|
||||
frame->ne[0],
|
||||
frame->ne[1],
|
||||
1,
|
||||
num_channels * batch_size);
|
||||
result = result == nullptr ? frame : ggml_concat(ctx->ggml_ctx, result, frame, 2);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -257,49 +257,49 @@ namespace MiniMaxH3VAE {
|
||||
ggml_tensor* forward(GGMLRunnerContext* ctx,
|
||||
ggml_tensor* x,
|
||||
ggml_tensor* pe) {
|
||||
auto to_qkv = std::dynamic_pointer_cast<Linear>(blocks["to_qkv"]);
|
||||
auto to_out = std::dynamic_pointer_cast<Linear>(blocks["to_out"]);
|
||||
auto to_qkv = std::dynamic_pointer_cast<Linear>(blocks["to_qkv"]);
|
||||
auto to_out = std::dynamic_pointer_cast<Linear>(blocks["to_out"]);
|
||||
auto qkv_projection = to_qkv->forward(ctx, x);
|
||||
int64_t sequence = x->ne[1];
|
||||
int64_t batch_size = x->ne[2] * x->ne[3];
|
||||
qkv_projection = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv_projection,
|
||||
3 * head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto qkv = ggml_ext_chunk(ctx->ggml_ctx, qkv_projection, 3, 0);
|
||||
auto q = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[0],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto k = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[1],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto v = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[2],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
q = ggml_rms_norm(ctx->ggml_ctx, q, 1e-5f);
|
||||
k = ggml_rms_norm(ctx->ggml_ctx, k, 1e-5f);
|
||||
q = apply_partial_rope(ctx->ggml_ctx, q, pe);
|
||||
k = apply_partial_rope(ctx->ggml_ctx, k, pe);
|
||||
auto out = ggml_ext_attention_ext(ctx->ggml_ctx,
|
||||
ctx->backend,
|
||||
q,
|
||||
k,
|
||||
v,
|
||||
num_head,
|
||||
nullptr,
|
||||
true,
|
||||
ctx->flash_attn_enabled);
|
||||
int64_t sequence = x->ne[1];
|
||||
int64_t batch_size = x->ne[2] * x->ne[3];
|
||||
qkv_projection = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv_projection,
|
||||
3 * head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto qkv = ggml_ext_chunk(ctx->ggml_ctx, qkv_projection, 3, 0);
|
||||
auto q = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[0],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto k = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[1],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
auto v = ggml_reshape_4d(ctx->ggml_ctx,
|
||||
qkv[2],
|
||||
head_dim,
|
||||
num_head,
|
||||
sequence,
|
||||
batch_size);
|
||||
q = ggml_rms_norm(ctx->ggml_ctx, q, 1e-5f);
|
||||
k = ggml_rms_norm(ctx->ggml_ctx, k, 1e-5f);
|
||||
q = apply_partial_rope(ctx->ggml_ctx, q, pe);
|
||||
k = apply_partial_rope(ctx->ggml_ctx, k, pe);
|
||||
auto out = ggml_ext_attention_ext(ctx->ggml_ctx,
|
||||
ctx->backend,
|
||||
q,
|
||||
k,
|
||||
v,
|
||||
num_head,
|
||||
nullptr,
|
||||
true,
|
||||
ctx->flash_attn_enabled);
|
||||
return to_out->forward(ctx, out);
|
||||
}
|
||||
};
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user