| 845 | int64_t hidden_size) { |
| 846 | const int64_t batch = input.shape.dims[0]; |
| 847 | const int64_t frames = input.shape.dims[1]; |
| 848 | auto table = core::reshape_tensor(ctx, scale_shift_table, core::TensorShape::from_dims({1, 2, hidden_size})); |
| 849 | table = modules::RepeatModule({core::TensorShape::from_dims({batch, 2, hidden_size})}).build(ctx, table); |
| 850 | auto embedded = core::reshape_tensor(ctx, embedded_timestep, core::TensorShape::from_dims({batch, 1, hidden_size})); |
| 851 | embedded = modules::RepeatModule({core::TensorShape::from_dims({batch, 2, hidden_size})}).build(ctx, embedded); |
| 852 | auto parts = modules::AddModule{}.build(ctx, embedded, table); |
| 853 | auto shift = expand_batch_token(ctx, modules::SliceModule({1, 0, 1}).build(ctx, parts), frames, hidden_size); |
| 854 | auto scale_part = expand_batch_token(ctx, modules::SliceModule({1, 1, 1}).build(ctx, parts), frames, hidden_size); |
| 855 | auto normalized = modules::LayerNormModule({hidden_size, 1.0e-6F, false, false}).build(ctx, input, {}); |
| 856 | return modules::AddModule{}.build( |
| 857 | ctx, |
| 858 | modules::MulModule{}.build(ctx, normalized, add_one(ctx, scale_part)), |
| 859 | shift); |
| 860 | } |
| 861 | |
| 862 | FlowEstimatorBuildResult flow_estimator( |
| 863 | core::ModuleBuildContext & ctx, |
| 864 | const core::TensorValue & hidden_states, |
| 865 | const core::TensorValue & timesteps, |
| 866 | const core::TensorValue & freqs, |
| 867 | const core::TensorValue & positions, |
| 868 | const HeartCodecFlowEstimatorWeights & weights, |
| 869 | const HeartCodecConfig & config) { |
| 870 | const int64_t estimator_dim = config.num_attention_heads * config.attention_head_dim; |
| 871 | const int64_t estimator_dim_2 = 2 * estimator_dim; |
| 872 | auto s = project_layer(ctx, hidden_states, weights.proj_in, config.in_channels, estimator_dim); |
| 873 | auto embedded_timestep = adaln_embedding(ctx, timesteps, freqs, weights.adaln_single, estimator_dim); |
| 874 | auto timestep_mod = modules::LinearModule({estimator_dim, 6 * estimator_dim, true, GGML_PREC_F32}) |
| 875 | .build(ctx, modules::SiluModule{}.build(ctx, embedded_timestep), weights.adaln_single.linear); |
| 876 | for (size_t index = 0; index < weights.transformer_blocks.size(); ++index) { |
| 877 | const auto & block = weights.transformer_blocks[index]; |
no test coverage detected