vllm-project / vllm

A high-throughput and memory-efficient inference and serving engine for LLMs
https://docs.vllm.ai
Apache License 2.0
29.76k stars 4.49k forks source link

[Bug]: Speculative decoding generate gibberish when receiving parallel requests with different seeds #9441

Open wallashss opened 3 weeks ago

wallashss commented 3 weeks ago

Your current environment

The output of `python collect_env.py` ```text Collecting environment information... 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: Red Hat Enterprise Linux 9.4 (Plow) (x86_64) GCC version: (GCC) 11.4.1 20231218 (Red Hat 11.4.1-3) Clang version: Could not collect CMake version: version 3.30.4 Libc version: glibc-2.34 Python version: 3.12.1 (main, Aug 23 2024, 00:00:00) [GCC 11.4.1 20231218 (Red Hat 11.4.1-3)] (64-bit runtime) Python platform: Linux-4.18.0-372.46.1.el8_6.x86_64-x86_64-with-glibc2.34 Is CUDA available: True CUDA runtime version: 12.4.131 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA A100-SXM4-80GB MIG 3g.40gb Device 0: Nvidia driver version: 535.104.05 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, 57 bits virtual Byte Order: Little Endian CPU(s): 80 On-line CPU(s) list: 0-79 Vendor ID: GenuineIntel Model name: Intel Xeon Processor (Icelake) CPU family: 6 Model: 134 Thread(s) per core: 2 Core(s) per socket: 20 Socket(s): 2 Stepping: 0 BogoMIPS: 5600.03 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch cpuid_fault invpcid_single ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow vnmi flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves wbnoinvd arat avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid fsrm md_clear arch_capabilities Virtualization: VT-x Hypervisor vendor: KVM Virtualization type: full L1d cache: 2.5 MiB (80 instances) L1i cache: 2.5 MiB (80 instances) L2 cache: 160 MiB (40 instances) L3 cache: 32 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-39 NUMA node1 CPU(s): 40-79 Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Vulnerable: Clear CPU buffers attempted, no microcode; SMT Host state unknown Vulnerability Retbleed: Not affected Vulnerability Spec store bypass: Mitigation; Speculative Store Bypass disabled via prctl Vulnerability Spectre v1: Mitigation; usercopy/swapgs barriers and __user pointer sanitization Vulnerability Spectre v2: Mitigation; Enhanced IBRS, IBPB conditional, RSB filling, PBRSB-eIBRS Not affected Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] flashinfer==0.1.6+cu124torch2.4 [pip3] mypy==1.11.1 [pip3] mypy-extensions==1.0.0 [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.77 [pip3] nvidia-nvtx-cu12==12.1.105 [pip3] pyzmq==26.2.0 [pip3] sentence-transformers==3.1.1 [pip3] torch==2.4.0 [pip3] torchvision==0.19.0 [pip3] transformers==4.45.2 [pip3] transformers-stream-generator==0.0.5 [pip3] triton==3.0.0 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: N/A (dev) vLLM Build Flags: CUDA Archs: 7.0 7.5 8.0 8.6 8.9 9.0+PTX; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 NIC0 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X NODE 0-39 0 N/A NIC0 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 ```

Model Input Dumps

No response

🐛 Describe the bug

I was doing some experiments with speculative decoding and found an strange behavior when the engine process request in parallel, there are some requests generated with gibberish.

Here's the script to reproduce the bug:

import asyncio
import tempfile
import uuid

from tests.mq_llm_engine.utils import RemoteMQLLMEngine
from vllm import SamplingParams
from vllm.engine.arg_utils import AsyncEngineArgs
from vllm.engine.multiprocessing.client import MQLLMEngineClient

DEFAULT_SEED=0

async def generate_repeated(client : MQLLMEngineClient, seed=None):
    params = SamplingParams(temperature=0, stop=['20:'], seed=seed, max_tokens=220)
    prompt = 'Write the following phrase exactly 20 times: I will never miss any tokens.\n1: I will never miss any tokens.\n2: '

    async for r in client.generate(prompt=prompt,
                                    sampling_params=params,
                                    request_id=uuid.uuid4()):
        if r.finished:
            txt = r.outputs[0].text
            n = len(txt.split('I will never miss any tokens.'))

            print(r.request_id, f'Has {n} occurrences')
            if n != 19:
                print(txt)
            # print(txt)

async def generate_other(client : MQLLMEngineClient, seed: int):
    params = SamplingParams(temperature=0, seed=seed, max_tokens=200)
    prompt = "How to make pizza" 
    async for _ in client.generate(prompt=prompt,
                                    sampling_params=params,
                                    request_id=uuid.uuid4()):
        # No need to process output
        pass

async def run_tests(client):
    await client.check_health()

    print(">>>  Running only the repeated prompt")

    repeated_prompt_tasks = [asyncio.create_task(generate_repeated(client)) for _ in range(10)]
    await asyncio.gather(*repeated_prompt_tasks) 

    print(">>>  Running the repeated prompt with other prompts with same seed")

    repeated_prompt_tasks = [asyncio.create_task(generate_repeated(client, DEFAULT_SEED)) for _ in range(5)]
    other_prompt_tasks = [asyncio.create_task(generate_other(client, DEFAULT_SEED)) for _ in range(5)]
    tasks = repeated_prompt_tasks + other_prompt_tasks
    await asyncio.gather(*(tasks)) 

    print(">>>  Running the repeated prompt with other prompts with different seeds")

    repeated_prompt_tasks = [asyncio.create_task(generate_repeated(client)) for _ in range(5)]
    other_prompt_tasks = [asyncio.create_task(generate_other(client, DEFAULT_SEED)) for _ in range(5)]
    tasks = repeated_prompt_tasks + other_prompt_tasks

    await asyncio.gather(*(tasks))

    client.close()

async def main(ipc_path):

    engine_args = AsyncEngineArgs(model='meta-llama/Llama-3.1-8B-Instruct', 
                                  gpu_memory_utilization=0.95, use_v2_block_manager=True)

    print("__________RUNNING WITHOUT SPECULATING DECODING__________")

    with RemoteMQLLMEngine(engine_args=engine_args,
                           ipc_path=ipc_path) as engine:

        client = await engine.make_client()
        await run_tests(client)

    print("__________RUNNING WITH SPECULATING DECODING__________")

    engine_args = AsyncEngineArgs(model='meta-llama/Llama-3.1-8B-Instruct', 
                                  gpu_memory_utilization=0.95, use_v2_block_manager=True,
                                  max_model_len=1984, 
                                  speculative_model='ibm-fms/llama3-8b-accelerator', num_speculative_tokens=4)

    with RemoteMQLLMEngine(engine_args=engine_args,
                           ipc_path=ipc_path) as engine:

        client = await engine.make_client()
        await run_tests(client)

if __name__ == "__main__": 

    with tempfile.TemporaryDirectory() as td:
        socket = f"ipc://{td}/{uuid.uuid4()}"
        asyncio.run(main(socket))

    print("Done")

In a nutshell:

A possible output ```log /opt/vllm/lib64/python3.12/site-packages/vllm/connections.py:8: RuntimeWarning: Failed to read commit hash: No module named 'vllm._version' from vllm.version import __version__ as VLLM_VERSION __________RUNNING WITHOUT SPECULATING DECODING__________ /opt/vllm/lib64/python3.12/site-packages/vllm/connections.py:8: RuntimeWarning: Failed to read commit hash: No module named 'vllm._version' from vllm.version import __version__ as VLLM_VERSION WARNING 10-17 02:06:17 arg_utils.py:953] 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 10-17 02:06:17 config.py:1005] Chunked prefill is enabled with max_num_batched_tokens=512. WARNING 10-17 02:06:20 arg_utils.py:953] 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 10-17 02:06:20 config.py:1005] Chunked prefill is enabled with max_num_batched_tokens=512. INFO 10-17 02:06:20 llm_engine.py:237] Initializing an LLM engine (vdev) with config: model='meta-llama/Llama-3.1-8B-Instruct', speculative_config=None, tokenizer='meta-llama/Llama-3.1-8B-Instruct', 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=False, dtype=torch.bfloat16, max_seq_len=131072, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, 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=meta-llama/Llama-3.1-8B-Instruct, use_v2_block_manager=True, num_scheduler_steps=1, chunked_prefill_enabled=True multi_step_stream_outputs=True, enable_prefix_caching=False, use_async_output_proc=True, use_cached_outputs=True, mm_processor_kwargs=None) INFO 10-17 02:06:21 model_runner.py:1060] Starting to load model meta-llama/Llama-3.1-8B-Instruct... INFO 10-17 02:06:22 weight_utils.py:243] Using model weights format ['*.safetensors'] Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00>> Running only the repeated prompt fe289733-219d-48ee-96b1-5ce7f9f73874 Has 19 occurrences 8ab9d577-f6c5-4027-812f-c590248d4980 Has 19 occurrences bf23ac40-77d7-477b-8fb5-808a755a26d5 Has 19 occurrences 8f45a0bf-f4ef-4fc5-b799-8ced0e720f4e Has 19 occurrences 7e0c750b-92f5-424a-9a96-665926da88b2 Has 19 occurrences cfc1df95-0e83-4b12-8a76-2f91d02dae56 Has 19 occurrences 35462188-01a7-4137-ab94-2a4739015207 Has 19 occurrences 644fdc5b-18e6-44e9-b7f6-bc42dfe4b9aa Has 19 occurrences 3c859be7-67b7-4e99-96a9-29ca027b62bb Has 19 occurrences 2b8afcac-9a76-45b4-8368-a371eb585291 Has 19 occurrences >>> Running the repeated prompt with other prompts with same seed 7af075eb-e930-4084-a465-cbc4dc180f96 Has 19 occurrences 5d35b575-4ae6-4187-82a6-372a28fb7ee7 Has 19 occurrences f341e245-5bf6-4ced-83c8-7524876b3fb9 Has 19 occurrences 325a0f4f-cb5b-44a4-b208-28250b2e19e4 Has 19 occurrences fb0530a1-0f15-498a-b83c-d57f7e07f0e3 Has 19 occurrences >>> Running the repeated prompt with other prompts with different seeds 2b5d3959-a07f-4b81-b431-4e02703b3e4d Has 19 occurrences a9d0f590-9272-4292-a986-1b65e3d7b1cd Has 19 occurrences 6fe01def-ba33-495b-8c52-90f96bb22208 Has 19 occurrences c7f2492d-0dc3-4294-aa63-620e1d573b19 Has 19 occurrences 5211e0e9-455a-4ef3-a81e-00d51ef3421a Has 19 occurrences __________RUNNING WITH SPECULATING DECODING__________ WARNING 10-17 02:06:52 config.py:1674] Casting torch.float16 to torch.bfloat16. /opt/vllm/lib64/python3.12/site-packages/vllm/connections.py:8: RuntimeWarning: Failed to read commit hash: No module named 'vllm._version' from vllm.version import __version__ as VLLM_VERSION WARNING 10-17 02:06:56 config.py:395] Async output processing is not supported with speculative decoding currently. WARNING 10-17 02:07:00 config.py:1674] Casting torch.float16 to torch.bfloat16. WARNING 10-17 02:07:04 config.py:395] Async output processing is not supported with speculative decoding currently. INFO 10-17 02:07:04 llm_engine.py:237] Initializing an LLM engine (vdev) with config: model='meta-llama/Llama-3.1-8B-Instruct', speculative_config=SpeculativeConfig(draft_model='ibm-fms/llama3-8b-accelerator', num_spec_tokens=4), tokenizer='meta-llama/Llama-3.1-8B-Instruct', 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=False, dtype=torch.bfloat16, max_seq_len=1984, download_dir=None, load_format=LoadFormat.AUTO, tensor_parallel_size=1, 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=meta-llama/Llama-3.1-8B-Instruct, use_v2_block_manager=True, num_scheduler_steps=1, chunked_prefill_enabled=False multi_step_stream_outputs=True, enable_prefix_caching=False, use_async_output_proc=False, use_cached_outputs=True, mm_processor_kwargs=None) INFO 10-17 02:07:05 spec_decode_worker.py:169] Configuring SpecDecodeWorker with proposer= INFO 10-17 02:07:05 rejection_sampler.py:57] Use pytorch for rejection sampling. INFO 10-17 02:07:05 spec_decode_worker.py:181] [Speculative Decoding] Configuring SpecDecodeWorker with sampler= INFO 10-17 02:07:05 spec_decode_worker.py:204] [Speculative Decoding] Disabling MQA scorer as the target model is not running in eager mode. INFO 10-17 02:07:05 model_runner.py:1060] Starting to load model meta-llama/Llama-3.1-8B-Instruct... INFO 10-17 02:07:05 weight_utils.py:243] Using model weights format ['*.safetensors'] Loading safetensors checkpoint shards: 0% Completed | 0/4 [00:00>> Running only the repeated prompt da9a4028-09d7-4141-a2bc-6b275cd7fa56 Has 19 occurrences a6c6f527-eef8-43f9-a2df-93f629f44e50 Has 19 occurrences 61b089c8-9a85-4d01-bc5a-6ab56815f144 Has 19 occurrences f4f092be-6e22-4507-b3ca-3bd81d3843d6 Has 19 occurrences 6f4c0aae-f17c-46ff-9af7-ec9f863d318e Has 19 occurrences 22dc3f94-57eb-494a-b2eb-4e810b78b93f Has 19 occurrences 57808f41-90f3-48b4-9b1d-f6db08a816c1 Has 19 occurrences b3ac5c88-c9f7-46bc-a7f5-8350921a0fa7 Has 19 occurrences 76db0527-be1f-47ed-b552-be868b5f850f Has 19 occurrences 8837bd8f-23e9-467c-af9e-872ab8a51c82 Has 19 occurrences >>> Running the repeated prompt with other prompts with same seed e24eba59-2b8f-4279-995d-151390473e93 Has 19 occurrences bb77ed15-9746-4022-a6b0-ac8f32bd3493 Has 19 occurrences 618e83fa-cc89-4fc7-85d3-8640869ea5b0 Has 19 occurrences eb3977b1-f247-4d97-a000-ef977c28b857 Has 19 occurrences e9475f87-cf59-4324-bf76-bd56ab76f305 Has 19 occurrences >>> Running the repeated prompt with other prompts with different seeds a29b2c3d-ab1b-45bd-b1d7-ee8556faced3 Has 1 occurrences I will!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""!! I!!!"!"!!!"!"!"!"!!!!!"!"!"!"!"!!!!!!!"!"!"!! I!"!"!"!"!"!! I!"!! I!! I""!! I! I""!! I"!! I! I! I"!! I"!! I! I! I"!! I! I"!! I"! I! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! aa537b10-1e01-4faf-b52d-94d0329d2a0a Has 1 occurrences I will!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""!! I!!!"!"!!!"!"!"!"!!!!!"!"!"!"!"!!!!!!!"!"!"!! I!"!"!"!"!"!! I!"!! I!! I""!! I! I""!! I"!! I! I! I"!! I"!! I! I! I"!! I! I"!! I"! I! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! ca454e6d-baac-4a50-be9d-ae39b14fc424 Has 1 occurrences I will!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""!! I!!!"!"!!!"!"!"!"!!!!!"!"!"!"!"!!!!!!!"!"!"!! I!"!"!"!"!"!! I!"!! I!! I""!! I! I""!! I"!! I! I! I"!! I"!! I! I! I"!! I! I"!! I"! I! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! 7481adc3-3b0a-4517-aa27-05d39b6e79f0 Has 1 occurrences I will!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""!! I!!!"!"!!!"!"!"!"!!!!!"!"!"!"!"!!!!!!!"!"!"!! I!"!"!"!"!"!! I!"!! I!! I""!! I! I""!! I"!! I! I! I"!! I"!! I! I! I"!! I! I"!! I"! I! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! 5a1be1bc-5172-4481-a900-24883c472140 Has 1 occurrences I will!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!""!! I!!!"!"!!!"!"!"!"!!!!!"!"!"!"!"!!!!!!!"!"!"!! I!"!"!"!"!"!! I!"!! I!! I""!! I! I""!! I"!! I! I! I"!! I"!! I! I! I"!! I! I"!! I"! I! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! I"! Done /usr/lib64/python3.12/multiprocessing/resource_tracker.py:254: UserWarning: resource_tracker: There appear to be 2 leaked semaphore objects to clean up at shutdown warnings.warn('resource_tracker: There appear to be %d ' ```

Before submitting a new issue...

venkatakesav commented 3 weeks ago

Hi @wallashss, I'd like to work on this issue. Could you please assign it to me? Thanks!