| 380 | |
| 381 | |
| 382 | void BatchDecoder::draft_batched(const std::vector<BatchLane*>& lanes, const std::vector<int>& going, const std::vector<int>& r0, const std::vector<std::vector<int>>& got, |
| 383 | const std::vector<std::vector<int>>& look, const std::vector<int>& plan, const std::vector<int>& chain_room) { |
| 384 | const size_t ng = going.size(); |
| 385 | std::vector<int> used(ng), p(ng), prev_row(ng, 0), k(ng, 0); |
| 386 | std::vector<std::vector<int>> pen_seq(ng); |
| 387 | std::vector<char> pen(ng), samp(ng); |
| 388 | for (size_t g = 0; g < ng; ++g) { |
| 389 | BatchLane& L = *lanes[(size_t) going[g]]; |
| 390 | pen[g] = pen_drafts_ && penalizes(L.s); |
| 391 | samp[g] = samp_drafts_ && L.s.temperature > 0.f; |
| 392 | if (pen[g]) pen_seq[g] = tail(L.ctx, L.s.pen_last_n); |
| 393 | } |
| 394 | // as draft_one does for one lane: the penalty row, the draft layer's argmax or (sampling) a draw from its candidates under the lane's sampler and rng |
| 395 | auto finish = [&](size_t g, int d, Dist& q) { |
| 396 | BatchLane& L = *lanes[(size_t) going[g]]; |
| 397 | q = Dist{}; |
| 398 | if (samp[g]) { |
| 399 | std::uniform_real_distribution<double> unif(0.0, 1.0); |
| 400 | q = make_dist(e_.last_lane_cands[g], L.s); |
| 401 | d = draw(q, unif(L.rng)); |
| 402 | } |
| 403 | return d; |
| 404 | }; |
| 405 | std::vector<Engine::Penalties::Row> prow(ng); |
| 406 | std::vector<Engine::DraftReq> rq(ng); |
| 407 | int off = 0; |
| 408 | for (size_t g = 0; g < ng; ++g) { |
| 409 | BatchLane& L = *lanes[(size_t) going[g]]; |
| 410 | used[g] = (int) got[(size_t) going[g]].size(); |
| 411 | p[g] = e_.lane_pos(L.lane) - used[g]; // the lane's position before the window |
| 412 | Engine::DraftReq& q = rq[g]; |
| 413 | q.lane = L.lane, q.T = used[g], q.from_main = true, q.src_row = r0[(size_t) going[g]], q.pos0 = p[g], q.tokens = got[(size_t) going[g]]; |
| 414 | if (pen[g]) { |
| 415 | prow[g] = penalty_row(pen_seq[g], L.s); |
| 416 | q.pen = &prow[g]; |
| 417 | } |
| 418 | q.cands = samp[g]; |
| 419 | prev_row[g] = off + used[g] - 1; |
| 420 | off += used[g]; |
| 421 | } |
| 422 | std::vector<int> d1 = e_.draft_lanes(rq); |
| 423 | ++last_calls; |
| 424 | int deepest = 0; |
| 425 | for (size_t g = 0; g < ng; ++g) { |
| 426 | BatchLane& L = *lanes[(size_t) going[g]]; |
| 427 | const int d = plan[g]; |
| 428 | Dist q1; |
| 429 | d1[g] = finish(g, d1[g], q1); |
| 430 | if (d == 0) { |
| 431 | L.shadow = d1[g]; |
| 432 | L.shadow_q = q1; |
| 433 | } |
| 434 | if (!look[g].empty() && look[g][0] == d1[g]) { // the lookup stands behind the draft layer's d1, as alone |
| 435 | L.drafts.assign(look[g].begin(), look[g].begin() + d); |
| 436 | L.qs.assign((size_t) d, Dist{}); |
| 437 | if (d > 0) L.qs[0] = std::move(q1); |
| 438 | continue; |
| 439 | } |
nothing calls this directly
no test coverage detected