Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method #8893

Open
Hothan01 opened this issue Sep 27, 2024 · 7 comments
Labels
usage How to use vllm

Comments

@Hothan01
Copy link

Hothan01 commented Sep 27, 2024

I have updated to the latest version and used the “spawn” method,
export VLLM_WORKER_MULTIPROC_METHOD=spawn
but the error still persists. Could you please help me?

@Hothan01 Hothan01 added the usage How to use vllm label Sep 27, 2024
@Hothan01
Copy link
Author

my code

from vllm import LLM, SamplingParams
import torch

# # 检查是否有GPU可用
device = "cuda" if torch.cuda.is_available() else "cpu"

# 推理数据以List[str]格式组织
prompts = [
    "Hello, my name is",
    "The president of the United States is",
    "The capital of France is",
    "The future of AI is",
]

# 设置采样参数
sampling_params = SamplingParams(temperature=0.8, top_p=0.95)

# 加载模型,并指定设备为GPU
llm = LLM(model="Qwen/Qwen2.5-32B-Instruct", device=device, tensor_parallel_size=2, trust_remote_code=True)

# 执行推理
outputs = llm.generate(prompts, sampling_params)

# 输出推理结果
for output in outputs:
    prompt = output.prompt
    generated_text = output.outputs[0].text
    print(f"Prompt: {prompt!r}, Generated text: {generated_text!r}")

@jeejeelee
Copy link
Contributor

You can try commenting out or deleting :

 'device = "cuda" if torch.cuda.is_available() else "cpu"

@Hothan01
Copy link
Author

Thanks, it works.
But I got an error:

ERROR 09-27 17:51:52 multiproc_worker_utils.py:120] Worker VllmWorkerProcess pid 26713 died, exit code: 1
INFO 09-27 17:51:52 multiproc_worker_utils.py:123] Killing local vLLM worker processes
Processed prompts:   0%|          | 0/4 [00:00<?, ?it/s, est. speed input: 0.00 toks/s, output: 0.00 toks/s]
Processed prompts:  25%|██▌       | 1/4 [00:00<00:00,  3.73it/s, est. speed input: 22.37 toks/s, output: 59.64 toks/s]
Processed prompts: 100%|██████████| 4/4 [00:00<00:00, 14.90it/s, est. speed input: 96.85 toks/s, output: 238.40 toks/s]
[rank0]:[W927 17:49:14.927366122 CudaIPCTypes.cpp:16] Producer process has been terminated before all shared CUDA tensors released. See Note [Sharing CUDA tensors]
/home/test/test07/miniconda3/envs/op/lib/python3.10/multiprocessing/resource_tracker.py:224: UserWarning: resource_tracker: There appear to be 1 leaked shared_memory objects to clean up at shutdown
  warnings.warn('resource_tracker: There appear to be %d '

@DarkLight1337
Copy link
Member

Can you show the full stack trace?

@Hothan01
Copy link
Author

Here:

INFO 09-27 18:05:57 config.py:899] Defaulting to use mp for distributed inference
WARNING 09-27 18:05:57 arg_utils.py:930] Chunked prefill is enabled by default for models with max_model_len > 32K. Currently, chunked prefill might not work with some features or models. If you encounter any issues, please disable chunked prefill by setting --enable-chunked-prefill=False.
INFO 09-27 18:05:57 config.py:1010] Chunked prefill is enabled with max_num_batched_tokens=512.
INFO 09-27 18:05:57 llm_engine.py:226] Initializing an LLM engine (v0.6.1.dev238+ge2c6e0a82) with config: model='/home/test/test07/hechaoqun/download_models/internlm/internlm2-chat-7b', speculative_config=None, tokenizer='/home/test/test07/hechaoqun/download_models/internlm/internlm2-chat-7b', skip_tokenizer_init=False, tokenizer_mode=auto, revision=None, override_neuron_config=None, rope_scaling=None, rope_theta=None, tokenizer_revision=None, trust_remote_code=True, dtype=torch.bfloat16, max_seq_len=65536, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=2, pipeline_parallel_size=1, disable_custom_all_reduce=False, quantization=None, enforce_eager=False, kv_cache_dtype=auto, quantization_param_path=None, device_config=cuda, decoding_config=DecodingConfig(guided_decoding_backend='outlines'), observability_config=ObservabilityConfig(otlp_traces_endpoint=None, collect_model_forward_time=False, collect_model_execute_time=False), seed=0, served_model_name=/home/test/test07/hechaoqun/download_models/internlm/internlm2-chat-7b, use_v2_block_manager=False, num_scheduler_steps=1, multi_step_stream_outputs=False, enable_prefix_caching=False, use_async_output_proc=True, use_cached_outputs=False, mm_processor_kwargs=None)
INFO 09-27 18:05:57 custom_cache_manager.py:17] Setting Triton cache manager to: vllm.triton_utils.custom_cache_manager:CustomCacheManager
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:05:58 multiproc_worker_utils.py:218] Worker ready; awaiting tasks
INFO 09-27 18:05:59 utils.py:992] Found nccl from library libnccl.so.2
INFO 09-27 18:05:59 pynccl.py:63] vLLM is using nccl==2.20.5
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:05:59 utils.py:992] Found nccl from library libnccl.so.2
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:05:59 pynccl.py:63] vLLM is using nccl==2.20.5
INFO 09-27 18:06:02 custom_all_reduce_utils.py:242] reading GPU P2P access cache from /home/test/test07/.cache/vllm/gpu_p2p_access_cache_for_0,1.json
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:02 custom_all_reduce_utils.py:242] reading GPU P2P access cache from /home/test/test07/.cache/vllm/gpu_p2p_access_cache_for_0,1.json
INFO 09-27 18:06:02 shm_broadcast.py:241] vLLM message queue communication handle: Handle(connect_ip='127.0.0.1', local_reader_ranks=[1], buffer=<vllm.distributed.device_communicators.shm_broadcast.ShmRingBuffer object at 0x7f4c46bce380>, local_subscribe_port=60099, remote_subscribe_port=None)
INFO 09-27 18:06:02 model_runner.py:1014] Starting to load model /home/test/test07/hechaoqun/download_models/internlm/internlm2-chat-7b...
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:02 model_runner.py:1014] Starting to load model /home/test/test07/hechaoqun/download_models/internlm/internlm2-chat-7b...
INFO 09-27 18:06:11 model_runner.py:1025] Loading model weights took 7.2232 GB
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:11 model_runner.py:1025] Loading model weights took 7.2232 GB
INFO 09-27 18:06:16 distributed_gpu_executor.py:57] # GPU blocks: 63651, # CPU blocks: 4096
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:19 model_runner.py:1329] Capturing the model for CUDA graphs. This may lead to unexpected consequences if the model is not static. To run the model in eager mode, set 'enforce_eager=True' or use '--enforce-eager' in the CLI.
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:19 model_runner.py:1333] CUDA graphs can take additional 1~3 GiB memory per GPU. If you are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. You can also reduce the `max_num_seqs` as needed to decrease memory usage.
INFO 09-27 18:06:19 model_runner.py:1329] Capturing the model for CUDA graphs. This may lead to unexpected consequences if the model is not static. To run the model in eager mode, set 'enforce_eager=True' or use '--enforce-eager' in the CLI.
INFO 09-27 18:06:19 model_runner.py:1333] CUDA graphs can take additional 1~3 GiB memory per GPU. If you are running out of memory, consider decreasing `gpu_memory_utilization` or enforcing eager mode. You can also reduce the `max_num_seqs` as needed to decrease memory usage.
INFO 09-27 18:06:43 custom_all_reduce.py:229] Registering 2275 cuda graph addresses
INFO 09-27 18:06:43 model_runner.py:1456] Graph capturing finished in 24 secs.
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:43 custom_all_reduce.py:229] Registering 2275 cuda graph addresses
�[1;36m(VllmWorkerProcess pid=28018)�[0;0m INFO 09-27 18:06:43 model_runner.py:1456] Graph capturing finished in 24 secs.
Prompt: 'Hello, my name is', Generated text: ' Lorena. I am a native Spanish speaker who loves teaching Spanish to anyone who'
Prompt: 'The president of the United States is', Generated text: ' the head of state of the United States and is further empowered to grant federal'
Prompt: 'The capital of France is', Generated text: ' Paris. The population of the city is about 2.1 million. Paris'
Prompt: 'The future of AI is', Generated text: ' bright\nArtificial Intelligence (AI) is an ever-evolving technology,'
ERROR 09-27 18:06:45 multiproc_worker_utils.py:120] Worker VllmWorkerProcess pid 28018 died, exit code: -15
INFO 09-27 18:06:45 multiproc_worker_utils.py:124] Killing local vLLM worker processes

@DarkLight1337
Copy link
Member

Can you run collect_env.py and post the output? cc @youkaichao

@Hothan01
Copy link
Author

PyTorch version: 2.4.0+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: CentOS Linux 7 (Core) (x86_64)
GCC version: (conda-forge gcc 10.4.0-17) 10.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.17

Python version: 3.10.14 (main, May  6 2024, 19:42:50) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-3.10.0-1160.el7.x86_64-x86_64-with-glibc2.17
Is CUDA available: True
CUDA runtime version: 12.1.66
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: 
GPU 0: NVIDIA A800-SXM4-80GB
GPU 1: NVIDIA A800-SXM4-80GB
GPU 2: NVIDIA A800-SXM4-80GB
GPU 3: NVIDIA A800-SXM4-80GB
GPU 4: NVIDIA A800-SXM4-80GB
GPU 5: NVIDIA A800-SXM4-80GB
GPU 6: NVIDIA A800-SXM4-80GB
GPU 7: NVIDIA A800-SXM4-80GB

Nvidia driver version: 535.183.06
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:          x86_64
CPU op-mode(s):        32-bit, 64-bit
Byte Order:            Little Endian
CPU(s):                104
On-line CPU(s) list:   0-103
Thread(s) per core:    1
Core(s) per socket:    52
Socket(s):             2
NUMA node(s):          2
Vendor ID:             GenuineIntel
CPU family:            6
Model:                 143
Model name:            Intel(R) Xeon(R) Platinum 8470
Stepping:              8
CPU MHz:               3799.926
CPU max MHz:           3800.0000
CPU min MHz:           800.0000
BogoMIPS:              4000.00
Virtualization:        VT-x
L1d cache:             48K
L1i cache:             32K
L2 cache:              2048K
L3 cache:              107520K
NUMA node0 CPU(s):     0-51
NUMA node1 CPU(s):     52-103
Flags:                 fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc aperfmperf eagerfpu pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch epb cat_l3 cat_l2 cdp_l3 invpcid_single intel_pt cdp_l2 ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts hwp hwp_act_window hwp_epp hwp_pkg_req avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq cldemote movdiri movdir64b md_clear pconfig spec_ctrl intel_stibp flush_l1d arch_capabilities

Versions of relevant libraries:
[pip3] numpy==1.26.4
[pip3] nvidia-cublas-cu12==12.1.3.1
[pip3] nvidia-cuda-cupti-cu12==12.1.105
[pip3] nvidia-cuda-nvrtc-cu12==12.1.105
[pip3] nvidia-cuda-runtime-cu12==12.1.105
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.0.2.54
[pip3] nvidia-curand-cu12==10.3.2.106
[pip3] nvidia-cusolver-cu12==11.4.5.107
[pip3] nvidia-cusparse-cu12==12.1.0.106
[pip3] nvidia-ml-py==12.560.30
[pip3] nvidia-nccl-cu12==2.20.5
[pip3] nvidia-nvjitlink-cu12==12.6.68
[pip3] nvidia-nvtx-cu12==12.1.105
[pip3] pyzmq==26.2.0
[pip3] sentence-transformers==2.2.2
[pip3] torch==2.4.0
[pip3] torchvision==0.19.0
[pip3] transformers==4.45.1
[pip3] triton==3.0.0
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] nvidia-cublas-cu12        12.1.3.1                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.1.105                 pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.1.105                 pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.1.105                 pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.1.0.70                 pypi_0    pypi
[conda] nvidia-cufft-cu12         11.0.2.54                pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.2.106               pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.4.5.107               pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.1.0.106               pypi_0    pypi
[conda] nvidia-ml-py              12.560.30                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.20.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.6.68                  pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.1.105                 pypi_0    pypi
[conda] pyzmq                     26.2.0                   pypi_0    pypi
[conda] sentence-transformers     2.2.2                    pypi_0    pypi
[conda] torch                     2.4.0                    pypi_0    pypi
[conda] torchvision               0.19.0                   pypi_0    pypi
[conda] transformers              4.45.1                   pypi_0    pypi
[conda] triton                    3.0.0                    pypi_0    pypi
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.6.1.dev238+ge2c6e0a82
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    NIC0    NIC1    NIC2    NIC3    NIC4    NIC5    NIC6    NIC7    NIC8    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      NV8     NV8     NV8     NV8     NV8     NV8     NV8     PXB     NODE    NODE    NODE    SYS     SYS     SYS     SYS     SYS     0-51    0               N/A
GPU1    NV8      X      NV8     NV8     NV8     NV8     NV8     NV8     NODE    PXB     NODE    NODE    SYS     SYS     SYS     SYS     SYS     0-51    0               N/A
GPU2    NV8     NV8      X      NV8     NV8     NV8     NV8     NV8     NODE    NODE    PXB     NODE    SYS     SYS     SYS     SYS     SYS     0-51    0               N/A
GPU3    NV8     NV8     NV8      X      NV8     NV8     NV8     NV8     NODE    NODE    NODE    PXB     SYS     SYS     SYS     SYS     SYS     0-51    0               N/A
GPU4    NV8     NV8     NV8     NV8      X      NV8     NV8     NV8     SYS     SYS     SYS     SYS     PXB     NODE    NODE    NODE    NODE    52-103  1               N/A
GPU5    NV8     NV8     NV8     NV8     NV8      X      NV8     NV8     SYS     SYS     SYS     SYS     NODE    NODE    PXB     NODE    NODE    52-103  1               N/A
GPU6    NV8     NV8     NV8     NV8     NV8     NV8      X      NV8     SYS     SYS     SYS     SYS     NODE    NODE    NODE    PXB     NODE    52-103  1               N/A
GPU7    NV8     NV8     NV8     NV8     NV8     NV8     NV8      X      SYS     SYS     SYS     SYS     NODE    NODE    NODE    NODE    PXB     52-103  1               N/A
NIC0    PXB     NODE    NODE    NODE    SYS     SYS     SYS     SYS      X      NODE    NODE    NODE    SYS     SYS     SYS     SYS     SYS
NIC1    NODE    PXB     NODE    NODE    SYS     SYS     SYS     SYS     NODE     X      NODE    NODE    SYS     SYS     SYS     SYS     SYS
NIC2    NODE    NODE    PXB     NODE    SYS     SYS     SYS     SYS     NODE    NODE     X      NODE    SYS     SYS     SYS     SYS     SYS
NIC3    NODE    NODE    NODE    PXB     SYS     SYS     SYS     SYS     NODE    NODE    NODE     X      SYS     SYS     SYS     SYS     SYS
NIC4    SYS     SYS     SYS     SYS     PXB     NODE    NODE    NODE    SYS     SYS     SYS     SYS      X      NODE    NODE    NODE    NODE
NIC5    SYS     SYS     SYS     SYS     NODE    NODE    NODE    NODE    SYS     SYS     SYS     SYS     NODE     X      NODE    NODE    NODE
NIC6    SYS     SYS     SYS     SYS     NODE    PXB     NODE    NODE    SYS     SYS     SYS     SYS     NODE    NODE     X      NODE    NODE
NIC7    SYS     SYS     SYS     SYS     NODE    NODE    PXB     NODE    SYS     SYS     SYS     SYS     NODE    NODE    NODE     X      NODE
NIC8    SYS     SYS     SYS     SYS     NODE    NODE    NODE    PXB     SYS     SYS     SYS     SYS     NODE    NODE    NODE    NODE     X 

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

NIC Legend:

  NIC0: mlx5_0
  NIC1: mlx5_1
  NIC2: mlx5_2
  NIC3: mlx5_3
  NIC4: mlx5_4
  NIC5: mlx5_5
  NIC6: mlx5_6
  NIC7: mlx5_7
  NIC8: mlx5_8

@Hothan01 Hothan01 changed the title [Usage]: RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method [Bug]: RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start method Sep 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
usage How to use vllm
Projects
None yet
Development

No branches or pull requests

3 participants