vllm-project / vllm

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

[Bug]: Qwen2.5-Math-7B-Instruct vllm output garbled code, but huggingface not #9183

Open ziyuwan opened 2 weeks ago

ziyuwan commented 2 weeks ago

Your current environment

The output of `python collect_env.py` ```text 2024-10-09 14:34:40 (641 KB/s) - ‘collect_env.py’ saved [25599/25599] 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.30.4 Libc version: glibc-2.35 Python version: 3.10.14 (main, May 6 2024, 19:42:50) [GCC 11.2.0] (64-bit runtime) Python platform: Linux-5.4.0-155-generic-x86_64-with-glibc2.35 Is CUDA available: True CUDA runtime version: 11.8.89 CUDA_MODULE_LOADING set to: LAZY GPU models and configuration: GPU 0: NVIDIA A800-SXM4-80GB GPU 1: NVIDIA A800-SXM4-80GB GPU 2: NVIDIA A800-SXM4-80GB GPU 3: NVIDIA A800-SXM4-80GB Nvidia driver version: 535.54.03 cuDNN version: Probably one of the following: /usr/lib/x86_64-linux-gnu/libcudnn.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_adv_infer.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_adv_train.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_infer.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_cnn_train.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_ops_infer.so.8.9.6 /usr/lib/x86_64-linux-gnu/libcudnn_ops_train.so.8.9.6 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): 64 On-line CPU(s) list: 0-63 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Platinum 8358P CPU @ 2.60GHz CPU family: 6 Model: 106 Thread(s) per core: 1 Core(s) per socket: 32 Socket(s): 2 Stepping: 6 CPU max MHz: 3400.0000 CPU min MHz: 800.0000 BogoMIPS: 5200.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 hwp hwp_act_window hwp_epp hwp_pkg_req 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: 3 MiB (64 instances) L1i cache: 2 MiB (64 instances) L2 cache: 80 MiB (64 instances) L3 cache: 96 MiB (2 instances) NUMA node(s): 2 NUMA node0 CPU(s): 0-31 NUMA node1 CPU(s): 32-63 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 disabled 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] 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==8.9.2.26 [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.535.161 [pip3] nvidia-nccl-cu12==2.20.5 [pip3] nvidia-nvjitlink-cu12==12.6.68 [pip3] nvidia-nvtx-cu12==12.1.105 [pip3] pyzmq==25.1.2 [pip3] torch==2.3.0 [pip3] torchtyping==0.1.5 [pip3] torchvision==0.18.0 [pip3] transformers==4.45.0 [pip3] triton==2.3.0 [conda] numpy 1.26.4 pypi_0 pypi [conda] nvidia-cublas-cu12 12.1.3.1 pypi_0 pypi [conda] nvidia-cuda-cupti-cu12 12.1.105 pypi_0 pypi [conda] nvidia-cuda-nvrtc-cu12 12.1.105 pypi_0 pypi [conda] nvidia-cuda-runtime-cu12 12.1.105 pypi_0 pypi [conda] nvidia-cudnn-cu12 8.9.2.26 pypi_0 pypi [conda] nvidia-cufft-cu12 11.0.2.54 pypi_0 pypi [conda] nvidia-curand-cu12 10.3.2.106 pypi_0 pypi [conda] nvidia-cusolver-cu12 11.4.5.107 pypi_0 pypi [conda] nvidia-cusparse-cu12 12.1.0.106 pypi_0 pypi [conda] nvidia-nccl-cu12 2.20.5 pypi_0 pypi [conda] nvidia-nvjitlink-cu12 12.6.68 pypi_0 pypi [conda] nvidia-nvtx-cu12 12.1.105 pypi_0 pypi [conda] pyzmq 26.2.0 pypi_0 pypi [conda] torch 2.3.0 pypi_0 pypi [conda] torchtyping 0.1.5 pypi_0 pypi [conda] torchvision 0.18.0 pypi_0 pypi [conda] transformers 4.45.0 pypi_0 pypi [conda] triton 2.3.0 pypi_0 pypi ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.5.1 vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: GPU0 GPU1 GPU2 GPU3 NIC0 NIC1 CPU Affinity NUMA Affinity GPU NUMA ID GPU0 X NV8 NV8 NV8 NODE NODE 0-31 0 N/A GPU1 NV8 X NV8 NV8 NODE NODE 0-31 0 N/A GPU2 NV8 NV8 X NV8 SYS SYS 32-63 1 N/A GPU3 NV8 NV8 NV8 X SYS SYS 32-63 1 N/A NIC0 NODE NODE SYS SYS X PIX NIC1 NODE NODE SYS 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_bond_0 ```

Model Input Dumps

No response

🐛 Describe the bug

Hi!

I'm now using Qwen2.5-Math-7B-Instruct to solve problems in the MATH dataset. And I found that the vLLM engine sometimes has weird outputs(garbled code). Here is the code

from vllm import LLM, SamplingParams

## VLLM output
model_name = "Qwen2.5-Math-7B-Instruct"
llm = LLM(model_name)

text='<|im_start|>system\nPlease reason step by step, and put your final answer within \\boxed{{}}.<|im_end|>\n<|im_start|>user\nSimplify $\\tan 100^\\circ + 4 \\sin 100^\\circ.$<|im_end|>\n<|im_start|>assistant\nTo simplify the expression \\(\\tan 100^\\circ + 4 \\sin 100^\\circ\\), we start by using the identity \\(\\tan 100^\\circ = \\tan (180^\\circ - 80^\\circ) = -\\tan 80^\\circ\\). Therefore, the expression becomes:\n\n\\[\n\\tan 100^\\circ + 4 \\sin 100^\\circ = -\\tan 80^\\circ + 4 \\sin 100^\\circ\n\\]\n\nNext, we use the identity \\(\\sin 100^\\circ = \\sin (180^\\circ - 80^\\circ) = \\sin 80^\\circ\\). So the expression further simplifies to:\n\n\\[\n-\\tan 80^\\circ + 4 \\sin 80^\\circ\n\\]\n\nWe can express \\(\\tan 80^\\circ\\) as \\(\\frac{\\sin 80^\\circ}{\\cos 80^\\circ}\\). Substituting this into the expression, we get:\n\n\\[\n-\\frac{\\sin 80^\\circ}{\\cos 80^\\circ} + 4 \\sin 80^\\circ\n\\]\n\nTo combine these terms, we need a common denominator. The common denominator is \\(\\cos 80^\\circ\\), so we rewrite the expression as:\n\n\\[\n-\\frac{\\sin 80^\\circ}{\\cos 80^\\circ} + \\frac{4 \\sin 80^\\circ \\cos 80^\\circ}{\\cos 80^\\circ} = \\frac{-\\sin 80^\\circ + 4 \\sin 80^\\circ \\cos 80^\\circ}{\\cos 80^\\circ}\n\\]\n\nWe can factor out \\(\\sin 80^\\circ\\) from the numerator:\n\n\\[\n\\frac{\\sin 80^\\circ (-1 + 4 \\cos 80^\\circ)}{\\cos 80^\\circ}\n\\]\n\nThis simplifies to:\n\n\\[\n\\sin 80^\\circ \\cdot \\frac{-1 + 4 \\cos 80^\\circ}{\\cos 80^\\circ} = \\sin 80^\\circ \\left( \\frac{-1}{\\cos 80^\\circ} + 4 \\right) = \\sin 80^\\circ \\left( -\\sec 80^\\circ + 4 \\right)\n\\]\n\nWe know from trigonometric identities that \\(\\sec 80^\\circ = \\frac{1}{\\cos 80^\\circ} = \\csc 10^\\circ\\) (since \\(\\sec (90^\\circ - \\theta) = \\csc \\theta\\)). Therefore, \\(-\\sec 80^\\circ = -\\csc 10^\\circ\\). So the expression becomes:\n\n\\[\n\\sin 80^\\circ \\left( -\\csc 10^\\circ + 4 \\right) = \\sin 80^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} + 4 \\right)\n\\]\n\nWe can rewrite \\(\\sin 80^\\circ\\) as \\(\\cos 10^\\circ\\) (since \\(\\sin (90^\\circ - \\theta) = \\cos \\theta\\)). So the expression is:\n\n\\[\n\\cos 10^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} + 4 \\right) = \\cos 10^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} \\right) + \\cos 10^\\circ \\cdot 4 = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + 4 \\cos 10^\\circ = -\\cot 10^\\circ + 4 \\cos 10^\\circ\n\\]\n\nWe know from trigonometric identities that \\(\\cot 10^\\circ = \\frac{\\cos 10^\\circ}{\\sin 10^\\circ}\\). So we have:\n\n\\[\n-\\cot 10^\\circ + 4 \\cos 10^\\circ = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + 4 \\cos 10^\\circ = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + \\frac{4 \\cos 10^\\circ \\sin 10^\\circ}{\\sin 10^\\circ} = \\frac{-\\cos 10^\\circ + 4 \\cos 10^\\circ \\sin 10^\\circ}{\\sin 10^\\circ}\n\\]\n\nWe can factor out \\(\\cos 10^\\circ\\) from the numerator:\n\n'
output = llm.generate(
    text, 
    sampling_params=SamplingParams(
        n=1, temperature=0.7, 
        top_k=50, 
        max_tokens=2048,
        stop=["</s>", "<|im_end|>", "<|endoftext|>"],
        stop_token_ids=[151645, 151643])
    )
print(output[0].outputs[0].text)

and vLLM's output is output.txt

image

and here is the code for text generation with transformers

text='<|im_start|>system\nPlease reason step by step, and put your final answer within \\boxed{{}}.<|im_end|>\n<|im_start|>user\nSimplify $\\tan 100^\\circ + 4 \\sin 100^\\circ.$<|im_end|>\n<|im_start|>assistant\nTo simplify the expression \\(\\tan 100^\\circ + 4 \\sin 100^\\circ\\), we start by using the identity \\(\\tan 100^\\circ = \\tan (180^\\circ - 80^\\circ) = -\\tan 80^\\circ\\). Therefore, the expression becomes:\n\n\\[\n\\tan 100^\\circ + 4 \\sin 100^\\circ = -\\tan 80^\\circ + 4 \\sin 100^\\circ\n\\]\n\nNext, we use the identity \\(\\sin 100^\\circ = \\sin (180^\\circ - 80^\\circ) = \\sin 80^\\circ\\). So the expression further simplifies to:\n\n\\[\n-\\tan 80^\\circ + 4 \\sin 80^\\circ\n\\]\n\nWe can express \\(\\tan 80^\\circ\\) as \\(\\frac{\\sin 80^\\circ}{\\cos 80^\\circ}\\). Substituting this into the expression, we get:\n\n\\[\n-\\frac{\\sin 80^\\circ}{\\cos 80^\\circ} + 4 \\sin 80^\\circ\n\\]\n\nTo combine these terms, we need a common denominator. The common denominator is \\(\\cos 80^\\circ\\), so we rewrite the expression as:\n\n\\[\n-\\frac{\\sin 80^\\circ}{\\cos 80^\\circ} + \\frac{4 \\sin 80^\\circ \\cos 80^\\circ}{\\cos 80^\\circ} = \\frac{-\\sin 80^\\circ + 4 \\sin 80^\\circ \\cos 80^\\circ}{\\cos 80^\\circ}\n\\]\n\nWe can factor out \\(\\sin 80^\\circ\\) from the numerator:\n\n\\[\n\\frac{\\sin 80^\\circ (-1 + 4 \\cos 80^\\circ)}{\\cos 80^\\circ}\n\\]\n\nThis simplifies to:\n\n\\[\n\\sin 80^\\circ \\cdot \\frac{-1 + 4 \\cos 80^\\circ}{\\cos 80^\\circ} = \\sin 80^\\circ \\left( \\frac{-1}{\\cos 80^\\circ} + 4 \\right) = \\sin 80^\\circ \\left( -\\sec 80^\\circ + 4 \\right)\n\\]\n\nWe know from trigonometric identities that \\(\\sec 80^\\circ = \\frac{1}{\\cos 80^\\circ} = \\csc 10^\\circ\\) (since \\(\\sec (90^\\circ - \\theta) = \\csc \\theta\\)). Therefore, \\(-\\sec 80^\\circ = -\\csc 10^\\circ\\). So the expression becomes:\n\n\\[\n\\sin 80^\\circ \\left( -\\csc 10^\\circ + 4 \\right) = \\sin 80^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} + 4 \\right)\n\\]\n\nWe can rewrite \\(\\sin 80^\\circ\\) as \\(\\cos 10^\\circ\\) (since \\(\\sin (90^\\circ - \\theta) = \\cos \\theta\\)). So the expression is:\n\n\\[\n\\cos 10^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} + 4 \\right) = \\cos 10^\\circ \\left( -\\frac{1}{\\sin 10^\\circ} \\right) + \\cos 10^\\circ \\cdot 4 = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + 4 \\cos 10^\\circ = -\\cot 10^\\circ + 4 \\cos 10^\\circ\n\\]\n\nWe know from trigonometric identities that \\(\\cot 10^\\circ = \\frac{\\cos 10^\\circ}{\\sin 10^\\circ}\\). So we have:\n\n\\[\n-\\cot 10^\\circ + 4 \\cos 10^\\circ = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + 4 \\cos 10^\\circ = -\\frac{\\cos 10^\\circ}{\\sin 10^\\circ} + \\frac{4 \\cos 10^\\circ \\sin 10^\\circ}{\\sin 10^\\circ} = \\frac{-\\cos 10^\\circ + 4 \\cos 10^\\circ \\sin 10^\\circ}{\\sin 10^\\circ}\n\\]\n\nWe can factor out \\(\\cos 10^\\circ\\) from the numerator:\n\n'
model_inputs = tokenizer([text], return_tensors="pt").to(device)

generated_ids = model.generate(
    **model_inputs,
    max_new_tokens=2048,
    temperature=0.7
)
generated_ids = [
    output_ids[len(input_ids):] for input_ids, output_ids in zip(model_inputs.input_ids, generated_ids)
]

response = tokenizer.batch_decode(generated_ids, skip_special_tokens=True)[0]
print(response)

The output with transformers looks good.

I know that t > 0 may cause some randomness, but for both of the two codes here, I've tested over 5 times. And vLLM output strange texts in >60% cases. However, the transformers version always has good output.

Before submitting a new issue...

DarkLight1337 commented 2 weeks ago

I see that your version of vLLM is quite old. Can you try updating to the latest version and see if the problem is solved?

DarkLight1337 commented 2 weeks ago

I also see that you are using custom stop tokens and IDs, not sure whether this is the standard practice for using Qwen2.5.

ziyuwan commented 2 weeks ago

Thanks for your reply, for the custom stop tokens and IDs, I've followed the evaluation code in Qwen2.5-Math official repo. https://github.com/QwenLM/Qwen2.5-Math/blob/e128aa06871c7a0eeedc2ab21b69459bcb24c4fb/evaluation/math_eval.py#L234

and I'll try to first update vllm and reproduce the result.

ziyuwan commented 2 weeks ago

I see that your version of vLLM is quite old. Can you try updating to the latest version and see if the problem is solved?

I've update to 0.6.1.dev238+ge2c6e0a82, the problem is still there. I sampled 8 times, and 6/8 generated garbled texts.

DarkLight1337 commented 2 weeks ago

Can you try removing the tokens from stop, and instead specify all of them in stop_token_ids? After inspecting the code, it seems that they have different semantics which is quite confusing. cc @rkooo567

ziyuwan commented 2 weeks ago

Can you try removing the tokens from stop, and instead specify all of them in stop_token_ids? After inspecting the code, it seems that they have different semantics which is quite confusing. cc @rkooo567

Ok, in fact I found that the two stop_token_ids used here are just <|im_end|> and <|endoftext|>. After removing them, the problem still happens and I also checked the length of prompt_token_ids, it's correct.

DarkLight1337 commented 2 weeks ago

I don't have the bandwidth to look into this in detail, see if anyone else can help.