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

Function block_layer_post

engine/src/core/layer.cpp:1642–1666  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1640}
1641
1642bool block_layer_post(const WeightTable& tables, const ModelGeometry& g, int64_t layer, int64_t k, const MoEBuffers& mb, const BlockBuffers& bb, const float* parts, void* stream, std::string& err) { const strata::kernels::GrShapes gs{g.n_embd, g.hc, g.hc_lr};
1643// `bb.mixed` and `bb.inject` are what `block_layer_pre` left, and NOTHING between the two calls may touch
1644// them - that is what makes `post[l]` safe to launch after the host has run the pool.
1645st_begin(layer, 5, stream);
1646 if (g_shared_early ? !moe_combine_parts(g, layer, k, mb, parts, bb.block_out, stream, err)
1647 : !moe_finish(tables, g, layer, k, mb, bb.mixed, parts, bb.block_out, stream, err)) return false;
1648 st_end(layer, 5, stream); dump_half(bb, g, layer, bb.block_out, (uint64_t) g.n_embd, g.n_embd, stream); dump_half(bb, g, layer, bb.inject, (uint64_t) 2 * g.n_embd + g.hc, g.hc, stream); st_begin(layer, 6, stream);
1649 const bool steer = strata::kernels::cvec().covers(layer); // --control-vector-scaled: after this write
1650 try {
1651 if (!(g_fused_gr && strata::kernels::fused_gr_supported(g.n_embd, g.hc, g.hc_lr))) {
1652 gr_write(bb.R, bb.block_out, bb.inject, gs, bb.R, stream);
1653 if (steer) strata::kernels::cvec_apply(bb.R, layer, 1, g.hc * g.n_embd, nullptr, 0, nullptr, 0, false, stream);
1654 } else if (layer == g.n_layers - 1) {
1655 gr_write(bb.R, bb.block_out, bb.inject2, gs, bb.R, stream); // materialise R for the head
1656 if (steer) strata::kernels::cvec_apply(bb.R, layer, 1, g.hc * g.n_embd, nullptr, 0, nullptr, 0, false, stream);
1657 } else if (steer) {
1658 // the write the next layer's fused read would have folded, then the vector
1659 strata::kernels::cvec_apply(bb.R, layer, 1, g.hc * g.n_embd, bb.block_out, g.n_embd, bb.inject2, g.hc,
1660 true, stream);
1661 }
1662 } catch (const std::exception& e) {
1663 err = std::string("block_layer_post: ") + e.what();
1664 return false;
1665 }
1666 st_end(layer, 6, stream); return true;}
1667bool block_layer(const WeightTable& tables, const ModelGeometry& g, int64_t layer, int64_t pos, int32_t pos_base, const GdnBuffers& gb, const QsaState& qst, const QsaBuffers& qb, const MoEBuffers& mb, int64_t k, const BlockBuffers& bb, const float* parts, void* stream, std::string& err, const Doorbell* db, const PleRun* ple) {
1668// The two halves back to back. `parts` must be THIS layer's experts and must be ready before the call -
1669// which holds for `session_token`, where the caller supplies them, and does NOT hold for a host loop that

Callers 3

block_layerFunction · 0.70
session_captureFunction · 0.70
session_capture_tokenFunction · 0.70

Calls 10

coversMethod · 0.80
st_beginFunction · 0.70
moe_combine_partsFunction · 0.70
moe_finishFunction · 0.70
st_endFunction · 0.70
dump_halfFunction · 0.70
fused_gr_supportedFunction · 0.50
gr_writeFunction · 0.50
cvec_applyFunction · 0.50
stringFunction · 0.50

Tested by

no test coverage detected