| 194 | } |
| 195 | |
| 196 | core::TensorValue build_snake1d_exact_bct( |
| 197 | core::ModuleBuildContext & ctx, |
| 198 | const core::TensorValue & input, |
| 199 | const SnakeExactWeights & weights, |
| 200 | int64_t channels) { |
| 201 | const auto input_f32 = ensure_f32(ctx, ensure_contiguous_nontransposed(ctx, input)); |
| 202 | auto alpha = ensure_f32(ctx, weights.alpha); |
| 203 | auto beta_inv = ensure_f32(ctx, weights.beta_inv); |
| 204 | if (alpha.shape.rank != 3 || alpha.shape.dims[0] != 1 || alpha.shape.dims[1] != channels || alpha.shape.dims[2] != 1 || |
| 205 | beta_inv.shape.rank != 3 || beta_inv.shape.dims[0] != 1 || beta_inv.shape.dims[1] != channels || beta_inv.shape.dims[2] != 1) { |
| 206 | throw std::runtime_error("ACE-Step VAE Snake1d weight shape mismatch"); |
| 207 | } |
| 208 | if (input_f32.shape.rank != 3) { |
| 209 | throw std::runtime_error("ACE-Step VAE Snake1d expects rank-3 BCT input"); |
| 210 | } |
| 211 | auto periodic = core::wrap_tensor( |
| 212 | ggml_sqr(ctx.ggml, ggml_sin(ctx.ggml, ggml_mul(ctx.ggml, input_f32.tensor, alpha.tensor))), |
| 213 | input_f32.shape, |
| 214 | GGML_TYPE_F32); |
| 215 | const auto beta_inv_broadcast = core::wrap_tensor( |
| 216 | ggml_repeat(ctx.ggml, beta_inv.tensor, input_f32.tensor), |
| 217 | input_f32.shape, |
| 218 | GGML_TYPE_F32); |
| 219 | auto frac = modules::MulModule{}.build(ctx, periodic, beta_inv_broadcast); |
| 220 | return modules::AddModule{}.build(ctx, input_f32, frac); |
| 221 | } |
| 222 | |
| 223 | SnakeExactWeights load_snake_exact( |
| 224 | core::BackendWeightStore & store, |
no test coverage detected