| 154 | } |
| 155 | |
| 156 | std::vector<VibeVoiceConnectorOutput> run_batch( |
| 157 | const std::vector<VibeVoiceTokenizerLatents> & features) { |
| 158 | if (static_cast<int64_t>(features.size()) != batch_size_) { |
| 159 | throw std::runtime_error("VibeVoice connector feature batch size mismatch"); |
| 160 | } |
| 161 | const size_t per_sample = static_cast<size_t>(frames_ * weights_->input_dim); |
| 162 | std::vector<float> input(static_cast<size_t>(batch_size_) * per_sample, 0.0F); |
| 163 | for (int64_t batch = 0; batch < batch_size_; ++batch) { |
| 164 | const auto & item = features[static_cast<size_t>(batch)]; |
| 165 | if (item.frames != frames_ || item.dim != weights_->input_dim) { |
| 166 | throw std::runtime_error("VibeVoice connector batch feature shape mismatch"); |
| 167 | } |
| 168 | if (item.values.size() != per_sample) { |
| 169 | throw std::runtime_error("VibeVoice connector batch feature payload size mismatch"); |
| 170 | } |
| 171 | std::copy( |
| 172 | item.values.begin(), |
| 173 | item.values.end(), |
| 174 | input.begin() + static_cast<std::ptrdiff_t>(batch * static_cast<int64_t>(per_sample))); |
| 175 | } |
| 176 | ggml_backend_tensor_set(input_, input.data(), 0, input.size() * sizeof(float)); |
| 177 | core::set_backend_threads(runtime_->backend(), runtime_->threads()); |
| 178 | const ggml_status status = engine::core::compute_backend_graph(runtime_->backend(), graph_); |
| 179 | ggml_backend_synchronize(runtime_->backend()); |
| 180 | if (status != GGML_STATUS_SUCCESS) { |
| 181 | throw std::runtime_error("VibeVoice connector graph compute failed"); |
| 182 | } |
| 183 | std::vector<float> output(static_cast<size_t>(batch_size_ * frames_ * weights_->hidden_size), 0.0F); |
| 184 | ggml_backend_tensor_get(output_, output.data(), 0, output.size() * sizeof(float)); |
| 185 | std::vector<VibeVoiceConnectorOutput> out(static_cast<size_t>(batch_size_)); |
| 186 | const size_t output_per_sample = static_cast<size_t>(frames_ * weights_->hidden_size); |
| 187 | for (int64_t batch = 0; batch < batch_size_; ++batch) { |
| 188 | auto & item = out[static_cast<size_t>(batch)]; |
| 189 | item.frames = frames_; |
| 190 | item.hidden_size = weights_->hidden_size; |
| 191 | const auto begin = output.begin() + static_cast<std::ptrdiff_t>(batch * static_cast<int64_t>(output_per_sample)); |
| 192 | item.values.assign(begin, begin + static_cast<std::ptrdiff_t>(output_per_sample)); |
| 193 | } |
| 194 | return out; |
| 195 | } |
| 196 | |
| 197 | private: |
| 198 | const VibeVoiceConnectorWeightsRuntime * runtime_ = nullptr; |
no test coverage detected