Skip to content

[Bug][Regression]: Dimension out of range when using MooncakeStoreConnector #18834

Open
@gronsti-amd

Description

@gronsti-amd

Your current environment

The output of python collect_env.py
==============================
        System Info
==============================
OS                           : Ubuntu 22.04.5 LTS (x86_64)
GCC version                  : (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version                : 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.1 24491 1e0fda770a2079fbd71e4b70974d74f62fd3af10)
CMake version                : version 3.31.6
Libc version                 : glibc-2.35

==============================
       PyTorch Info
==============================
PyTorch version              : 2.7.0+gitf717b2a
Is debug build               : False
CUDA used to build PyTorch   : N/A
ROCM used to build PyTorch   : 6.3.42133-1b9c17779

==============================
      Python Environment
==============================
Python version               : 3.12.10 (main, Apr  9 2025, 08:55:05) [GCC 11.4.0] (64-bit runtime)
Python platform              : Linux-5.15.0-140-generic-x86_64-with-glibc2.35

==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : Could not collect
CUDA_MODULE_LOADING set to   : LAZY
GPU models and configuration : AMD Instinct MI300X (gfx942:sramecc+:xnack-)
Nvidia driver version        : Could not collect
cuDNN version                : Could not collect
HIP runtime version          : 6.3.42133
MIOpen runtime version       : 3.3.0
Is XNNPACK available         : True

==============================
          CPU Info
==============================
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):                               128
On-line CPU(s) list:                  0-127
Vendor ID:                            AuthenticAMD
Model name:                           AMD EPYC 9354 32-Core Processor
CPU family:                           25
Model:                                17
Thread(s) per core:                   2
Core(s) per socket:                   32
Socket(s):                            2
Stepping:                             1
Frequency boost:                      enabled
CPU max MHz:                          3250.0000
CPU min MHz:                          1500.0000
BogoMIPS:                             6490.32
Flags:                                fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ht syscall nx mmxext fxsr_opt pdpe1gb rdtscp lm constant_tsc rep_good nopl nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt aes xsave avx f16c rdrand lahf_lm cmp_legacy svm extapic cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw ibs skinit wdt tce topoext perfctr_core perfctr_nb bpext perfctr_llc mwaitx cpb cat_l3 cdp_l3 invpcid_single hw_pstate ssbd mba ibrs ibpb stibp ibrs_enhanced vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid cqm rdt_a avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd amd_ppin cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid overflow_recov succor smca fsrm flush_l1d
Virtualization:                       AMD-V
L1d cache:                            2 MiB (64 instances)
L1i cache:                            2 MiB (64 instances)
L2 cache:                             64 MiB (64 instances)
L3 cache:                             512 MiB (16 instances)
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-31,64-95
NUMA node1 CPU(s):                    32-63,96-127
Vulnerability Gather data sampling:   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: Not affected
Vulnerability Retbleed:               Not affected
Vulnerability Spec rstack overflow:   Mitigation; safe RET
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 / Automatic IBRS; IBPB conditional; STIBP always-on; RSB filling; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Not affected

==============================
Versions of relevant libraries
==============================
[pip3] numpy==1.26.4
[pip3] pyzmq==26.4.0
[pip3] torch==2.7.0+gitf717b2a
[pip3] torchvision==0.21.0+7af6987
[pip3] transformers==4.52.3
[pip3] triton==3.2.0+gite5be006a
[conda] Could not collect

==============================
         vLLM Info
==============================
ROCM Version                 : 6.3.42133-1b9c17779
Neuron SDK Version           : N/A
vLLM Version                 : 0.9.1.dev18+gce75efeec (git sha: ce75efeec)
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
  ============================ ROCm System Management Interface ============================
================================ Weight between two GPUs =================================
       GPU0         GPU1         GPU2         GPU3         GPU4         GPU5         GPU6         GPU7         
GPU0   0            15           15           15           15           15           15           15           
GPU1   15           0            15           15           15           15           15           15           
GPU2   15           15           0            15           15           15           15           15           
GPU3   15           15           15           0            15           15           15           15           
GPU4   15           15           15           15           0            15           15           15           
GPU5   15           15           15           15           15           0            15           15           
GPU6   15           15           15           15           15           15           0            15           
GPU7   15           15           15           15           15           15           15           0            

================================= Hops between two GPUs ==================================
       GPU0         GPU1         GPU2         GPU3         GPU4         GPU5         GPU6         GPU7         
GPU0   0            1            1            1            1            1            1            1            
GPU1   1            0            1            1            1            1            1            1            
GPU2   1            1            0            1            1            1            1            1            
GPU3   1            1            1            0            1            1            1            1            
GPU4   1            1            1            1            0            1            1            1            
GPU5   1            1            1            1            1            0            1            1            
GPU6   1            1            1            1            1            1            0            1            
GPU7   1            1            1            1            1            1            1            0            

=============================== Link Type between two GPUs ===============================
       GPU0         GPU1         GPU2         GPU3         GPU4         GPU5         GPU6         GPU7         
GPU0   0            XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         
GPU1   XGMI         0            XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         
GPU2   XGMI         XGMI         0            XGMI         XGMI         XGMI         XGMI         XGMI         
GPU3   XGMI         XGMI         XGMI         0            XGMI         XGMI         XGMI         XGMI         
GPU4   XGMI         XGMI         XGMI         XGMI         0            XGMI         XGMI         XGMI         
GPU5   XGMI         XGMI         XGMI         XGMI         XGMI         0            XGMI         XGMI         
GPU6   XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         0            XGMI         
GPU7   XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         XGMI         0            

======================================= Numa Nodes =======================================
GPU[0]          : (Topology) Numa Node: 0
GPU[0]          : (Topology) Numa Affinity: 0
GPU[1]          : (Topology) Numa Node: 0
GPU[1]          : (Topology) Numa Affinity: 0
GPU[2]          : (Topology) Numa Node: 0
GPU[2]          : (Topology) Numa Affinity: 0
GPU[3]          : (Topology) Numa Node: 0
GPU[3]          : (Topology) Numa Affinity: 0
GPU[4]          : (Topology) Numa Node: 1
GPU[4]          : (Topology) Numa Affinity: 1
GPU[5]          : (Topology) Numa Node: 1
GPU[5]          : (Topology) Numa Affinity: 1
GPU[6]          : (Topology) Numa Node: 1
GPU[6]          : (Topology) Numa Affinity: 1
GPU[7]          : (Topology) Numa Node: 1
GPU[7]          : (Topology) Numa Affinity: 1
================================== End of ROCm SMI Log ===================================

==============================
     Environment Variables
==============================
PYTORCH_TUNABLEOP_TUNING=0
PYTORCH_TUNABLEOP_ENABLED=1
VLLM_WORKER_MULTIPROC_METHOD=spawn
PYTORCH_ROCM_ARCH=gfx90a;gfx942;gfx1100;gfx1101;gfx1200;gfx1201
LD_LIBRARY_PATH=/opt/rocm/lib:/usr/local/lib:
PYTORCH_TUNABLEOP_FILENAME=/app/afo_tune_device_%d_full.csv
NCCL_CUMEM_ENABLE=0
PYTORCH_NVML_BASED_CUDA_CHECK=1
TORCHINDUCTOR_COMPILE_THREADS=1
CUDA_MODULE_LOADING=LAZY

🐛 Describe the bug

When using disaggregated prefill with the mooncake store connector, the decoding instance crashes with an IndexError: Dimension out of range from the reshape_and_cache_flash kernel.

The bug is not triggered when using normal non-disaggregated serving with the same model. It seems that it is the vLLM Mooncake integration not conforming to the new expected shape of the KV cache.

The bug appears to be a regression, triggered by the following change: (#16605)

commit 9e96f56efb5b44a12d9d516276daa5538700a211 2025-04-26 Shu Wang <[email protected]> Allocate kv_cache with stride order (#16605)                                                
9e96f56efb csrc/cache_kernels.cu (Shu Wang           2025-04-26 00:03:31 -0500 439)   int64_t page_stride = key_cache.stride(1);                                                  
9e96f56efb csrc/cache_kernels.cu (Shu Wang           2025-04-26 00:03:31 -0500 440)   int64_t head_stride = key_cache.stride(2);    
Sample script to reproduce:
#!/bin/bash
set -eux

apt-get install --yes iproute2

LOCAL_IP=$(ip route get 1.2.3.4 | cut -d' ' -f7)
MODEL="meta-llama/Meta-Llama-3.1-8B-Instruct"

start_vllm() {
    instance_name=$1
    port=$2
    visible_devices=$3
    kv_role=$4
    kv_rank=$5
    tp_flag=$6

    CUDA_VISIBLE_DEVICES=${visible_devices} LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH MOONCAKE_CONFIG_PATH=./mooncake.json vllm serve ${MODEL} \
        --port ${port} \
        --max-model-len 12000 \
        --max-num-batched-tokens 12000 \
        --gpu-memory-utilization 0.95 \
        ${tp_flag} \
        --kv-transfer-config '{"kv_connector":"MooncakeStoreConnector", "kv_role":"'$kv_role'", "kv_rank":'$kv_rank', "kv_parallel_size":2}' &
}

etcd --listen-client-urls http://${LOCAL_IP}:2379 --advertise-client-urls http://${LOCAL_IP}:2379 &
mooncake_master --port 50001 &

start_vllm "instance_1" 8100 "0" kv_producer 0 ""
start_vllm "instance_2" 8200 "4" kv_consumer 1 ""

# Confirm that the server is running
sleep 40
until curl http://localhost:8200/health; do sleep 5; done

python3 disagg_proxy_demo.py --model $MODEL --prefill localhost:8100 --decode localhost:8200 --port 8000 &

sleep 10

curl -X POST -s http://localhost:8000/v1/completions -H "Content-Type: application/json" -d '{"model": "'$MODEL'","prompt": "San Francisco is a","max_
tokens": 50,"temperature": 0, "top_k":1}' | awk -F'"' '{print $22}' &

wait

Error message:

ERROR 05-28 10:18:40 [engine.py:164] IndexError('Dimension out of range (expected to be in range of [-2, 1], but got 2)')^M
ERROR 05-28 10:18:40 [engine.py:164] Traceback (most recent call last):^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/engine/multiprocessing/engine.py", line 162, in start^M
ERROR 05-28 10:18:40 [engine.py:164]     self.run_engine_loop()^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/engine/multiprocessing/engine.py", line 225, in run_engine_loop^M
ERROR 05-28 10:18:40 [engine.py:164]     request_outputs = self.engine_step()^M
ERROR 05-28 10:18:40 [engine.py:164]                       ^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/engine/multiprocessing/engine.py", line 251, in engine_step^M
ERROR 05-28 10:18:40 [engine.py:164]     raise e^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/engine/multiprocessing/engine.py", line 234, in engine_step^M
ERROR 05-28 10:18:40 [engine.py:164]     return self.engine.step()^M
ERROR 05-28 10:18:40 [engine.py:164]            ^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/engine/llm_engine.py", line 1393, in step^M
ERROR 05-28 10:18:40 [engine.py:164]     outputs = self.model_executor.execute_model(^M
ERROR 05-28 10:18:40 [engine.py:164]               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/executor/executor_base.py", line 140, in execute_model^M
ERROR 05-28 10:18:40 [engine.py:164]     output = self.collective_rpc("execute_model",^M
ERROR 05-28 10:18:40 [engine.py:164]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/executor/uniproc_executor.py", line 56, in collective_rpc^M
ERROR 05-28 10:18:40 [engine.py:164]     answer = run_method(self.driver_worker, method, args, kwargs)^M
ERROR 05-28 10:18:40 [engine.py:164]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/utils.py", line 2605, in run_method^M
ERROR 05-28 10:18:40 [engine.py:164]     return func(*args, **kwargs)^M
ERROR 05-28 10:18:40 [engine.py:164]            ^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/worker/worker_base.py", line 420, in execute_model^M
ERROR 05-28 10:18:40 [engine.py:164]     output = self.model_runner.execute_model(^M
ERROR 05-28 10:18:40 [engine.py:164]              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/usr/local/lib/python3.12/dist-packages/torch/utils/_contextlib.py", line 116, in decorate_context^M
ERROR 05-28 10:18:40 [engine.py:164]     return func(*args, **kwargs)^M
ERROR 05-28 10:18:40 [engine.py:164]            ^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/worker/model_runner.py", line 1817, in execute_model^M
ERROR 05-28 10:18:40 [engine.py:164]     get_kv_transfer_group().recv_kv_caches_and_hidden_states(^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/distributed/kv_transfer/kv_connector/mooncake_store_connector.py", line 174, in recv_kv_caches_  and_hidden_states^M
ERROR 05-28 10:18:40 [engine.py:164]     self.kv_helper.put_kv_to_cache(model_executable, remote_k,^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/distributed/kv_transfer/kv_connector/utils.py", line 82, in put_kv_to_cache^M
ERROR 05-28 10:18:40 [engine.py:164]     ops.reshape_and_cache_flash(^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/opt/vllm/vllm/_custom_ops.py", line 1564, in reshape_and_cache_flash^M
ERROR 05-28 10:18:40 [engine.py:164]     torch.ops._C_cache_ops.reshape_and_cache_flash(key, value, key_cache,^M
ERROR 05-28 10:18:40 [engine.py:164]   File "/usr/local/lib/python3.12/dist-packages/torch/_ops.py", line 1158, in __call__^M
ERROR 05-28 10:18:40 [engine.py:164]     return self._op(*args, **(kwargs or {}))^M
ERROR 05-28 10:18:40 [engine.py:164]            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^M
ERROR 05-28 10:18:40 [engine.py:164] IndexError: Dimension out of range (expected to be in range of [-2, 1], but got 2)

### Before submitting a new issue...

- [x] Make sure you already searched for relevant issues, and asked the chatbot living at the bottom right corner of the [documentation page](https://docs.vllm.ai/en/latest/), which can answer lots of frequently asked questions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions