MCPcopy Create free account
hub / github.com/Niko1221/Strata / capture_commit_batch

Method capture_commit_batch

engine/src/core/verify.cpp:5445–5554  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5443}
5444
5445bool Verifier::capture_commit_batch(const int* rows, int S, int hbase, std::string& err) {
5446 if (batch_self_commits(rows, S)) return true; // the window keeps its rows: no commit graph
5447 cudaGraphExec_t& cex = commit_bm_[bkey(rows, S, hbase)];
5448 if (cex != nullptr) return true;
5449 using namespace strata::kernels;
5450 const ModelGeometry& g = *g_;
5451 const QsaShapes s = shapes_of(g);
5452 const int64_t C = g.ssm_conv_channels, HV = g.ssm_v_heads, ZV = g.ssm_value_dim, ID = g.idx_key_dim, MT = max_t_;
5453 const int64_t CB = 2 + MT, nQ = g.n_qsa_layers();
5454 const uint64_t gdn_floats = (uint64_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size +
5455 (uint64_t) g.ssm_conv_channels * (g.ssm_d_conv - 1);
5456 const int64_t TS = (s.idx_block - 1) * ID;
5457 const int64_t HS = (int64_t) NG_HIST * NG_HC_DIM;
5458 if (cudaStreamBeginCapture(cs_, cudaStreamCaptureModeThreadLocal) != cudaSuccess) {
5459 err = "verify: begin batch commit capture failed";
5460 return false;
5461 }
5462 bool ok = true;
5463 try {
5464 for (int t = 0; t < S; ++t)
5465 if (t == 0 || rows[t] != rows[t - 1])
5466 copy_i32_from_mapped(commitb_ + (size_t) rows[t] * CB, m_commitb_ + (size_t) rows[t] * CB, CB, cs_);
5467 int64_t qsa_index = 0, gdn_index = 0;
5468 for (int64_t l = 0; l < lb_; ++l) (is_qsa_layer(g, l) ? qsa_index : gdn_index) += 1;
5469 for (int64_t l = lb_; l < le_ && ok; ++l) {
5470 const LayerView v(*wt_, l);
5471 if (!is_qsa_layer(g, l)) {
5472 const WeightRef* wnm = need(v, "ssm_norm.weight", err);
5473 if (!wnm) { ok = false; break; }
5474 // STRATA_BATCH_GDN_GROUPS=1: one-row groups (no --batch-mtp proposals) commit their recurrence
5475 // in one launch for all slots; the conv commits stay per slot
5476 bool one_row = S <= 8;
5477 for (int t = 1; one_row && t < S; ++t) one_row = rows[t] != rows[t - 1];
5478 strata::kernels::GdnGroups gg;
5479 for (int t = 0; t < S;) {
5480 const int first = t;
5481 while (t < S && rows[t] == rows[first]) ++t;
5482 SessionState& sx = *slots_[(size_t) rows[first]];
5483 const int32_t* keep = commitb_ + (size_t) rows[first] * CB;
5484 float* state = sx.gdn_state + (size_t) (gdn_index - sx.gdn_ord0) * gdn_floats;
5485 float* conv = state + (uint64_t) g.ssm_state_size * g.ssm_v_heads * g.ssm_state_size;
5486 gdn_conv_commit(conv, qkv_L_ + (size_t) gdn_index * MT * C + (size_t) first * C,
5487 (int) C, keep, cs_);
5488 if (g_batch_gdn_groups && one_row) {
5489 gg.state[gg.n] = state;
5490 gg.keep[gg.n] = keep;
5491 gg.first[gg.n] = first;
5492 gg.ntok[gg.n] = 1;
5493 ++gg.n;
5494 continue;
5495 }
5496 gdn_step_norm_multi(state, h_L_ + (size_t) gdn_index * MT * C + (size_t) first * C, (int) C,
5497 gate_L_ + (size_t) gdn_index * MT * HV + (size_t) first * HV,
5498 beta_L_ + (size_t) gdn_index * MT * HV + (size_t) first * HV,
5499 z_ + (size_t) first * ZV, (const float*) wnm->data, EPS,
5500 y_dummy_ + (size_t) first * ZV, (int) g.ssm_k_heads,
5501 (int) HV, t - first, keep, cs_,
5502 t - first > 1 ? t - first : 0); // a 1-row group keeps the 0.1.39 kernel

Callers

nothing calls this directly

Calls 15

batch_self_commitsFunction · 0.85
is_qsa_layerFunction · 0.85
n_qsa_layersMethod · 0.80
shapes_ofFunction · 0.70
needFunction · 0.70
readyMethod · 0.65
cudaStreamBeginCaptureFunction · 0.50
copy_i32_from_mappedFunction · 0.50
gdn_conv_commitFunction · 0.50
gdn_step_norm_multiFunction · 0.50
gdn_step_norm_groupsFunction · 0.50
copy_from_mappedFunction · 0.50

Tested by

no test coverage detected