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

Function fsq_quantized

src/models/miocodec/graph_ops.cpp:530–563  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

528 auto latent = engine::modules::LinearModule({768, 5, weights.input_projection.bias.has_value()}).build(
529 ctx,
530 input,
531 weights.input_projection);
532 constexpr float eps = 1.0e-3F;
533 const float half_l_values[] = {3.5F * (1.0F - eps), 3.5F * (1.0F - eps), 3.5F * (1.0F - eps), 2.0F * (1.0F - eps), 2.0F * (1.0F - eps)};
534 const float offset_values[] = {0.5F, 0.5F, 0.5F, 0.0F, 0.0F};
535 const float shift_values[] = {
536 std::tan(offset_values[0] / half_l_values[0]),
537 std::tan(offset_values[1] / half_l_values[1]),
538 std::tan(offset_values[2] / half_l_values[2]),
539 0.0F,
540 0.0F};
541 const float half_width_values[] = {4.0F, 4.0F, 4.0F, 2.0F, 2.0F};
542 const auto constant_shape = core::TensorShape::from_dims({1, 1, 5});
543 const auto half_l = repeat_like(ctx, constants.make_f32(constant_shape, std::vector<float>(std::begin(half_l_values), std::end(half_l_values))), latent, constant_shape);
544 const auto offset = repeat_like(ctx, constants.make_f32(constant_shape, std::vector<float>(std::begin(offset_values), std::end(offset_values))), latent, constant_shape);
545 const auto shift = repeat_like(ctx, constants.make_f32(constant_shape, std::vector<float>(std::begin(shift_values), std::end(shift_values))), latent, constant_shape);
546 const auto half_width = repeat_like(ctx, constants.make_f32(constant_shape, std::vector<float>(std::begin(half_width_values), std::end(half_width_values))), latent, constant_shape);
547 auto shifted = core::wrap_tensor(ggml_add(ctx.ggml, latent.tensor, shift.tensor), latent.shape, GGML_TYPE_F32);
548 auto bounded = core::wrap_tensor(ggml_tanh(ctx.ggml, shifted.tensor), latent.shape, GGML_TYPE_F32);
549 auto scaled_bounded = engine::modules::MulModule{}.build(ctx, bounded, half_l);
550 bounded = core::wrap_tensor(ggml_sub(ctx.ggml, scaled_bounded.tensor, offset.tensor), latent.shape, GGML_TYPE_F32);
551 auto rounded = core::wrap_tensor(ggml_round(ctx.ggml, bounded.tensor), latent.shape, GGML_TYPE_F32);
552 auto normalized = core::wrap_tensor(ggml_div(ctx.ggml, rounded.tensor, half_width.tensor), latent.shape, GGML_TYPE_F32);
553 return engine::modules::LinearModule({5, 768, weights.output_projection.bias.has_value()}).build(
554 ctx,
555 normalized,
556 weights.output_projection);
557}
558
559core::TensorValue convnext_block(
560 core::ModuleBuildContext & ctx,
561 const core::TensorValue & input_bct,
562 const MioCodecConvNeXtBlockWeights & weights) {
563 auto x = engine::modules::DepthwiseConv1dModule(weights.depthwise_conv_config).build(ctx, input_bct, weights.depthwise_conv);
564 x = engine::modules::TransposeModule({{0, 2, 1, 3}, x.shape.rank}).build(ctx, x);
565 x = engine::modules::LayerNormModule({384, 1.0e-6F, true, true}).build(ctx, x, weights.norm);
566 x = engine::modules::LinearModule({384, 1152, weights.pointwise_conv1.bias.has_value()}).build(

Callers 1

Calls 11

LinearModuleClass · 0.85
wrap_tensorFunction · 0.85
ggml_addFunction · 0.85
ggml_tanhFunction · 0.85
ggml_subFunction · 0.85
ggml_mulFunction · 0.85
ggml_roundFunction · 0.85
ggml_divFunction · 0.85
repeat_likeFunction · 0.70
buildMethod · 0.45
make_f32Method · 0.45

Tested by

no test coverage detected