vllm - 💡(How to fix) Fix [Bug]: `prompt_logprobs` depends on request order when prefix caching is enabled

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Error Message

import gc import torch from vllm import LLM, SamplingParams

PROMPTS = [ [1, 10408, 15, 3312, 16315, 7519, 47932, 247, 16204, 275, 4255, 20098, 19083, 15, 2064, 6505, 347, 11853, 665, 1978, 368, 1977, 432, 4076, 8737, 13, 12868, 342, 326, 28148, 2929, 13], [2, 187, 6759, 16, 681, 16, 12929, 316, 14, 88, 1087, 16, 73, 1976, 16, 73, 15, 5581, 2, 1387, 4311, 187, 7330, 14, 9150, 9283, 608, 14, 2420, 187, 7330, 14], [3, 16440, 323, 368, 24174, 634, 12108, 13, 38857, 17087, 294, 4399, 19083, 15, 2064, 368, 971, 11853, 14565, 1978, 368, 1977, 432, 634, 9781, 13, 403, 1469, 281, 320, 8261, 13], ]

def score(llm, order): params = SamplingParams( n=1, max_tokens=1, temperature=0.0, prompt_logprobs=0, detokenize=False, ) outputs = llm.generate([PROMPTS[i] for i in order], params)

by_first_token = {}
for ro in outputs:
    vals = [0.0]
    for lp_dict, token_id in zip(ro.prompt_logprobs[1:], ro.prompt_token_ids[1:]):
        vals.append(float(lp_dict[token_id].logprob))
    by_first_token[int(ro.prompt_token_ids[0])] = torch.tensor(vals)
return by_first_token

def print_diff(label, ref, cur): print(label) for first_token in sorted(ref): diff = (cur[first_token] - ref[first_token]).abs() pos = int(diff.argmax()) print( f" prompt starting with {first_token}: " f"max={diff.max().item():.6f} at pos={pos} " f"ref={ref[first_token][pos].item():.6f} " f"cur={cur[first_token][pos].item():.6f}" )

llm = LLM( "EleutherAI/pythia-14m", dtype="float32", gpu_memory_utilization=0.5, # enable_prefix_caching=False makes this repro print exact zeros. )

try: ref = score(llm, (0, 1, 2)) same_order = score(llm, (0, 1, 2)) shuffled_order = score(llm, (2, 0, 1))

print_diff("same order repeated:", ref, same_order)
print_diff("after scoring shuffled order (2, 0, 1):", ref, shuffled_order)

finally: try: llm.llm_engine.engine_core.shutdown() except Exception: pass del llm gc.collect() if torch.cuda.is_available(): torch.cuda.empty_cache()

Fix Action

Workaround

Setting enable_prefix_caching=False makes the same repro print exact zeros.

Code Example

==============================
        System Info
==============================
OS                           : Ubuntu 24.04.4 LTS (x86_64)
GCC version                  : (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version                : Could not collect
CMake version                : version 4.3.1
Libc version                 : glibc-2.39

==============================
       PyTorch Info
==============================
PyTorch version              : 2.10.0+cu128
Is debug build               : False
CUDA used to build PyTorch   : 12.8
ROCM used to build PyTorch   : N/A
XPU used to build PyTorch    : N/A

==============================
      Python Environment
==============================
Python version               : 3.11.7 (main, Dec 15 2023, 18:12:31) [GCC 11.2.0] (64-bit runtime)
Python platform              : Linux-6.8.0-111-generic-x86_64-with-glibc2.39
    
==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : 12.0.140
CUDA_MODULE_LOADING set to   : 
GPU models and configuration : 
GPU 0: NVIDIA GeForce RTX 4090
GPU 1: NVIDIA GeForce RTX 4090

Nvidia driver version        : 570.172.08
cuDNN version                : Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.7.1
HIP runtime version          : N/A
MIOpen runtime version       : N/A
Is XNNPACK available         : True

==============================
          CPU Info
==============================
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           46 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  32
On-line CPU(s) list:                     0-31
Vendor ID:                               GenuineIntel
Model name:                              13th Gen Intel(R) Core(TM) i9-13900K
CPU family:                              6
Model:                                   183
Thread(s) per core:                      2
Core(s) per socket:                      24
Socket(s):                               1
Stepping:                                1
CPU(s) scaling MHz:                      30%
CPU max MHz:                             5800.0000
CPU min MHz:                             800.0000
BogoMIPS:                                5990.40
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization:                          VT-x
L1d cache:                               896 KiB (24 instances)
L1i cache:                               1.3 MiB (24 instances)
L2 cache:                                32 MiB (12 instances)
L3 cache:                                36 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-31
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Mitigation; Clear Register File
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      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 / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

==============================
Versions of relevant libraries
==============================
[pip3] flake8==6.0.0
[pip3] flashinfer-python==0.6.6
[pip3] mypy==1.8.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==2.4.4
[pip3] numpydoc==1.5.0
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cutlass-dsl==4.5.0.dev0
[pip3] nvidia-cutlass-dsl-libs-base==4.5.0.dev0
[pip3] nvidia-ml-py==13.595.45
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.4.5
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] pyzmq==25.1.2
[pip3] torch==2.10.0
[pip3] torch_c_dlpack_ext==0.1.5
[pip3] torchaudio==2.10.0
[pip3] torchvision==0.25.0
[pip3] transformers==4.57.6
[pip3] triton==3.6.0
[conda] _anaconda_depends         2024.02             py311_mkl_1  
[conda] blas                      1.0                         mkl  
[conda] cuda-cudart               12.1.105                      0    nvidia
[conda] cuda-cupti                12.1.105                      0    nvidia
[conda] cuda-libraries            12.1.0                        0    nvidia
[conda] cuda-nvrtc                12.1.105                      0    nvidia
[conda] cuda-nvtx                 12.1.105                      0    nvidia
[conda] cuda-opencl               12.4.127                      0    nvidia
[conda] cuda-runtime              12.1.0                        0    nvidia
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] flashinfer-python         0.6.6                    pypi_0    pypi
[conda] libcublas                 12.1.0.26                     0    nvidia
[conda] libcufft                  11.0.2.4                      0    nvidia
[conda] libcufile                 1.9.1.3                       0    nvidia
[conda] libcurand                 10.3.5.147                    0    nvidia
[conda] libcusolver               11.4.4.55                     0    nvidia
[conda] libcusparse               12.0.2.55                     0    nvidia
[conda] libjpeg-turbo             2.0.0                h9bf148f_0    pytorch
[conda] libnpp                    12.0.2.50                     0    nvidia
[conda] libnvjitlink              12.1.105                      0    nvidia
[conda] libnvjpeg                 12.1.1.14                     0    nvidia
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-service               2.4.0           py311h5eee18b_1  
[conda] mkl_fft                   1.3.8           py311h5eee18b_0  
[conda] mkl_random                1.2.4           py311hdb19cb5_0  
[conda] numpy                     2.4.4                    pypi_0    pypi
[conda] numpydoc                  1.5.0           py311h06a4308_0  
[conda] nvidia-cublas-cu12        12.8.4.1                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.8.90                  pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.8.93                  pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.8.90                  pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.10.2.21                pypi_0    pypi
[conda] nvidia-cudnn-frontend     1.18.0                   pypi_0    pypi
[conda] nvidia-cufft-cu12         11.3.3.83                pypi_0    pypi
[conda] nvidia-cufile-cu12        1.13.1.3                 pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.9.90                pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.7.3.90                pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.5.8.93                pypi_0    pypi
[conda] nvidia-cusparselt-cu12    0.7.1                    pypi_0    pypi
[conda] nvidia-cutlass-dsl        4.5.0.dev0               pypi_0    pypi
[conda] nvidia-cutlass-dsl-libs-base 4.5.0.dev0               pypi_0    pypi
[conda] nvidia-ml-py              13.595.45                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.27.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.8.93                  pypi_0    pypi
[conda] nvidia-nvshmem-cu12       3.4.5                    pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.8.90                  pypi_0    pypi
[conda] pytorch-cuda              12.1                 ha16c6d3_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pyzmq                     25.1.2          py311h6a678d5_0  
[conda] torch                     2.10.0                   pypi_0    pypi
[conda] torch-c-dlpack-ext        0.1.5                    pypi_0    pypi
[conda] torchaudio                2.10.0                   pypi_0    pypi
[conda] torchvision               0.25.0                   pypi_0    pypi
[conda] transformers              4.57.6                   pypi_0    pypi
[conda] triton                    3.6.0                    pypi_0    pypi

==============================
         vLLM Info
==============================
ROCM Version                 : Could not collect
vLLM Version                 : 0.19.0
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: Disabled; XPU: Disabled
GPU Topology:
        GPU0    GPU1    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      PHB     0-31    0               N/A
GPU1    PHB      X      0-31    0               N/A

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

==============================
     Environment Variables
==============================
PYTORCH_NVML_BASED_CUDA_CHECK=1

---

log p(t_k | t_<k)

---

import gc
import torch
from vllm import LLM, SamplingParams

PROMPTS = [
    [1, 10408, 15, 3312, 16315, 7519, 47932, 247, 16204, 275, 4255, 20098, 19083, 15, 2064, 6505, 347, 11853, 665, 1978, 368, 1977, 432, 4076, 8737, 13, 12868, 342, 326, 28148, 2929, 13],
    [2, 187, 6759, 16, 681, 16, 12929, 316, 14, 88, 1087, 16, 73, 1976, 16, 73, 15, 5581, 2, 1387, 4311, 187, 7330, 14, 9150, 9283, 608, 14, 2420, 187, 7330, 14],
    [3, 16440, 323, 368, 24174, 634, 12108, 13, 38857, 17087, 294, 4399, 19083, 15, 2064, 368, 971, 11853, 14565, 1978, 368, 1977, 432, 634, 9781, 13, 403, 1469, 281, 320, 8261, 13],
]

def score(llm, order):
    params = SamplingParams(
        n=1,
        max_tokens=1,
        temperature=0.0,
        prompt_logprobs=0,
        detokenize=False,
    )
    outputs = llm.generate([PROMPTS[i] for i in order], params)

    by_first_token = {}
    for ro in outputs:
        vals = [0.0]
        for lp_dict, token_id in zip(ro.prompt_logprobs[1:], ro.prompt_token_ids[1:]):
            vals.append(float(lp_dict[token_id].logprob))
        by_first_token[int(ro.prompt_token_ids[0])] = torch.tensor(vals)
    return by_first_token

def print_diff(label, ref, cur):
    print(label)
    for first_token in sorted(ref):
        diff = (cur[first_token] - ref[first_token]).abs()
        pos = int(diff.argmax())
        print(
            f"  prompt starting with {first_token}: "
            f"max={diff.max().item():.6f} at pos={pos} "
            f"ref={ref[first_token][pos].item():.6f} "
            f"cur={cur[first_token][pos].item():.6f}"
        )

llm = LLM(
    "EleutherAI/pythia-14m",
    dtype="float32",
    gpu_memory_utilization=0.5,
    # enable_prefix_caching=False makes this repro print exact zeros.
)

try:
    ref = score(llm, (0, 1, 2))
    same_order = score(llm, (0, 1, 2))
    shuffled_order = score(llm, (2, 0, 1))

    print_diff("same order repeated:", ref, same_order)
    print_diff("after scoring shuffled order (2, 0, 1):", ref, shuffled_order)
finally:
    try:
        llm.llm_engine.engine_core.shutdown()
    except Exception:
        pass
    del llm
    gc.collect()
    if torch.cuda.is_available():
        torch.cuda.empty_cache()

---

same order repeated:
  prompt starting with 1: max=0.000000 at pos=0 ref=0.000000 cur=0.000000
  prompt starting with 2: max=0.000000 at pos=0 ref=0.000000 cur=0.000000
  prompt starting with 3: max=0.000000 at pos=0 ref=0.000000 cur=0.000000

after scoring shuffled order (2, 0, 1):
  prompt starting with 1: max=0.037937 at pos=30 ref=-5.427786 cur=-5.465723
  prompt starting with 2: max=0.013506 at pos=15 ref=-2.306305 cur=-2.319810
  prompt starting with 3: max=0.022612 at pos=13 ref=-2.395505 cur=-2.372894

---

vllm 0.19.0
torch 2.10.0+cu128
CUDA 12.8
GPU: RTX 4090
Model: EleutherAI/pythia-14m
dtype: float32
RAW_BUFFERClick to expand / collapse

Your current environment

<details> <summary>The output of <code>python collect_env.py</code></summary>
==============================
        System Info
==============================
OS                           : Ubuntu 24.04.4 LTS (x86_64)
GCC version                  : (Ubuntu 13.3.0-6ubuntu2~24.04.1) 13.3.0
Clang version                : Could not collect
CMake version                : version 4.3.1
Libc version                 : glibc-2.39

==============================
       PyTorch Info
==============================
PyTorch version              : 2.10.0+cu128
Is debug build               : False
CUDA used to build PyTorch   : 12.8
ROCM used to build PyTorch   : N/A
XPU used to build PyTorch    : N/A

==============================
      Python Environment
==============================
Python version               : 3.11.7 (main, Dec 15 2023, 18:12:31) [GCC 11.2.0] (64-bit runtime)
Python platform              : Linux-6.8.0-111-generic-x86_64-with-glibc2.39
    
==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : 12.0.140
CUDA_MODULE_LOADING set to   : 
GPU models and configuration : 
GPU 0: NVIDIA GeForce RTX 4090
GPU 1: NVIDIA GeForce RTX 4090

Nvidia driver version        : 570.172.08
cuDNN version                : Probably one of the following:
/usr/lib/x86_64-linux-gnu/libcudnn.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_adv.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_cnn.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_precompiled.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_engines_runtime_compiled.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_graph.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_heuristic.so.9.7.1
/usr/lib/x86_64-linux-gnu/libcudnn_ops.so.9.7.1
HIP runtime version          : N/A
MIOpen runtime version       : N/A
Is XNNPACK available         : True

==============================
          CPU Info
==============================
Architecture:                            x86_64
CPU op-mode(s):                          32-bit, 64-bit
Address sizes:                           46 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  32
On-line CPU(s) list:                     0-31
Vendor ID:                               GenuineIntel
Model name:                              13th Gen Intel(R) Core(TM) i9-13900K
CPU family:                              6
Model:                                   183
Thread(s) per core:                      2
Core(s) per socket:                      24
Socket(s):                               1
Stepping:                                1
CPU(s) scaling MHz:                      30%
CPU max MHz:                             5800.0000
CPU min MHz:                             800.0000
BogoMIPS:                                5990.40
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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb ssbd ibrs ibpb stibp ibrs_enhanced tpr_shadow flexpriority ept vpid ept_ad fsgsbase tsc_adjust bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb intel_pt sha_ni xsaveopt xsavec xgetbv1 xsaves split_lock_detect user_shstk avx_vnni dtherm ida arat pln pts hwp hwp_notify hwp_act_window hwp_epp hwp_pkg_req hfi vnmi umip pku ospke waitpkg gfni vaes vpclmulqdq tme rdpid movdiri movdir64b fsrm md_clear serialize pconfig arch_lbr ibt flush_l1d arch_capabilities ibpb_exit_to_user
Virtualization:                          VT-x
L1d cache:                               896 KiB (24 instances)
L1i cache:                               1.3 MiB (24 instances)
L2 cache:                                32 MiB (12 instances)
L3 cache:                                36 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-31
Vulnerability Gather data sampling:      Not affected
Vulnerability Indirect target selection: Not affected
Vulnerability Itlb multihit:             Not affected
Vulnerability L1tf:                      Not affected
Vulnerability Mds:                       Not affected
Vulnerability Meltdown:                  Not affected
Vulnerability Mmio stale data:           Not affected
Vulnerability Reg file data sampling:    Mitigation; Clear Register File
Vulnerability Retbleed:                  Not affected
Vulnerability Spec rstack overflow:      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 / Automatic IBRS; IBPB conditional; PBRSB-eIBRS SW sequence; BHI BHI_DIS_S
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Not affected
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

==============================
Versions of relevant libraries
==============================
[pip3] flake8==6.0.0
[pip3] flashinfer-python==0.6.6
[pip3] mypy==1.8.0
[pip3] mypy-extensions==1.0.0
[pip3] numpy==2.4.4
[pip3] numpydoc==1.5.0
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cutlass-dsl==4.5.0.dev0
[pip3] nvidia-cutlass-dsl-libs-base==4.5.0.dev0
[pip3] nvidia-ml-py==13.595.45
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.4.5
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] pyzmq==25.1.2
[pip3] torch==2.10.0
[pip3] torch_c_dlpack_ext==0.1.5
[pip3] torchaudio==2.10.0
[pip3] torchvision==0.25.0
[pip3] transformers==4.57.6
[pip3] triton==3.6.0
[conda] _anaconda_depends         2024.02             py311_mkl_1  
[conda] blas                      1.0                         mkl  
[conda] cuda-cudart               12.1.105                      0    nvidia
[conda] cuda-cupti                12.1.105                      0    nvidia
[conda] cuda-libraries            12.1.0                        0    nvidia
[conda] cuda-nvrtc                12.1.105                      0    nvidia
[conda] cuda-nvtx                 12.1.105                      0    nvidia
[conda] cuda-opencl               12.4.127                      0    nvidia
[conda] cuda-runtime              12.1.0                        0    nvidia
[conda] ffmpeg                    4.3                  hf484d3e_0    pytorch
[conda] flashinfer-python         0.6.6                    pypi_0    pypi
[conda] libcublas                 12.1.0.26                     0    nvidia
[conda] libcufft                  11.0.2.4                      0    nvidia
[conda] libcufile                 1.9.1.3                       0    nvidia
[conda] libcurand                 10.3.5.147                    0    nvidia
[conda] libcusolver               11.4.4.55                     0    nvidia
[conda] libcusparse               12.0.2.55                     0    nvidia
[conda] libjpeg-turbo             2.0.0                h9bf148f_0    pytorch
[conda] libnpp                    12.0.2.50                     0    nvidia
[conda] libnvjitlink              12.1.105                      0    nvidia
[conda] libnvjpeg                 12.1.1.14                     0    nvidia
[conda] mkl                       2023.1.0         h213fc3f_46344  
[conda] mkl-service               2.4.0           py311h5eee18b_1  
[conda] mkl_fft                   1.3.8           py311h5eee18b_0  
[conda] mkl_random                1.2.4           py311hdb19cb5_0  
[conda] numpy                     2.4.4                    pypi_0    pypi
[conda] numpydoc                  1.5.0           py311h06a4308_0  
[conda] nvidia-cublas-cu12        12.8.4.1                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.8.90                  pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.8.93                  pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.8.90                  pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.10.2.21                pypi_0    pypi
[conda] nvidia-cudnn-frontend     1.18.0                   pypi_0    pypi
[conda] nvidia-cufft-cu12         11.3.3.83                pypi_0    pypi
[conda] nvidia-cufile-cu12        1.13.1.3                 pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.9.90                pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.7.3.90                pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.5.8.93                pypi_0    pypi
[conda] nvidia-cusparselt-cu12    0.7.1                    pypi_0    pypi
[conda] nvidia-cutlass-dsl        4.5.0.dev0               pypi_0    pypi
[conda] nvidia-cutlass-dsl-libs-base 4.5.0.dev0               pypi_0    pypi
[conda] nvidia-ml-py              13.595.45                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.27.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.8.93                  pypi_0    pypi
[conda] nvidia-nvshmem-cu12       3.4.5                    pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.8.90                  pypi_0    pypi
[conda] pytorch-cuda              12.1                 ha16c6d3_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pyzmq                     25.1.2          py311h6a678d5_0  
[conda] torch                     2.10.0                   pypi_0    pypi
[conda] torch-c-dlpack-ext        0.1.5                    pypi_0    pypi
[conda] torchaudio                2.10.0                   pypi_0    pypi
[conda] torchvision               0.25.0                   pypi_0    pypi
[conda] transformers              4.57.6                   pypi_0    pypi
[conda] triton                    3.6.0                    pypi_0    pypi

==============================
         vLLM Info
==============================
ROCM Version                 : Could not collect
vLLM Version                 : 0.19.0
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: Disabled; XPU: Disabled
GPU Topology:
        GPU0    GPU1    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      PHB     0-31    0               N/A
GPU1    PHB      X      0-31    0               N/A

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

==============================
     Environment Variables
==============================
PYTORCH_NVML_BASED_CUDA_CHECK=1
</details>

Describe the bug

I found that prompt_logprobs for the same fixed token prompts can change when the same prompts are scored in a different batch order.

This is a scoring-only repro: no sampling path is involved. Each prompt is fixed token ids, and logprobs are read via lp_dict[token_id].logprob.

With enable_prefix_caching=True (default), reordering the requests changes per-token logprobs for the same prompt. With enable_prefix_caching=False, the same test prints exact zeros.

Expected behavior

Reordering independent requests in a batch should not change:

log p(t_k | t_<k)

for any fixed prompt.

Repro

import gc
import torch
from vllm import LLM, SamplingParams

PROMPTS = [
    [1, 10408, 15, 3312, 16315, 7519, 47932, 247, 16204, 275, 4255, 20098, 19083, 15, 2064, 6505, 347, 11853, 665, 1978, 368, 1977, 432, 4076, 8737, 13, 12868, 342, 326, 28148, 2929, 13],
    [2, 187, 6759, 16, 681, 16, 12929, 316, 14, 88, 1087, 16, 73, 1976, 16, 73, 15, 5581, 2, 1387, 4311, 187, 7330, 14, 9150, 9283, 608, 14, 2420, 187, 7330, 14],
    [3, 16440, 323, 368, 24174, 634, 12108, 13, 38857, 17087, 294, 4399, 19083, 15, 2064, 368, 971, 11853, 14565, 1978, 368, 1977, 432, 634, 9781, 13, 403, 1469, 281, 320, 8261, 13],
]

def score(llm, order):
    params = SamplingParams(
        n=1,
        max_tokens=1,
        temperature=0.0,
        prompt_logprobs=0,
        detokenize=False,
    )
    outputs = llm.generate([PROMPTS[i] for i in order], params)

    by_first_token = {}
    for ro in outputs:
        vals = [0.0]
        for lp_dict, token_id in zip(ro.prompt_logprobs[1:], ro.prompt_token_ids[1:]):
            vals.append(float(lp_dict[token_id].logprob))
        by_first_token[int(ro.prompt_token_ids[0])] = torch.tensor(vals)
    return by_first_token

def print_diff(label, ref, cur):
    print(label)
    for first_token in sorted(ref):
        diff = (cur[first_token] - ref[first_token]).abs()
        pos = int(diff.argmax())
        print(
            f"  prompt starting with {first_token}: "
            f"max={diff.max().item():.6f} at pos={pos} "
            f"ref={ref[first_token][pos].item():.6f} "
            f"cur={cur[first_token][pos].item():.6f}"
        )

llm = LLM(
    "EleutherAI/pythia-14m",
    dtype="float32",
    gpu_memory_utilization=0.5,
    # enable_prefix_caching=False makes this repro print exact zeros.
)

try:
    ref = score(llm, (0, 1, 2))
    same_order = score(llm, (0, 1, 2))
    shuffled_order = score(llm, (2, 0, 1))

    print_diff("same order repeated:", ref, same_order)
    print_diff("after scoring shuffled order (2, 0, 1):", ref, shuffled_order)
finally:
    try:
        llm.llm_engine.engine_core.shutdown()
    except Exception:
        pass
    del llm
    gc.collect()
    if torch.cuda.is_available():
        torch.cuda.empty_cache()

Output

same order repeated:
  prompt starting with 1: max=0.000000 at pos=0 ref=0.000000 cur=0.000000
  prompt starting with 2: max=0.000000 at pos=0 ref=0.000000 cur=0.000000
  prompt starting with 3: max=0.000000 at pos=0 ref=0.000000 cur=0.000000

after scoring shuffled order (2, 0, 1):
  prompt starting with 1: max=0.037937 at pos=30 ref=-5.427786 cur=-5.465723
  prompt starting with 2: max=0.013506 at pos=15 ref=-2.306305 cur=-2.319810
  prompt starting with 3: max=0.022612 at pos=13 ref=-2.395505 cur=-2.372894

Environment

vllm 0.19.0
torch 2.10.0+cu128
CUDA 12.8
GPU: RTX 4090
Model: EleutherAI/pythia-14m
dtype: float32

Workaround

Setting enable_prefix_caching=False makes the same repro print exact zeros.

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.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

FAQ

Expected behavior

Reordering independent requests in a batch should not change:

log p(t_k | t_<k)

for any fixed prompt.

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING

vllm - 💡(How to fix) Fix [Bug]: `prompt_logprobs` depends on request order when prefix caching is enabled