| 1829 | return runtime_.get() == &runtime && prompt_steps_ == prompt_steps; |
| 1830 | } |
| 1831 | |
| 1832 | PrefillOutput run(const std::vector<int32_t> & token_ids, const std::vector<int32_t> & attention_mask) { |
| 1833 | const auto & config = runtime_->assets().config.planner; |
| 1834 | if (static_cast<int64_t>(token_ids.size()) != prompt_steps_ || |
| 1835 | static_cast<int64_t>(attention_mask.size()) != prompt_steps_) { |
| 1836 | throw std::runtime_error("ACE-Step planner prefill token or attention-mask count mismatch"); |
| 1837 | } |
| 1838 | ggml_backend_tensor_set(token_ids_, token_ids.data(), 0, token_ids.size() * sizeof(int32_t)); |
| 1839 | std::vector<int32_t> position_ids(static_cast<size_t>(prompt_steps_), 0); |
| 1840 | for (int64_t i = 0; i < prompt_steps_; ++i) { |
| 1841 | position_ids[static_cast<size_t>(i)] = static_cast<int32_t>(i); |
| 1842 | } |
| 1843 | ggml_backend_tensor_set(positions_, position_ids.data(), 0, position_ids.size() * sizeof(int32_t)); |
| 1844 | const auto attention_mask_values = build_prefill_attention_mask_values(attention_mask); |
| 1845 | ggml_backend_tensor_set( |
| 1846 | attention_mask_, |
| 1847 | attention_mask_values.data(), |
| 1848 | 0, |
| 1849 | attention_mask_values.size() * sizeof(ggml_fp16_t)); |
| 1850 | std::vector<float> query_mask_values(static_cast<size_t>(prompt_steps_), 0.0F); |
| 1851 | for (int64_t i = 0; i < prompt_steps_; ++i) { |
| 1852 | query_mask_values[static_cast<size_t>(i)] = attention_mask[static_cast<size_t>(i)] != 0 ? 1.0F : 0.0F; |
| 1853 | } |
| 1854 | ggml_backend_tensor_set(query_mask_, query_mask_values.data(), 0, query_mask_values.size() * sizeof(float)); |
| 1855 | core::set_backend_threads(runtime_->backend(), runtime_->threads()); |
| 1856 | const ggml_status status = engine::core::compute_backend_graph(runtime_->backend(), graph_); |
| 1857 | ggml_backend_synchronize(runtime_->backend()); |
| 1858 | if (status != GGML_STATUS_SUCCESS) { |
| 1859 | throw std::runtime_error("ACE-Step planner prefill graph compute failed"); |
| 1860 | } |
| 1861 | PrefillOutput out; |
| 1862 | out.logits.resize(static_cast<size_t>(config.vocab_size)); |
| 1863 | ggml_backend_tensor_get(logits_, out.logits.data(), 0, out.logits.size() * sizeof(float)); |
| 1864 | out.kv_state.current_end = prompt_steps_; |
| 1865 | out.kv_state.layers.resize(keys_.size()); |
| 1866 | const size_t layer_values = static_cast<size_t>(prompt_steps_ * config.num_key_value_heads * config.head_dim); |
| 1867 | for (size_t layer = 0; layer < keys_.size(); ++layer) { |
| 1868 | auto & state = out.kv_state.layers[layer]; |
| 1869 | state.valid_steps = prompt_steps_; |
| 1870 | state.key.resize(layer_values); |
| 1871 | state.value.resize(layer_values); |
| 1872 | ggml_backend_tensor_get(keys_[layer], state.key.data(), 0, state.key.size() * sizeof(float)); |
| 1873 | ggml_backend_tensor_get(values_[layer], state.value.data(), 0, state.value.size() * sizeof(float)); |
| 1874 | } |
| 1875 | return out; |
| 1876 | } |
| 1877 | |
| 1878 | private: |
no test coverage detected