vllm-project / vllm

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

[Bug]: Logprob values are affected by sampling parameters and are incompatible with OpenAI API #9453

Open DIYer22 opened 2 weeks ago

DIYer22 commented 2 weeks ago

Your current environment

The output of `python collect_env.py` ```text root@vllm-cpu:/workspace# python3 collect_env.py Collecting environment information... INFO 08-20 07:37:37 importing.py:10] Triton not installed; certain GPU-related functions will be not be available. PyTorch version: 2.4.0+cpu Is debug build: False CUDA used to build PyTorch: None ROCM used to build PyTorch: N/A OS: Ubuntu 22.04.4 LTS (x86_64) GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0 Clang version: Could not collect CMake version: version 3.30.2 Libc version: glibc-2.35 Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime) Python platform: Linux-5.10.25-nvidia-gpu-x86_64-with-glibc2.35 Is CUDA available: False CUDA runtime version: No CUDA CUDA_MODULE_LOADING set to: N/A GPU models and configuration: No CUDA Nvidia driver version: No CUDA cuDNN version: No CUDA 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): 17 On-line CPU(s) list: 0-16 Vendor ID: GenuineIntel Model name: Intel(R) Xeon(R) Gold 6330 CPU @ 2.00GHz CPU family: 6 Model: 106 Thread(s) per core: 1 Core(s) per socket: 1 Socket(s): 17 Stepping: 6 BogoMIPS: 4000.00 Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq 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 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 avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid md_clear arch_capabilities Hypervisor vendor: KVM Virtualization type: full L1d cache: 544 KiB (17 instances) L1i cache: 544 KiB (17 instances) L2 cache: 68 MiB (17 instances) L3 cache: 272 MiB (17 instances) Vulnerability Itlb multihit: Not affected Vulnerability L1tf: Not affected Vulnerability Mds: Not affected Vulnerability Meltdown: 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 Vulnerability Srbds: Not affected Vulnerability Tsx async abort: Not affected Versions of relevant libraries: [pip3] intel_extension_for_pytorch==2.4.0+gitfbaa4bc [pip3] numpy==1.26.4 [pip3] pyzmq==26.1.0 [pip3] torch==2.4.0+cpu [pip3] torchvision==0.19.0+cpu [pip3] transformers==4.44.0 [conda] Could not collect ROCM Version: Could not collect Neuron SDK Version: N/A vLLM Version: 0.5.4@3f674a49b5033a6ed778ab960e86e03cfa64aa1f vLLM Build Flags: CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled GPU Topology: Could not collect ```

Model Input Dumps

No response

🐛 Describe the bug

The logprob in vLLM is not the raw probability of the standard LLM loss but is influenced by the sampling parameters. On the other hand, OpenAI returns the raw probability, meaning that no matter how the sampling parameters are set, the logprob of the next token under the same context remains unchanged in OpenAI.

I would like vLLM's logprob to be consistent with OpenAI's behavior because logprob should reflect the ideal probability of a token being sampled, independent of the sampling parameters. Additionally, when setting top_p: 0.0001, only the first token in top_logprobs is correct, while the subsequent tokens are fixed high-frequency tokens (such as ", !) instead of the current highest-probability tokens. The bug can be reproduced as follows:

curl -X POST "http://39.105.21.95:12481/v1/chat/completions" \
     -H "Content-Type: application/json" \
     -d '{
           "model": "meta-llama/Meta-Llama-3-8B-Instruct",
           "top_p": 0.0001,
           "stream": false, "max_tokens":5, "logprobs": true, "top_logprobs": 3,
           "messages": [
             {
               "role": "user",
               "content": "just generate a random two-digit integer , no other words"
             }
           ]
         }'

{'id': 'chat-6f6322c5dfab404782adf729201a024c',
 'object': 'chat.completion',
 'created': 1729071624,
 'model': 'meta-llama/Meta-Llama-3-8B-Instruct',
 'choices': [{'index': 0,
   'message': {'role': 'assistant', 'content': '43', 'tool_calls': []},
   'logprobs': {'content': [{'token': '43',
      'logprob': 0.0,
      'bytes': [52, 51],
      'top_logprobs': [{'token': '43', 'logprob': 0.0, 'bytes': [52, 51]},
       {'token': '"', 'logprob': -9999.0, 'bytes': [34]},
       {'token': '!', 'logprob': -9999.0, 'bytes': [33]}]},
     {'token': '',
      'logprob': 0.0,
      'bytes': [],
      'top_logprobs': [{'token': '', 'logprob': 0.0, 'bytes': []},
       {'token': '"', 'logprob': -9999.0, 'bytes': [34]},
       {'token': '!', 'logprob': -9999.0, 'bytes': [33]}]}]},
   'finish_reason': 'stop',
   'stop_reason': None}],
 'usage': {'prompt_tokens': 21, 'total_tokens': 23, 'completion_tokens': 2},
 'prompt_logprobs': None}

Before submitting a new issue...

ctjian commented 1 week ago

I have the same issue

tqfang commented 4 days ago

same