﻿# ONNX Runtime CPU attention: internal QKV transposes need the operator thread pool too

The 1.32 CPU attention change threads internal QKV movement; verify actual operator threading and keep fused-versus-unfused comparisons numerically matched.

Author: Retrivium team
Updated: 2026-11-15
Canonical URL: https://retrivium.ai/journal/week46-engine-ort-cpu-attention-qkv-threadpool/
Language: en

ONNX Runtime 1.32.0 release notes include parallelizing CPU MultiHeadAttention QKV transposes. The linked work identifies a path where internal copies omitted the operator thread pool even though standalone transpose operations used it. A fused operator can therefore be numerically correct yet slower than a decomposed graph because its auxiliary data movement is serialized.

## Fusion does not guarantee parallel auxiliary work

A fused node can still call several internal transformations. If one ignores the available thread pool, removing graph-level nodes can reduce visible scheduling while leaving more serialized work inside. A proposed profile separates QKV layout movement from attention arithmetic. Compare with the equivalent unfused graph under the same thread budget, rather than assuming that the version with fewer operators must be the faster implementation.

## Thread count must be an effective setting

Record intra-operator settings and the actual thread pool used by the session. A process-level thread count alone does not show whether this transpose received parallel workers. A proposed test includes one worker and several workers with identical input shape. Keep concurrent requests controlled so inter-request parallelism does not masquerade as a faster internal transpose. CPU affinity and other workload should be documented when interpreting timing differences.

## Bias variants can select different internals

The linked description distinguishes attention bias from projection bias and covers multiple query lengths and value-head sizes. Preserve those inputs explicitly. A test that changes both bias form and thread count can inadvertently compare different operator paths. Use distinct Q, K and V values and compare against a scalar or trusted attention reference, ensuring parallel copying preserves the intended order instead of merely completing sooner.

## A reported reproduction is not a universal CPU ratio

The release reports the optimization and the PR supplies its own focused performance observation. This article adds no independent timing result. A useful local assessment verifies dispatch, numerical parity and the attention operator’s share of total latency before projecting an application benefit. A model dominated by other kernels can legitimately show little end-to-end change even when the internal transpose is substantially improved.

## Sources

- [ONNX Runtime v1.32.0 release](https://github.com/microsoft/onnxruntime/releases/tag/v1.32.0)
- [ONNX Runtime pull request #33887](https://github.com/microsoft/onnxruntime/pull/33887)

## Related reading

- [Tune llama.cpp CPU threads separately for prefill and decode](/journal/llama-cpp-prefill-decode-cpu-threads/)
- [CUDA events and request time: different measurement boundaries](/journal/gpu-cuda-events-wall-time/)
