| 458 | } |
| 459 | |
| 460 | std::vector<float> flatten_prefill_cache_by_step( |
| 461 | const std::vector<float> & values, |
| 462 | int64_t batch, |
| 463 | int64_t steps, |
| 464 | int64_t heads, |
| 465 | int64_t dim) { |
| 466 | const size_t expected = static_cast<size_t>(batch * steps * heads * dim); |
| 467 | if (values.size() != expected) { |
| 468 | throw std::runtime_error("HeartMuLa backbone prefill cache tensor size mismatch"); |
| 469 | } |
| 470 | std::vector<float> out(expected); |
| 471 | for (int64_t step = 0; step < steps; ++step) { |
| 472 | for (int64_t b = 0; b < batch; ++b) { |
| 473 | for (int64_t head = 0; head < heads; ++head) { |
| 474 | const size_t src = static_cast<size_t>(((b * steps + step) * heads + head) * dim); |
| 475 | const size_t dst = static_cast<size_t>(((step * batch + b) * heads + head) * dim); |
| 476 | std::copy(values.begin() + static_cast<ptrdiff_t>(src), |
| 477 | values.begin() + static_cast<ptrdiff_t>(src + dim), |
| 478 | out.begin() + static_cast<ptrdiff_t>(dst)); |
| 479 | } |
| 480 | } |
| 481 | } |
| 482 | return out; |
| 483 | } |
| 484 | |
| 485 | core::TensorValue codebook_audio_logits( |
| 486 | core::ModuleBuildContext & ctx, |