MCPcopy Create free account
hub / github.com/0xShug0/audio.cpp / build_time_mask_4d

Function build_time_mask_4d

src/framework/modules/conformer_modules.cpp:48–71  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

46}
47
48core::TensorValue build_time_mask_4d(
49 core::ModuleBuildContext & ctx,
50 const core::TensorValue & input,
51 const core::TensorValue & lengths) {
52 core::validate_rank_between(input, 4, 4, "time_mask.input");
53 core::validate_shape(lengths, core::TensorShape::from_dims({input.shape.dims[0]}), "time_mask.lengths");
54
55 const int64_t batch = input.shape.dims[0];
56 const int64_t channels = input.shape.dims[1];
57 const int64_t frames = input.shape.dims[2];
58 const int64_t features = input.shape.dims[3];
59
60 auto lengths_f32 = core::wrap_tensor(ggml_cast(ctx.ggml, lengths.tensor, GGML_TYPE_F32), lengths.shape, GGML_TYPE_F32);
61 auto lengths_4d = core::reshape_tensor(ctx, lengths_f32, core::TensorShape::from_dims({batch, 1, 1, 1}));
62 lengths_4d = RepeatModule(RepeatConfig{core::TensorShape::from_dims({batch, 1, frames, 1})}).build(ctx, lengths_4d);
63
64 auto positions = core::wrap_tensor(ggml_arange(ctx.ggml, 0.5f, static_cast<float>(frames) + 0.5f, 1.0f), core::TensorShape::from_dims({frames}), GGML_TYPE_F32);
65 positions = core::reshape_tensor(ctx, positions, core::TensorShape::from_dims({1, 1, frames, 1}));
66 positions = RepeatModule(RepeatConfig{core::TensorShape::from_dims({batch, 1, frames, 1})}).build(ctx, positions);
67
68 auto diff = core::wrap_tensor(ggml_add(ctx.ggml, lengths_4d.tensor, ggml_scale(ctx.ggml, positions.tensor, -1.0f)), lengths_4d.shape, GGML_TYPE_F32);
69 auto mask = core::wrap_tensor(ggml_step(ctx.ggml, diff.tensor), diff.shape, GGML_TYPE_F32);
70 return RepeatModule(RepeatConfig{core::TensorShape::from_dims({batch, channels, frames, features})}).build(ctx, mask);
71}
72
73core::TensorValue apply_lengths_time_mask_4d(
74 core::ModuleBuildContext & ctx,

Callers 1

Calls 11

validate_rank_betweenFunction · 0.85
validate_shapeFunction · 0.85
wrap_tensorFunction · 0.85
ggml_castFunction · 0.85
reshape_tensorFunction · 0.85
RepeatModuleClass · 0.85
ggml_arangeFunction · 0.85
ggml_addFunction · 0.85
ggml_scaleFunction · 0.85
ggml_stepFunction · 0.85
buildMethod · 0.45

Tested by

no test coverage detected