[vLLM] How to Fix "To use CUDA with multiprocessing, you must use the 'spawn' start method"
When using vLLM on WSL and trying to serve a single LLM across multiple GPUs with tensor parallelism, you will often run into an error like the following.
RuntimeError: Cannot re-initialize CUDA in forked subprocess. To use CUDA with multiprocessing, you must use the 'spawn' start methodA typical scenario where you encounter this is when you specify the tensor parallelism option in vLLM's startup options, as shown below.
--tensor-parallel-size 2In other words, the error is telling you to use "spawn" instead of "fork" when using CUDA with multiprocessing.
To tell vLLM this, set the environment variable as shown on the second line below, and vLLM will use "spawn".
export CUDA_VISIBLE_DEVICES=0,1
export VLLM_WORKER_MULTIPROC_METHOD=spawn