| 900 | } |
| 901 | |
| 902 | HeartMuLaBackboneResult run_step(const std::vector<float> & embedding) { |
| 903 | allocate_workspace(); |
| 904 | const auto & config = runtime_->assets().mula_config.backbone; |
| 905 | if (static_cast<int64_t>(embedding.size()) != batch_size_ * config.embed_dim) { |
| 906 | throw std::runtime_error("HeartMuLa backbone cached step embedding payload size mismatch"); |
| 907 | } |
| 908 | if (step_cache_.valid_steps() >= cache_steps_) { |
| 909 | throw std::runtime_error("HeartMuLa backbone cached step exceeds cache capacity"); |
| 910 | } |
| 911 | ggml_backend_tensor_set(input_, embedding.data(), 0, embedding.size() * sizeof(float)); |
| 912 | const int32_t position = static_cast<int32_t>(step_cache_.current_end()); |
| 913 | ggml_backend_tensor_set(positions_, &position, 0, sizeof(int32_t)); |
| 914 | const int64_t cache_slot = step_cache_.valid_steps(); |
| 915 | std::fill( |
| 916 | attention_mask_buffer_.begin(), |
| 917 | attention_mask_buffer_.end(), |
| 918 | ggml_fp32_to_fp16(-std::numeric_limits<float>::infinity())); |
| 919 | for (int64_t i = 0; i < step_cache_.valid_steps(); ++i) { |
| 920 | attention_mask_buffer_[static_cast<size_t>(i)] = ggml_fp32_to_fp16(0.0F); |
| 921 | } |
| 922 | attention_mask_buffer_[static_cast<size_t>(cache_steps_)] = ggml_fp32_to_fp16(0.0F); |
| 923 | ggml_backend_tensor_set( |
| 924 | attention_mask_, |
| 925 | attention_mask_buffer_.data(), |
| 926 | 0, |
| 927 | attention_mask_buffer_.size() * sizeof(ggml_fp16_t)); |
| 928 | core::set_backend_threads(runtime_->backend(), runtime_->threads()); |
| 929 | const ggml_status status = engine::core::compute_backend_graph(runtime_->backend(), graph_); |
| 930 | ggml_backend_synchronize(runtime_->backend()); |
| 931 | if (status != GGML_STATUS_SUCCESS) { |
| 932 | throw std::runtime_error("HeartMuLa backbone cached step graph compute failed"); |
| 933 | } |
| 934 | const size_t dst_slot = static_cast<size_t>(cache_slot); |
| 935 | for (size_t layer = 0; layer < key_sources_.size(); ++layer) { |
| 936 | ggml_backend_tensor_copy(key_sources_[layer], key_destinations_[dst_slot][layer]); |
| 937 | ggml_backend_tensor_copy(value_sources_[layer], value_destinations_[dst_slot][layer]); |
| 938 | } |
| 939 | HeartMuLaBackboneResult out; |
| 940 | out.logits.vocab_size = runtime_->assets().mula_config.audio_vocab_size; |
| 941 | out.logits.values.resize(static_cast<size_t>(batch_size_ * out.logits.vocab_size)); |
| 942 | ggml_backend_tensor_get(logits_output_, out.logits.values.data(), 0, out.logits.values.size() * sizeof(float)); |
| 943 | out.last_hidden.dims = config.embed_dim; |
| 944 | out.last_hidden.values.resize(static_cast<size_t>(batch_size_ * config.embed_dim)); |
| 945 | ggml_backend_tensor_get(hidden_output_, out.last_hidden.values.data(), 0, out.last_hidden.values.size() * sizeof(float)); |
| 946 | step_cache_.advance_after_direct_append(1); |
| 947 | return out; |
| 948 | } |
| 949 | |
| 950 | private: |
| 951 | void build_transfer_views(int64_t step_elems) { |
nothing calls this directly
no test coverage detected