chore: sync ggml and remove obsolete conv1d workarounds (#2147)

This commit is contained in:
leejet authored and GitHub committed 2026-10-17 02:39:51 +08:00
1 parent 2f016e8e30
commit af0fc72c96
4 files changed
+19 -37

No files matched your search

+1 -1
Submodule ggml updated: d25b121ce1...dc998771e7.
+8 -15
View File
@@ -344,22 +344,15 @@ ggml_tensor* ggml_ext_pad(ggml_context* ctx,
} }
static ggml_tensor* conv_1d(ggml_context* ctx, ggml_tensor* x, ggml_tensor* w, int s0, int p0, int d0, bool force_prec_f32) { static ggml_tensor* conv_1d(ggml_context* ctx, ggml_tensor* x, ggml_tensor* w, int s0, int p0, int d0, bool force_prec_f32) {
ggml_tensor* result; if (!force_prec_f32) {
if (force_prec_f32) { return ggml_conv_1d(ctx, w, x, s0, p0, d0);
ggml_tensor* patches = ggml_im2col(ctx, w, x, s0, 0, p0, 0, d0, 0, false, GGML_TYPE_F32);
result = ggml_mul_mat(ctx,
ggml_reshape_2d(ctx, patches, patches->ne[0], patches->ne[2] * patches->ne[1]),
ggml_reshape_2d(ctx, w, w->ne[0] * w->ne[1], w->ne[2]));
result = ggml_reshape_3d(ctx, result, patches->ne[1], w->ne[2], patches->ne[2]);
} else {
result = ggml_conv_1d(ctx, w, x, s0, p0, d0);
} }
if (x->ne[2] > 1) { ggml_tensor* patches = ggml_im2col(ctx, w, x, s0, 0, p0, 0, d0, 0, false, GGML_TYPE_F32);
// mul_mat packs positions and batches before output channels: [OL, N, OC]. ggml_tensor* result = ggml_mul_mat(ctx,
result = ggml_reshape_3d(ctx, result, result->ne[0], x->ne[2], w->ne[2]); ggml_reshape_2d(ctx, patches, patches->ne[0], patches->ne[2] * patches->ne[1]),
result = ggml_cont(ctx, ggml_permute(ctx, result, 0, 2, 1, 3)); ggml_reshape_2d(ctx, w, w->ne[0] * w->ne[1], w->ne[2]));
} result = ggml_reshape_3d(ctx, result, patches->ne[1], patches->ne[2], w->ne[2]);
return result; return ggml_cont(ctx, ggml_permute(ctx, result, 0, 2, 1, 3));
} }
ggml_tensor* ggml_ext_conv_1d(ggml_context* ctx, ggml_tensor* ggml_ext_conv_1d(ggml_context* ctx,
+1 -1
View File
@@ -13,8 +13,8 @@
#include <vector> #include <vector>
#include "core/ggml_extend.h" #include "core/ggml_extend.h"
#include "core/ggml_runner.h"
#include "core/ggml_extend_backend.h" #include "core/ggml_extend_backend.h"
#include "core/ggml_runner.h"
#include "model.h" #include "model.h"
class GGMLBlock { class GGMLBlock {
+9 -20
View File
@@ -363,33 +363,22 @@ namespace MiniMaxH3 {
auto pre = std::dynamic_pointer_cast<AudioAttentionProjection>(blocks["pre_block"]); auto pre = std::dynamic_pointer_cast<AudioAttentionProjection>(blocks["pre_block"]);
auto mean_proj = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["mean_proj"]); auto mean_proj = std::dynamic_pointer_cast<LTXV::Conv1D>(blocks["mean_proj"]);
// GGML's batched conv1d storage interleaves the stream dimension
// with output channels. Subsequent layers then read stereo samples
// as adjacent feature channels. Run each mono stream independently,
// matching PyTorch's reshape(B*S, 1, samples), and concatenate only
// the completed normalized latents.
const int64_t streams = waveform->ne[2] * waveform->ne[3]; const int64_t streams = waveform->ne[2] * waveform->ne[3];
waveform = ggml_reshape_3d(ctx->ggml_ctx, waveform = ggml_reshape_3d(ctx->ggml_ctx,
waveform, waveform,
waveform->ne[0], waveform->ne[0],
1, 1,
streams); streams);
ggml_tensor* stereo_z = nullptr; auto x = encoder->forward(ctx, waveform);
for (int64_t stream = 0; stream < streams; ++stream) { x = ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, x, 1, 0, 2, 3));
auto mono = ggml_ext_slice(ctx->ggml_ctx, waveform, 2, stream, stream + 1); x = pre->forward(ctx, x);
auto x = encoder->forward(ctx, mono); x = ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, x, 1, 0, 2, 3));
x = ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, x, 1, 0, 2, 3)); auto z = mean_proj->forward(ctx, x);
x = pre->forward(ctx, x);
x = ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, x, 1, 0, 2, 3));
auto z = mean_proj->forward(ctx, x);
auto mean = ggml_reshape_4d(ctx->ggml_ctx, params["latents_mean"], 1, kLatentChannels, 1, 1); auto mean = ggml_reshape_4d(ctx->ggml_ctx, params["latents_mean"], 1, kLatentChannels, 1, 1);
auto std = ggml_reshape_4d(ctx->ggml_ctx, params["latents_std"], 1, kLatentChannels, 1, 1); auto std = ggml_reshape_4d(ctx->ggml_ctx, params["latents_std"], 1, kLatentChannels, 1, 1);
z = ggml_div(ctx->ggml_ctx, ggml_sub(ctx->ggml_ctx, z, mean), std); z = ggml_div(ctx->ggml_ctx, ggml_sub(ctx->ggml_ctx, z, mean), std);
z = ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, z, 0, 2, 1, 3)); return ggml_cont(ctx->ggml_ctx, ggml_permute(ctx->ggml_ctx, z, 0, 2, 1, 3));
stereo_z = stereo_z == nullptr ? z : ggml_concat(ctx->ggml_ctx, stereo_z, z, 1);
}
return stereo_z;
} }
ggml_tensor* decode(GGMLRunnerContext* ctx, ggml_tensor* latent) { ggml_tensor* decode(GGMLRunnerContext* ctx, ggml_tensor* latent) {