| 139 | } |
| 140 | |
| 141 | core::TensorValue build_timestep_embedding( |
| 142 | core::ModuleBuildContext & ctx, |
| 143 | const core::TensorValue & timesteps, |
| 144 | const VibeVoiceDiffusionHeadWeights & weights, |
| 145 | const VibeVoiceDiffusionHeadConfig & config) { |
| 146 | core::validate_rank_between(timesteps, 1, 1, "timesteps"); |
| 147 | const int64_t batch = timesteps.shape.dims[0]; |
| 148 | auto freqs = core::reshape_tensor(ctx, weights.time_freqs, core::TensorShape::from_dims({1, kTimestepFrequencyEmbeddingSize / 2})); |
| 149 | freqs = modules::RepeatModule({core::TensorShape::from_dims({batch, kTimestepFrequencyEmbeddingSize / 2})}).build(ctx, freqs); |
| 150 | auto expanded_time = core::reshape_tensor(ctx, timesteps, core::TensorShape::from_dims({batch, 1})); |
| 151 | expanded_time = modules::RepeatModule({core::TensorShape::from_dims({batch, kTimestepFrequencyEmbeddingSize / 2})}).build(ctx, expanded_time); |
| 152 | auto args = modules::MulModule{}.build(ctx, expanded_time, freqs); |
| 153 | auto cos_part = core::wrap_tensor(ggml_cos(ctx.ggml, args.tensor), args.shape, GGML_TYPE_F32); |
| 154 | auto sin_part = core::wrap_tensor(ggml_sin(ctx.ggml, args.tensor), args.shape, GGML_TYPE_F32); |
| 155 | auto embedding = modules::ConcatModule({1}).build(ctx, cos_part, sin_part); |
| 156 | auto hidden = modules::LinearModule( |
| 157 | binding::linear_config(kTimestepFrequencyEmbeddingSize, config.hidden_size, false)) |
| 158 | .build(ctx, embedding, weights.timestep_fc1); |
| 159 | hidden = modules::SiluModule{}.build(ctx, hidden); |
| 160 | return modules::LinearModule( |
| 161 | binding::linear_config(config.hidden_size, config.hidden_size, false)) |
| 162 | .build(ctx, hidden, weights.timestep_fc2); |
| 163 | } |
| 164 | |
| 165 | core::TensorValue build_swiglu( |
| 166 | core::ModuleBuildContext & ctx, |
no test coverage detected