lmdeploy icon indicating copy to clipboard operation
lmdeploy copied to clipboard

[Bug] When running lmdeploy serve api_server with the argument --tp 2, one thread consistently consumes 100% CPU even when the API is idle.

Open mizuikki opened this issue 1 year ago • 6 comments

Checklist

  • [x] 1. I have searched related issues but cannot get the expected help.
  • [x] 2. The bug has not been fixed in the latest version.
  • [x] 3. Please note that if the bug-related issue you submitted lacks corresponding environment info and a minimal reproducible demo, it will be challenging for us to reproduce and resolve the issue, reducing the likelihood of receiving feedback.

Describe the bug

When lmdeploy is serving the api_server with args "--tp 2", it leads to 100% CPU usage by a single thread even without user access to the API interface.

When I used the args --tp 1, the CPU usage returned to normal, so it might be an issue related to tensor parallelism.

//--tp=1 Image

//--tp=2 turbomind backend: Image

pytorch backend: Image

Reproduction

lmdeploy serve api_server --backend turbomind --tp 2 Qwen/Qwen3-4B-AWQ
lmdeploy serve api_server --backend pytorch --tp 2 Qwen/Qwen3-4B-AWQ

Environment

sys.platform: linux
Python: 3.10.12 (main, May 27 2025, 17:12:29) [GCC 11.4.0]
CUDA available: True
MUSA available: False
numpy_random_seed: 2147483648
GPU 0,1: Tesla V100-SXM2-16GB
CUDA_HOME: /usr/local/cuda
NVCC: Cuda compilation tools, release 12.4, V12.4.131
GCC: x86_64-linux-gnu-gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
PyTorch: 2.7.1+cu126
PyTorch compiling details: PyTorch built with:
  - GCC 11.2
  - C++ Version: 201703
  - Intel(R) oneAPI Math Kernel Library Version 2024.2-Product Build 20240605 for Intel(R) 64 architecture applications
  - Intel(R) MKL-DNN v3.7.1 (Git Hash 8d263e693366ef8db40acc569cc7d8edf644556d)
  - OpenMP 201511 (a.k.a. OpenMP 4.5)
  - LAPACK is enabled (usually provided by MKL)
  - NNPACK is enabled
  - CPU capability usage: AVX2
  - CUDA Runtime 12.6
  - NVCC architecture flags: -gencode;arch=compute_50,code=sm_50;-gencode;arch=compute_60,code=sm_60;-gencode;arch=compute_70,code=sm_70;-gencode;arch=compute_75,code=sm_75;-gencode;arch=compute_80,code=sm_80;-gencode;arch=compute_86,code=sm_86;-gencode;arch=compute_90,code=sm_90
  - CuDNN 90.5.1
  - Magma 2.6.1
  - Build settings: BLAS_INFO=mkl, BUILD_TYPE=Release, COMMIT_SHA=e2d141dbde55c2a4370fac5165b0561b6af4798b, CUDA_VERSION=12.6, CUDNN_VERSION=9.5.1, CXX_COMPILER=/opt/rh/gcc-toolset-11/root/usr/bin/c++, CXX_FLAGS= -D_GLIBCXX_USE_CXX11_ABI=1 -fvisibility-inlines-hidden -DUSE_PTHREADPOOL -DNDEBUG -DUSE_KINETO -DLIBKINETO_NOROCTRACER -DLIBKINETO_NOXPUPTI=ON -DUSE_FBGEMM -DUSE_PYTORCH_QNNPACK -DUSE_XNNPACK -DSYMBOLICATE_MOBILE_DEBUG_HANDLE -O2 -fPIC -Wall -Wextra -Werror=return-type -Werror=non-virtual-dtor -Werror=range-loop-construct -Werror=bool-operation -Wnarrowing -Wno-missing-field-initializers -Wno-unknown-pragmas -Wno-unused-parameter -Wno-strict-overflow -Wno-strict-aliasing -Wno-stringop-overflow -Wsuggest-override -Wno-psabi -Wno-error=old-style-cast -fdiagnostics-color=always -faligned-new -Wno-maybe-uninitialized -fno-math-errno -fno-trapping-math -Werror=format -Wno-stringop-overflow, LAPACK_INFO=mkl, PERF_WITH_AVX=1, PERF_WITH_AVX2=1, TORCH_VERSION=2.7.1, USE_CUDA=ON, USE_CUDNN=ON, USE_CUSPARSELT=1, USE_GFLAGS=OFF, USE_GLOG=OFF, USE_GLOO=ON, USE_MKL=ON, USE_MKLDNN=ON, USE_MPI=OFF, USE_NCCL=1, USE_NNPACK=ON, USE_OPENMP=ON, USE_ROCM=OFF, USE_ROCM_KERNEL_ASSERT=OFF,

TorchVision: 0.22.1+cu126
LMDeploy: 0.9.2+9098ae8
transformers: 4.54.0
gradio: 5.38.2
fastapi: 0.116.1
pydantic: 2.11.7
triton: 3.3.1
NVIDIA Topology:
        GPU0    GPU1    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      PHB     0-11    0               N/A
GPU1    PHB      X      0-11    0               N/A

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

Error traceback


mizuikki avatar Jul 27 '25 13:07 mizuikki

pytorch backend would start a MPEngine to isolate engine and server process. It will query request in a while True loop again and again so we can start the model inference ASAP.

https://github.com/InternLM/lmdeploy/blob/5f0647f1181312975f05d16eeb166d5a69afb6ef/lmdeploy/pytorch/engine/mp_engine/zmq_rpc.py#L166

grimoire avatar Jul 28 '25 06:07 grimoire

Regarding turbomind engine, @lzhangzz could you investigate it?

lvhan028 avatar Jul 29 '25 03:07 lvhan028

TurboMind's current broadcast implementation use a busy CAS loop to synchronize the ranks. I will try to make it switch to a blocking barrier when a max retry count is reached.

lzhangzz avatar Jul 29 '25 06:07 lzhangzz

We have already optimized the PyTorch Engine to avoid the 100% CPU issue in #3766

windreamer avatar Aug 10 '25 03:08 windreamer

We have already optimized the PyTorch Engine to avoid the 100% CPU issue in #3766

The issue has been confirmed as fixed with the PyTorch engine and is pending a fix from the Turbomind engine.

mizuikki avatar Aug 10 '25 09:08 mizuikki

Both engines have resolved this issue. May try the latest main.

lvhan028 avatar Sep 17 '25 06:09 lvhan028