mirror of
https://github.com/iafiscal1212/diffuse-cpp.git
synced 2026-12-04 00:28:08 +00:00
Fix layer profiling: add profile tensors to forward graph
Profile tensors (limp.XX) were created but never added to ggml_build_forward_expand, so they were never computed (all 0.0). Now collected in a vector and added after the main forward tensor. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
46e9dc1fbe
commit
1d2bd6a2e6
1 file changed
+12
-1
+12
-1
@@ -86,6 +86,9 @@ static struct ggml_cgraph * ar_build_graph(
|
||||
// ── Embedding lookup ─────────────────────────────────────────
|
||||
struct ggml_tensor * cur = ggml_get_rows(ctx, model.tok_embd, inp_tokens);
|
||||
|
||||
// Profile tensors collected here, added to graph after main forward
|
||||
std::vector<struct ggml_tensor *> profile_tensors;
|
||||
|
||||
// ── Transformer layers ───────────────────────────────────────
|
||||
for (int il = 0; il < n_layer; il++) {
|
||||
// Layer skip (VSIDS-inspired): skip least important layers during decode
|
||||
@@ -226,6 +229,7 @@ static struct ggml_cgraph * ar_build_graph(
|
||||
snprintf(name_buf, sizeof(name_buf), "limp.%02d", il);
|
||||
ggml_set_name(dsq, name_buf);
|
||||
ggml_set_output(dsq);
|
||||
profile_tensors.push_back(dsq);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -243,6 +247,13 @@ static struct ggml_cgraph * ar_build_graph(
|
||||
ggml_set_output(cur);
|
||||
|
||||
ggml_build_forward_expand(gf, cur);
|
||||
|
||||
// Add profiling tensors to forward graph (they depend on layer outputs
|
||||
// already in the graph, so only sub/sqr/sum nodes get added)
|
||||
for (auto * pt : profile_tensors) {
|
||||
ggml_build_forward_expand(gf, pt);
|
||||
}
|
||||
|
||||
return gf;
|
||||
}
|
||||
|
||||
@@ -473,7 +484,7 @@ bool ar_profile_layers(
|
||||
// Report top/bottom layer impacts
|
||||
DIFFUSE_LOG(" lowest impact layers:");
|
||||
for (int i = 0; i < std::min(n_skip + 4, n_layer); i++) {
|
||||
DIFFUSE_LOG(" layer %2d: impact = %.2f%s",
|
||||
DIFFUSE_LOG(" layer %2d: impact = %.6e%s",
|
||||
ranked[i].second, ranked[i].first,
|
||||
(ranked[i].second < 2 || ranked[i].second >= n_layer - 2)
|
||||
? " [PROTECTED]" : "");
|
||||
|
||||
Reference in new issue
Block a user