vllm: [Bug]: Qwen2.5-Math-7B-Instruct vllm output garbled code, but the probability of huggingface outputing garbled code is lower.

Your current environment

The output of `python collect_env.py`
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 implementation outputs garbled code with a much lower probability.

Before submitting a new issue…

  • Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the documentation page, which can answer lots of frequently asked questions.

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 19 (4 by maintainers)

Most upvoted comments

@Hanqer

  1. 把vllm更新到最新版本,我更新后解决了
  2. 垃圾消息或者复读,在数学等领域是有可能的。尝试换些query看看,或者将模型规模提升到32B以上

感谢回复,我的vllm版本是0.6.4,请问你是更新到多少缓解了这个问题呢?

0.6.5