vllm-project / vllm

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

[Bug]: Chunked prefill vs. non-chunked output is different for a long prompt #5952

Open felixzhu555 opened 2 months ago

felixzhu555 commented 2 months ago

Your current environment

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

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

Python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-5.4.0-169-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 12.1.105 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA A40 Nvidia driver version: 535.129.03 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: 52 bits physical, 57 bits virtual Byte Order: Little Endian CPU(s): 96 On-line CPU(s) list: 0-95 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Gold 6342 CPU @ 2.80GHz CPU family: 6 Model: 106 Thread(s) per core: 2 Core(s) per socket: 24 Socket(s): 2 Stepping: 6 Frequency boost: enabled CPU max MHz: 2801.0000 CPU min MHz: 800.0000 BogoMIPS: 5600.00 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 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 cpuid_fault epb cat_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 rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb intel_pt avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local wbnoinvd dtherm ida arat pln pts avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg tme avx512_vpopcntdq rdpid md_clear pconfig flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 2.3 MiB (48 instances) L1i cache: 1.5 MiB (48 instances) L2 cache: 60 MiB (48 instances) L3 cache: 72 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-23,48-71 NUMA node1 CPU(s): 24-47,72-95 Vulnerability Gather data sampling: Mitigation; Microcode Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: Not affected Vulnerability Mmio stale data: Mitigation; Clear CPU buffers; SMT vulnerable Vulnerability Retbleed: 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: Not affected

Versions of relevant libraries: [pip3] numpy==1.26.3 [pip3] nvidia-nccl-cu12==2.20.5 [pip3] torch==2.3.0 [pip3] torchaudio==2.2.0 [pip3] torchvision==0.18.0 [pip3] transformers==4.42.2 [pip3] triton==2.3.0 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.5.0.post1 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 NIC0 NIC1 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X SYS SYS 0-23,48-71 0 N/A NIC0 SYS X PIX NIC1 SYS PIX 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

🐛 Describe the bug

Minimal reproducible example (the prompt is large so it's in a separate txt file, I'm happy to share it if needed).

import gc
import os
import torch
from vllm import LLM, SamplingParams

from huggingface_hub import login
login(token=os.environ.get("HF_TOKEN"))

model = "meta-llama/Meta-Llama-3-8B-Instruct"

with open("/workspace/vllm/temp/paxos-paper.txt", "r") as f:
    prompt = f.read()
params = SamplingParams(max_tokens=100, temperature=0.5)

def generate(enable_chunked_prefill):
    llm = LLM(model=model, enable_chunked_prefill=enable_chunked_prefill)
    request_output = llm.generate(prompt, sampling_params=params)[0]
    del llm
    gc.collect()
    torch.cuda.empty_cache()

    out = request_output.outputs[0]
    print(f"\nPrompt length: {len(request_output.prompt_token_ids)} tokens")
    print(f"OUTPUT: ({len(out.token_ids)} tokens)")
    print(out.text, "\n")
    return out.text

nonchunked_text = generate(False)
chunked_text = generate(True)

print("\nNON-CHUNKED:")
print(nonchunked_text)
print("\nCHUNKED:")
print(chunked_text)
print("\nDifferent?", nonchunked_text != chunked_text)

Unexpected result for meta-llama/Meta-Llama-3-8B-Instruct with input of 3600 tokens. Edit: bug also appears for mistralai/Mistral-7B-Instruct-v0.2 Output differs when toggling chunked prefill, but we should expect no difference. From what I see, this happens for sampling temperature in range [0.3, 0.9].

Example output for running above:

NON-CHUNKED:
  What are the main points of the paper?

Here is a summary of the paper:

The paper presents the Paxos algorithm for implementing a fault-tolerant distributed system. The algorithm is a consensus algorithm that ensures that a single value is chosen from a set of proposed values, even in the presence of failures and message loss.

The paper starts by defining the problem of choosing a value in a distributed system, and presents the safety requirements for a consensus algorithm. The algorithm is presented in three phases:

CHUNKED:
  What are the main points and what are the contributions of this paper?  What are the limitations and assumptions of this paper?  What are the implications of this paper for the field of distributed systems?

The paper presents a consensus algorithm for distributed systems, known as Paxos, which is designed to ensure that a single value is chosen from a set of proposed values. The algorithm is based on a state machine approach, where a set of processes (proposers, acceptors, and learners)

Different? True
simon-mo commented 2 months ago

@rkooo567 it would be great if you can help suggest some flows on this

rkooo567 commented 2 months ago

Lmk if there's a different opinion, but I think unless there's a big difference in quality benchmark, this much of output difference is difficult to be called a bug imo. Chunked prefill uses different kernels from regular kernels, and and this test doesn't use temperature == 0, float 32 dtype, nor greedy sampling. The chunked prefill output also seems relatively reasonable to me. Have you run benchmark such as MMLU and see the big quality difference?