MCPcopy Create free account
hub / github.com/cactus-compute/cactus / build_convolution_module

Method build_convolution_module

cactus/models/model_parakeet.cpp:447–488  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

445}
446
447size_t ParakeetModel::build_convolution_module(CactusGraph* gb, size_t hidden, uint32_t layer_idx, ComputeBackend backend) {
448 (void)backend;
449 const auto& layer = weight_nodes_.layers[layer_idx];
450 const auto& hidden_shape = gb->get_output_buffer(hidden).shape;
451 if (hidden_shape.size() != 2) {
452 throw std::runtime_error("Parakeet convolution module expects [T, D]");
453 }
454
455 const size_t T = hidden_shape[0];
456 const size_t D = hidden_shape[1];
457
458 size_t x = gb->reshape(hidden, {1, T, D});
459 x = gb->conv1d_pointwise(x, layer.conv_pointwise1_weight, layer.conv_pointwise1_bias);
460 x = gb->glu(x, -1);
461
462 x = gb->conv1d_same_depthwise_k9(x, layer.conv_depthwise_weight, layer.conv_depthwise_bias);
463
464 x = gb->batchnorm(
465 x,
466 layer.conv_batchnorm_weight,
467 layer.conv_batchnorm_bias,
468 layer.conv_batchnorm_running_mean,
469 layer.conv_batchnorm_running_var,
470 2,
471 1e-5f
472 );
473
474 std::string act = config_.encoder_hidden_act;
475 std::transform(act.begin(), act.end(), act.begin(), ::tolower);
476 if (act.find("gelu") != std::string::npos) {
477 x = gb->gelu(x);
478 } else if (act == "relu") {
479 x = gb->relu(x);
480 } else {
481 x = gb->silu(x);
482 }
483
484 x = gb->conv1d_pointwise(x, layer.conv_pointwise2_weight, layer.conv_pointwise2_bias);
485
486 x = gb->reshape(x, {T, D});
487 return x;
488}
489
490size_t ParakeetModel::build_encoder_block(CactusGraph* gb, size_t hidden, size_t position_embeddings,
491 uint32_t layer_idx, ComputeBackend backend) {

Callers

nothing calls this directly

Calls 10

get_output_bufferMethod · 0.80
sizeMethod · 0.80
reshapeMethod · 0.80
conv1d_pointwiseMethod · 0.80
gluMethod · 0.80
batchnormMethod · 0.80
siluMethod · 0.80
geluMethod · 0.45
reluMethod · 0.45

Tested by

no test coverage detected