| 119 | } |
| 120 | |
| 121 | TensorValue SEANetDecoder::build( |
| 122 | engine::core::ModuleBuildContext & ctx, |
| 123 | const TensorValue & input, |
| 124 | const SEANetDecoderWeights & weights) const { |
| 125 | if (weights.stages.size() != config_.stage_channels.size()) { |
| 126 | throw std::runtime_error("SEANetDecoderWeights stage count does not match config"); |
| 127 | } |
| 128 | |
| 129 | int64_t current_channels = config_.input_channels; |
| 130 | auto x = StreamingConv1dModule({ |
| 131 | config_.input_channels, |
| 132 | config_.input_channels, |
| 133 | 7, |
| 134 | 1, |
| 135 | 1, |
| 136 | config_.use_bias, |
| 137 | config_.pad_mode, |
| 138 | }).build(ctx, input, weights.input_projection); |
| 139 | |
| 140 | for (size_t stage_index = 0; stage_index < config_.stage_channels.size(); ++stage_index) { |
| 141 | const int64_t next_channels = config_.stage_channels[stage_index]; |
| 142 | const int stride = static_cast<int>(config_.stage_strides[stage_index]); |
| 143 | const int64_t kernel_size = static_cast<int64_t>(stride) * 2; |
| 144 | x = EluModule().build(ctx, x); |
| 145 | x = build_streaming_convtranspose1d(ctx, x, weights.stages[stage_index].upsample, current_channels, next_channels, kernel_size, stride, config_.use_bias); |
| 146 | |
| 147 | if (weights.stages[stage_index].residual_blocks.size() != static_cast<size_t>(config_.residual_layers)) { |
| 148 | throw std::runtime_error("SEANetDecoder stage residual block count does not match config.residual_layers"); |
| 149 | } |
| 150 | for (int64_t residual_index = 0; residual_index < config_.residual_layers; ++residual_index) { |
| 151 | int64_t dilation = 1; |
| 152 | for (int64_t i = 0; i < residual_index; ++i) { |
| 153 | dilation *= config_.residual_dilation_base; |
| 154 | } |
| 155 | x = build_seanet_residual_block( |
| 156 | ctx, |
| 157 | x, |
| 158 | weights.stages[stage_index].residual_blocks[static_cast<size_t>(residual_index)], |
| 159 | next_channels, |
| 160 | next_channels / config_.residual_hidden_divisor, |
| 161 | dilation, |
| 162 | config_.use_bias, |
| 163 | config_.pad_mode); |
| 164 | } |
| 165 | current_channels = next_channels; |
| 166 | } |
| 167 | |
| 168 | x = EluModule().build(ctx, x); |
| 169 | return StreamingConv1dModule({ |
| 170 | current_channels, |
| 171 | config_.output_channels, |
| 172 | config_.final_kernel_size, |
| 173 | 1, |
| 174 | 1, |
| 175 | config_.use_bias, |
| 176 | config_.pad_mode, |
| 177 | }).build(ctx, x, weights.output_projection); |
| 178 | } |
no test coverage detected