Skip to content

audio_exec: per-node timing, because the op totals cannot apportion their own MatMul row (engine#2366) - #2377

Merged
bong-water-water-bong merged 1 commit into
mainfrom
npu-node-times
Nov 13, 2026
Merged

bong-water-water-bong merged 1 commit into
mainfrom
npu-node-times

Conversation

@bong-water-water-bong

Copy link
Copy Markdown
Collaborator

Why this exists. ONEBIT_AUDIO_OP_TIMES=1 reports one MatMul row for the whisper encoder — 96 nodes, 6.87 s on a quiet box. That row contains 72 projections (q/k/v/o as four launches per layer, plus fc1 and fc2) and 24 attention products (Q·Kᵀ and scores·V). Apportioning it by node count is how I reported a 0.39 s family as 1.7 s on #2366, twice, and had to retract both.

ONEBIT_AUDIO_NODE_TIMES=1 prints one line per node, in graph order, with the output shape the executor already has in hand:

[audio-node]    1 Conv               1x768x3000                76.348 ms
[audio-node]    2 Div                1x768x3000                 5.947 ms
[audio-node]    3 Erf                1x768x3000                 5.267 ms
…
[audio-node] 447 …

Then the split is readable per shape instead of per op type. On whisper-small (encoder 30.80 s at this box's load, 447 nodes):

shape nodes time what it is
1x1500x768 60 10.887 s q/k/v/o (48) + fc2 (12)
1x1500x3072 12 5.494 s fc1
1x12x1500x1500 12 2.621 s Q·Kᵀ
1x12x1500x64 12 2.541 s scores·V

projections 16.38 s (53 %), attention 5.16 s (17 %), the rest 9.26 s (30 %) — and the attention/projection ratio (0.31) is what holds across loads, which is the number #2366 needed and did not have.

Cost and scope: a std::string per node when the variable is set, and nothing when it is not (the executor already times every node for the totals). No new dependency, no new file; the print sits beside the existing [audio-op] block. A decode step prints its own 786-node block per token, so the variable is for a single encoder pass, not for a served run.

…ate 72 projections from 24 attention products (engine#2366)
@github-actions

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

2366 - Partially compliant

Compliant requirements:

  • Implements ONEBIT_AUDIO_NODE_TIMES=1 functionality to output per-node timing
  • Provides accurate node-level timing data in graph order with output shapes
  • Enables proper apportioning of compute costs by shape instead of op type

Non-compliant requirements:

  • Does not include the actual kernel optimizations or performance improvements for Conv, Softmax, or attention operations mentioned in the issue

Requires further human verification:

  • Verification that the timing measurements are accurate and match the hardware performance
  • Confirmation that the node-level timing data correctly reflects the compute costs for different shapes as described in the issue
⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
🧪 No relevant tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Node Timing Implementation

The PR introduces per-node timing functionality via ONEBIT_AUDIO_NODE_TIMES=1, which is essential for accurately apportioning compute costs in the audio encoder. However, this change only provides the instrumentation for timing collection and does not address the actual performance bottlenecks identified in the issue (Conv, Softmax, attention operations). The implementation correctly logs timing per node in graph order with output shapes, but the performance improvements needed to reduce the encoder time from 21.7 s to 0.6 s per 30 s window are not included in this PR.

// ONEBIT_AUDIO_NODE_TIMES=1 (engine#2366): one line per node, in graph order, with the output shape. The op totals
// below collapse the 72 projections and the 24 attention products into one `MatMul` row, and apportioning that row by
// node count is how a 0.39 s family was reported as 1.7 s. The executor already times every node to build the totals,
// so this costs a string per node and nothing else.
const char* nt = std::getenv("ONEBIT_AUDIO_NODE_TIMES");
const bool node_times = nt != nullptr && nt[0] != '\0' && nt[0] != '0';
std::vector<std::string> node_lines;
auto finish_node = [&](const std::string& op, const std::string& name, Tensor& res,
                       std::chrono::steady_clock::time_point t0) {
    if (node_times) {
        std::string shape;
        for (int64_t d : res.dims) shape += (shape.empty() ? "" : "x") + std::to_string(d);
        char line[220];
        std::snprintf(line, sizeof line, "[audio-node] %4d %-18s %-22s %9.3f ms\n", int(node_lines.size()) + 1,
                      op.c_str(), shape.c_str(),
                      std::chrono::duration<double, std::milli>(std::chrono::steady_clock::now() - t0).count());
        node_lines.emplace_back(line);
    }

@bong-water-water-bong bong-water-water-bong left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

VERDICT at b366a00: READY

Reviewed by cl-856. I built the PR head merged with main (c41cd1b, merges clean) into whisper_transcribe and ran one host-only encoder pass under thermal-run at 4 threads. The run used whisper-small on jfk.wav with ONEBIT_AUDIO_NODE_TIMES=1 ONEBIT_AUDIO_OP_TIMES=1.

  • rc=0, and the transcript ids match the reference decode. Encoder 8.499 s.
  • The encoder block has 447 [audio-node] lines, then [audio-node] 447 node(s). The printed index equals the graph position on every line (0 mismatches).
  • The per-node times sum to 8302.9 ms, against the [audio-op] total of 8306.0 ms. Each op's sum matches its [audio-op] row within 0.3 ms (MatMul 5509.0 vs 5510.3; Softmax 724.4 vs 724.6; Conv 441.5 vs 441.5).
  • The node counts by shape are as the body states:
shape nodes this run
1x1500x768 60 2949.6 ms
1x1500x3072 12 1098.0 ms
1x12x1500x1500 (Q·Kᵀ) 12 675.8 ms
1x12x1500x64 (scores·V) 12 785.6 ms

Non-blocking:

  1. The ratio is load-dependent. In this run, attention/projections is 1461/4048 = 0.36, not 0.31. The body says 0.31 "holds across loads", but one quiet 4-thread run already gives 0.36. #2366 should quote it as a range, or with its load stated.
  2. The index is node_lines.size() + 1, not the loop's node_index. They are equal today because every path that does not fail() ends in finish_node. Passing node_index would keep them equal if a future path continues past it, and it would match the node N (op) text in where().
  3. As the body says, a decode prints a 786-line block per token. This run printed 25 of them (20,883 lines in all).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant