[Python] Debugging vLLM with debugpy on WSL fails: AttributeError: module 'ray' has no...

Discussão em 'Python' iniciado por Stack, Setembro 10, 2025.

  1. Stack

    Stack Membro Participativo

    I’m trying to debug my Python code with debugpy in VS Code on WSL (Ubuntu).

    Environment:


    • Python: 3.12.3 (venv)


    • vLLM: 0.10.1.1+cpu


    • debugpy: ms-python.debugpy-2025.10.0 (from VS Code extension)


    • Model: Tiny LLM downloaded from Hugging Face


    • Running inside WSL2 (Ubuntu)

    Code (run-model.py):


    from vllm import LLM, SamplingParams

    def main():
    llm = LLM(model="./Tiny-LLM")
    params = SamplingParams(temperature=0.7, max_tokens=200)
    prompt = "Once upon a time in a magical forest,"

    for output in llm.generate([prompt], sampling_params=params):
    print(output.outputs[0].text)

    if __name__ == "__main__":
    main()

    When I run this script normally in the terminal, it works and generates text.

    But when I run it with debugpy in VS Code, I get:

    AttributeError: module 'ray' has no attribute 'is_initialized'


    Traceback (excerpt):

    File ".../vllm/engine/arg_utils.py", line 1127, in create_engine_config
    if is_ray_initialized():
    File ".../vllm/ray/lazy_utils.py", line 9, in is_ray_initialized
    return ray.is_initialized()
    AttributeError: module 'ray' has no attribute 'is_initialized'


    launch.json:


    {
    "version": "0.2.0",
    "configurations": [
    {
    "name": "Debug run-model.py with vllm",
    "type": "debugpy",
    "request": "launch",
    "program": "${workspaceFolder}/run-model.py",
    "console": "integratedTerminal",
    "cwd": "${workspaceFolder}",
    "justMyCode": false,
    "env": {
    "VLLM_TARGET_DEVICE": "cpu",
    "PYTHONPATH": "${workspaceFolder}/../vllm"
    }
    }
    ]
    }

    What I’ve tried so far:

    • Verified that the model loads and runs outside of debugpy (works fine).
    • Installed and reinstalled different Ray versions (2.9.3, 2.49.1, etc.) — same error.
    • Checked that ray.is_initialized() exists when I import ray directly in Python (works outside vLLM).
    • Tried running debugpy both in integratedTerminal and externalTerminal.
    • Explicitly set environment variables (VLLM_TARGET_DEVICE=cpu, PYTHONPATH=...) in launch.json.

    Questions:

    1. Why does vLLM call ray.is_initialized() only when running under debugpy?
    2. Is this a Ray version mismatch, or something about vLLM’s CPU mode with debugpy?
    3. What’s the correct way to set up debugpy with vLLM on CPU in WSL?

    Continue reading...

Compartilhe esta Página