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

Function activation1d

src/framework/audio/flashsr.cpp:236–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

234}
235
236core::TensorValue activation1d(
237 core::ModuleBuildContext & ctx,
238 const core::TensorValue & input,
239 const ActivationParams & params,
240 const FlashSrWeights & weights) {
241 constexpr int64_t pad = kFlashSrActivationKernel / kFlashSrActivationRatio - 1;
242 constexpr int64_t crop_left = pad * kFlashSrActivationRatio +
243 (kFlashSrActivationKernel - kFlashSrActivationRatio) / 2;
244 constexpr int64_t crop_right = pad * kFlashSrActivationRatio +
245 (kFlashSrActivationKernel - kFlashSrActivationRatio + 1) / 2;
246 auto padded = replicate_pad1d(ctx, input, pad, pad);
247 auto up = modules::ConvTranspose1dModule({
248 kFlashSrChannels,
249 kFlashSrChannels,
250 kFlashSrActivationKernel,
251 kFlashSrActivationRatio,
252 0,
253 1,
254 false,
255 }).build(ctx, padded, weights.upsample_filter);
256 up = modules::SliceModule({2, crop_left, up.shape.dims[2] - crop_left - crop_right}).build(ctx, up);
257
258 auto alpha = core::reshape_tensor(ctx, params.alpha, core::TensorShape::from_dims({1, kFlashSrChannels, 1}));
259 alpha = core::wrap_tensor(ggml_repeat(ctx.ggml, alpha.tensor, up.tensor), up.shape, GGML_TYPE_F32);
260 auto inv_beta = core::reshape_tensor(ctx, params.inv_beta, core::TensorShape::from_dims({1, kFlashSrChannels, 1}));
261 inv_beta = core::wrap_tensor(ggml_repeat(ctx.ggml, inv_beta.tensor, up.tensor), up.shape, GGML_TYPE_F32);
262 auto periodic = core::wrap_tensor(
263 ggml_sqr(ctx.ggml, ggml_sin(ctx.ggml, ggml_mul(ctx.ggml, up.tensor, alpha.tensor))),
264 up.shape,
265 GGML_TYPE_F32);
266 auto snake = core::wrap_tensor(
267 ggml_add(ctx.ggml, up.tensor, ggml_mul(ctx.ggml, periodic.tensor, inv_beta.tensor)),
268 up.shape,
269 GGML_TYPE_F32);
270
271 auto down_padded = replicate_pad1d(
272 ctx,
273 snake,
274 kFlashSrActivationKernel / 2 - 1,
275 kFlashSrActivationKernel / 2);
276 return modules::Conv1dModule({
277 kFlashSrChannels,
278 kFlashSrChannels,
279 kFlashSrActivationKernel,
280 kFlashSrActivationRatio,
281 0,
282 1,
283 false,
284 }).build(ctx, down_padded, weights.downsample_filter);
285}
286
287core::TensorValue resblock(
288 core::ModuleBuildContext & ctx,

Callers 2

resblockFunction · 0.70
FlashSrGraphMethod · 0.70

Calls 12

replicate_pad1dFunction · 0.85
SliceModuleClass · 0.85
reshape_tensorFunction · 0.85
wrap_tensorFunction · 0.85
ggml_repeatFunction · 0.85
ggml_sqrFunction · 0.85
ggml_sinFunction · 0.85
ggml_mulFunction · 0.85
ggml_addFunction · 0.85
Conv1dModuleClass · 0.85
buildMethod · 0.45

Tested by

no test coverage detected