| 361 | void ensure_graph(int64_t batch, int64_t tokens) { |
| 362 | if (ggml_ != nullptr && batch_ == batch && tokens_ == tokens) { |
| 363 | return; |
| 364 | } |
| 365 | release_graph(); |
| 366 | ggml_init_params params{ |
| 367 | 1024ull * 1024ull * 512ull, |
| 368 | nullptr, |
| 369 | true, |
| 370 | }; |
| 371 | ggml_ = ggml_init(params); |
| 372 | if (ggml_ == nullptr) { |
| 373 | throw std::runtime_error("failed to initialize Seed-VC ASTRAL graph context"); |
| 374 | } |
| 375 | engine::core::ModuleBuildContext ctx{ |
| 376 | ggml_, |
| 377 | "seed_vc.astral", |
| 378 | execution_context_.backend_type()}; |
| 379 | input_ = engine::core::make_tensor( |
| 380 | ctx, |
| 381 | GGML_TYPE_F32, |
| 382 | engine::core::TensorShape::from_dims({batch, tokens, input_channels_})); |
| 383 | output_ = build_astral_projected( |
| 384 | ctx, |
| 385 | input_, |
| 386 | graph_weights_, |
| 387 | input_channels_, |
| 388 | channels_, |
| 389 | intermediate_channels_); |
| 390 | graph_ = ggml_new_graph_custom(ggml_, 65536, false); |
| 391 | ggml_build_forward_expand(graph_, output_.tensor); |
| 392 | gallocr_ = ggml_gallocr_new(ggml_backend_get_default_buffer_type(execution_context_.backend())); |
| 393 | if (gallocr_ == nullptr || |
| 394 | !ggml_gallocr_reserve(gallocr_, graph_) || |
| 395 | !ggml_gallocr_alloc_graph(gallocr_, graph_)) { |
| 396 | release_graph(); |
| 397 | throw std::runtime_error("failed to allocate Seed-VC ASTRAL graph tensors"); |
| 398 | } |
| 399 | batch_ = batch; |
| 400 | tokens_ = tokens; |
| 401 | } |
| 402 | |
| 403 | engine::core::ExecutionContext & execution_context_; |
| 404 | AstralWeights graph_weights_; |
| 405 | int64_t input_channels_ = 0; |
| 406 | int64_t channels_ = 0; |
nothing calls this directly
no test coverage detected