| 276 | } |
| 277 | |
| 278 | core::TensorValue same_feed_forward( |
| 279 | core::ModuleBuildContext & ctx, |
| 280 | const core::TensorValue & input, |
| 281 | const StableAudioSameFeedForwardWeights & weights, |
| 282 | bool sinusoidal) { |
| 283 | const int64_t dim = input.shape.last_dim(); |
| 284 | const int64_t inner = dim * 3; |
| 285 | auto projected = modules::LinearModule({dim, 2 * inner, true, GGML_PREC_F32}).build(ctx, input, weights.in_proj); |
| 286 | auto value = modules::SliceModule({2, 0, inner}).build(ctx, projected); |
| 287 | auto gate = modules::SliceModule({2, inner, inner}).build(ctx, projected); |
| 288 | if (sinusoidal) { |
| 289 | gate = core::wrap_tensor(ggml_sin(ctx.ggml, scale_tensor(ctx, gate, kPi).tensor), gate.shape, GGML_TYPE_F32); |
| 290 | } else { |
| 291 | gate = modules::SiluModule{}.build(ctx, gate); |
| 292 | } |
| 293 | auto hidden = modules::MulModule{}.build(ctx, value, gate); |
| 294 | return modules::LinearModule({inner, dim, true, GGML_PREC_F32}).build(ctx, hidden, weights.out_proj); |
| 295 | } |
| 296 | |
| 297 | core::TensorValue same_transformer_layer( |
| 298 | core::ModuleBuildContext & ctx, |
no test coverage detected