From cac81b6eda418fb5ca86b81197914dd02666353e Mon Sep 17 00:00:00 2001 From: Tianmu Li Date: Mon, 18 May 2026 03:04:41 -0700 Subject: [PATCH] [CPU Backend] Improve cpu thread utilization (#42666) Signed-off-by: Li, Tianmu Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> --- csrc/cpu/cpu_attn_impl.hpp | 2 +- vllm/utils/ompmultiprocessing.py | 8 +++----- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/csrc/cpu/cpu_attn_impl.hpp b/csrc/cpu/cpu_attn_impl.hpp index 72c96252b6..2d0859a13d 100644 --- a/csrc/cpu/cpu_attn_impl.hpp +++ b/csrc/cpu/cpu_attn_impl.hpp @@ -459,7 +459,7 @@ class AttentionScheduler { const int64_t kv_len_per_thread = (((total_kv_len / thread_num) + kv_len_alignment - 1) / kv_len_alignment) * - kv_len_alignment * (use_gqa ? input.num_heads_kv : input.num_heads_q); + kv_len_alignment; std::vector workitems; std::vector reduce_workitems; workitems.reserve(1024); diff --git a/vllm/utils/ompmultiprocessing.py b/vllm/utils/ompmultiprocessing.py index 6e7b8c3496..711f527355 100644 --- a/vllm/utils/ompmultiprocessing.py +++ b/vllm/utils/ompmultiprocessing.py @@ -84,13 +84,11 @@ class OMPProcessManager: ) # The time(milliseconds) that a thread should wait after # completing the execution of a parallel region, before sleeping. - envs_dict["KMP_BLOCKTIME"] = "1" + # A value of 5 masks thread underutilization. + # Set to 1 when debugging thread utilization issues. + envs_dict["KMP_BLOCKTIME"] = "5" # Prevents the CPU to run into low performance state envs_dict["KMP_TPAUSE"] = "0" - # Provides fine granularity parallelism - envs_dict["KMP_FORKJOIN_BARRIER_PATTERN"] = "dist,dist" - envs_dict["KMP_PLAIN_BARRIER_PATTERN"] = "dist,dist" - envs_dict["KMP_REDUCTION_BARRIER_PATTERN"] = "dist,dist" elif self.use_gomp: # set GOMP envs # likes '0 1 2 ...'