| 1601 | } |
| 1602 | |
| 1603 | bool MtpDrafter::capture_round(int T, bool coupled, std::string& err) { |
| 1604 | cudaGraphExec_t& exec = coupled ? round_exec_c_[T] : round_exec_[T]; |
| 1605 | if (exec) return true; |
| 1606 | using namespace strata::kernels; |
| 1607 | const int64_t HCN = g_->hc * g_->n_embd; |
| 1608 | g_mp.init(); // (its allocation before the capture) |
| 1609 | if (cudaStreamBeginCapture(cs_, cudaStreamCaptureModeThreadLocal) != cudaSuccess) { err = "mtp: begin capture"; return false; } |
| 1610 | g_mp.base = 0; |
| 1611 | bool ok = true; |
| 1612 | // coupled: the request's chain and the penalty history's base, for this round's drafts |
| 1613 | if (coupled) coupled_draft_stage(m_cparams_, m_chist_, cparams_, cring_, kCoupledHistCap, cs_); |
| 1614 | // the catch-up: the layer's front for the window's T cells (their K/V), then its rest for row a only, on row |
| 1615 | // a's intermediates copied to row 0, at the cell the host staged in step row 2*max_t - 1; the draft chain is |
| 1616 | // one graph per step (`capture_step`) so the host can stop it when a draft is unlikely |
| 1617 | const int ra = 2 * max_t_ - 1; |
| 1618 | const int64_t N = g_->n_embd, NH = g_->n_head; |
| 1619 | // the draft round's seven inputs in one launch (STRATA_MTP_MULTI_COPY=0 keeps the separate copies) |
| 1620 | const MappedCopy in[7] = {{tok_, m_tok_, T}, {step_, m_step_, (int64_t) 2 * T * 4}, {pos_, m_pos_, 2 * T * NH}, |
| 1621 | {row_, m_row_, 2}, {Rin_, window_R_, T * HCN}, {step_ + ra * 4, m_step_ + ra * 4, 4}, |
| 1622 | {pos_ + ra * NH, m_pos_ + ra * NH, NH}}; |
| 1623 | copy_from_mapped_multi(in, 7, cs_); |
| 1624 | ok = record_front(T, 0, cs_, err); |
| 1625 | if (ok) { |
| 1626 | if (T > 1) { |
| 1627 | copy_row_to_first(row_, R_, HCN, inj_, g_->hc, mixed_, N, cs_); |
| 1628 | native_quantize_q8_1(mixed_, xq_, (int) N, 1, cs_); |
| 1629 | } |
| 1630 | coupled_rec_ = coupled; |
| 1631 | coupled_j_ = 0; |
| 1632 | ok = record_rest(ra, cs_, err); |
| 1633 | coupled_rec_ = false; |
| 1634 | } |
| 1635 | if (ok) mtp_select(R_, HCN, out_ids_, row_ + 1, Rin_, tok_, m_out_, 0, cs_, probs_, m_prob_); |
| 1636 | if (ok) g_mp.stamp(16, cs_); |
| 1637 | g_mp.base = -1; |
| 1638 | if (ok && force_on_ && !coupled) force_token(tok_, m_force_, 0, cs_); // chain_launch: step 1's input |
| 1639 | return finish_capture(cs_, ok, exec, coupled ? "round (coupled)" : "round", err); |
| 1640 | } |
| 1641 | |
| 1642 | // Chain step j (1..max_t-2): one row at the cell staged in step row `max_t + j - 1`, from the previous step's |
| 1643 | // residual and token (left in Rin_[0] / tok_[0] by mtp_select); draft j and its probability to the mapped outputs. |
nothing calls this directly
no test coverage detected