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

[Usage]: Using AsyncLLMEngine with asyncio.run #3996

Closed
fozziethebeat opened this issue Apr 11, 2024 · 9 comments · Fixed by #5654
Closed

[Usage]: Using AsyncLLMEngine with asyncio.run #3996

fozziethebeat opened this issue Apr 11, 2024 · 9 comments · Fixed by #5654
Labels
usage How to use vllm

Comments

@fozziethebeat
Copy link

Your current environment

Collecting environment information...
PyTorch version: 2.1.2+cu121
Is debug build: False
CUDA used to build PyTorch: 12.1
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 LTS (x86_64)
GCC version: (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version: Could not collect
CMake version: Could not collect
Libc version: glibc-2.35

Python version: 3.10.14 (main, Mar 21 2024, 16:24:04) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-5.15.0-102-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: Could not collect
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration:
GPU 0: NVIDIA GeForce RTX 3060
GPU 1: NVIDIA RTX A6000

Nvidia driver version: 550.54.15
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
Address sizes:                      46 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             24
On-line CPU(s) list:                0-23
Vendor ID:                          GenuineIntel
Model name:                         Intel(R) Core(TM) i9-10920X CPU @ 3.50GHz
CPU family:                         6
Model:                              85
Thread(s) per core:                 2
Core(s) per socket:                 12
Socket(s):                          1
Stepping:                           7
CPU max MHz:                        4800.0000
CPU min MHz:                        1200.0000
BogoMIPS:                           6999.82
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 cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl vmx 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 cpuid_fault epb cat_l3 cdp_l3 invpcid_single ssbd mba ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves 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 avx512_vnni md_clear flush_l1d arch_capabilities
Virtualization:                     VT-x
L1d cache:                          384 KiB (12 instances)
L1i cache:                          384 KiB (12 instances)
L2 cache:                           12 MiB (12 instances)
L3 cache:                           19.3 MiB (1 instance)
NUMA node(s):                       1
NUMA node0 CPU(s):                  0-23
Vulnerability Gather data sampling: Mitigation; Microcode
Vulnerability Itlb multihit:        KVM: Mitigation: VMX disabled
Vulnerability L1tf:                 Not affected
Vulnerability Mds:                  Not affected
Vulnerability Meltdown:             Not affected
Vulnerability Mmio stale data:      Mitigation; Clear CPU buffers; SMT vulnerable
Vulnerability Retbleed:             Mitigation; Enhanced IBRS
Vulnerability Spec rstack overflow: Not affected
Vulnerability Spec store bypass:    Mitigation; Speculative Store Bypass disabled via prctl and seccomp
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS SW sequence
Vulnerability Srbds:                Not affected
Vulnerability Tsx async abort:      Mitigation; TSX disabled

Versions of relevant libraries:
[pip3] flake8==7.0.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==1.26.1
[pip3] torch==2.1.2
[pip3] triton==2.1.0
[conda] torch                     2.1.2                    pypi_0    pypi
[conda] triton                    2.1.0                    pypi_0    pypiROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.4.0.post1
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0	GPU1	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	SYS	0-23	0		N/A
GPU1	SYS	 X 	0-23	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

How would you like to use vllm

I want to run batch offline inference in a command line tool using AsyncLLMEngine in a set of coroutines being managed by a top level call to asyncio.run.

I have a demo script that ultimately does the right thing but doesn't tear down or complete correctly. It will either:

  1. Hang until asyncio times out
  2. Throw an error from _raise_exception_on_finish being cancelled

The minimal working example of what I want to do is:

import asyncio
from uuid import uuid4
from vllm import AsyncEngineArgs, AsyncLLMEngine, SamplingParams


def main():
    engine = AsyncLLMEngine.from_engine_args(
        AsyncEngineArgs(
            model="mistralai/Mistral-7B-Instruct-v0.2",
        )
    )
    params = SamplingParams(
        top_k=1,
        temperature=0.8,
        max_tokens=64,
        stop=[],
    )

    async def run_query(query: str):
        request_id = uuid4()
        outputs = engine.generate(query, params, request_id)
        async for output in outputs:
            final_output = output
        responses = []
        for output in final_output.outputs:
            responses.append(output.text)
        return responses

    async def process():
        queries = [
            "I have cats, do you?",
            "If you were a muppet, what type of muppet would you be?",
        ]
        tasks = [asyncio.create_task(run_query(q)) for q in queries]
        results = []
        for task in asyncio.as_completed(tasks):
            result = await task
            results.append(result)
        return results

    results = asyncio.run(process())
    print(results)


if __name__ == "__main__":
    main()

My guess is that this is due to AsyncLLMEngine calling asyncio.get_event_loop and that somehow conflicting with my top level runner calling asyncio.run.

@fozziethebeat fozziethebeat added the usage How to use vllm label Apr 11, 2024
@robertgshaw2-redhat
Copy link
Collaborator

robertgshaw2-redhat commented Apr 11, 2024

Is there a reason why you cannot use the following?

from vllm import LLM
model = LLM("mistralai/Mistral-7B-Instruct-v0.2")
model.generate([prompts])

The LLM class is intended for offline usage

The class you are using is not really intended to be used externally

@fozziethebeat
Copy link
Author

That's my current backup solution which works just fine. But if I can get a scenario like the above working that'd be ideal.

@robertgshaw2-redhat
Copy link
Collaborator

Okay, is there a reason that doesn't work? Just curious so we can improve the interface.

I would say that looking at vllm/entrypoints/api_server.py is the best place for an example using the AsyncLLMEngine. I think it will be tricky to have multiple asyncio loops running. The AsyncLLMEngine class is supposed to handle the concurrency

Otherwise I think your best bet is to reimplement AsyncLLMEngine for your needs

@fozziethebeat
Copy link
Author

As far as I can tell, when using the LLM engine my co-routines all run in sequence rather than doing anything parallel. When I activate the AsyncLLMEngine manually, everything works pretty smoothly but it never exits the top level co-routine and instead times out. I'll have to look deep into the engine to see what its doing that's interacting badly with asyncio.run. Alternative, I might just stand up vLLM servers as sub-processes and call them.

@Iven2132
Copy link

What is AsyncLLMEngine? What is the difference between AsyncLLMEngine vs LLM class?

@mces89
Copy link

mces89 commented May 22, 2024

@fozziethebeat I got the same issue, did you figure an workaround? thanks.

@fozziethebeat
Copy link
Author

Our solution was to fork off a sub-process that ran the server and waited until it was ready and then just call it via REST requests. Works well enough

@SuperBruceJia
Copy link

@robertgshaw2-neuralmagic Hi, Robert, how can we set distrubted_execution_backend="mp" while using the LLM?

@zifeitong
Copy link
Contributor

This is the same as #4789. I'll try to send a PR to fix it.

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

Successfully merging a pull request may close this issue.

6 participants