vllm - ✅(Solved) Fix [Bug]: HunyuanOCR crashes with "query and key must have the same dtype" during inference (vLLM 0.19.0, RTX 3050) [1 pull requests, 2 comments, 2 participants]

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…
GitHub stats
vllm-project/vllm#40165Fetched 2026-04-18 05:52:14
View on GitHub
Comments
2
Participants
2
Timeline
5
Reactions
0
Timeline (top)
commented ×2cross-referenced ×1labeled ×1referenced ×1

When serving tencent/HunyuanOCR with vLLM, the server starts successfully but crashes during the first inference request.

The error occurs inside the attention backend (flash_attn_varlen_func) with:

RuntimeError: query and key must have the same dtype

This happens even when forcing:

  • --dtype half
  • --enforce-eager

So it does not appear related to CUDA graph or compilation.


Error Message

  • Server starts successfully
  • First multimodal request (text + image) triggers model execution
  • Engine crashes during attention forward pass

Root Cause

When serving tencent/HunyuanOCR with vLLM, the server starts successfully but crashes during the first inference request.

The error occurs inside the attention backend (flash_attn_varlen_func) with:

RuntimeError: query and key must have the same dtype

This happens even when forcing:

  • --dtype half
  • --enforce-eager

So it does not appear related to CUDA graph or compilation.


Fix Action

Fix / Workaround

============================== CPU Info

Architecture: x86_64 CPU op-mode(s): 32-bit, 64-bit Address sizes: 39 bits physical, 48 bits virtual Byte Order: Little Endian CPU(s): 20 On-line CPU(s) list: 0-19 Vendor ID: GenuineIntel Model name: 12th Gen Intel(R) Core(TM) i7-12700F CPU family: 6 Model: 151 Thread(s) per core: 2 Core(s) per socket: 12 Socket(s): 1 Stepping: 2 CPU(s) scaling MHz: 82% CPU max MHz: 4900.0000 CPU min MHz: 800.0000 BogoMIPS: 4224.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx 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 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 rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities Virtualization: VT-x L1d cache: 512 KiB (12 instances) L1i cache: 512 KiB (12 instances) L2 cache: 12 MiB (9 instances) L3 cache: 25 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-19 Vulnerability Gather data sampling: Not affected Vulnerability Ghostwrite: 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 Old microcode: 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

PR fix notes

PR #40180: [Bugfix] Fix dtype mismatch in XDRotaryEmbedding for HunyuanOCR

Description (problem / solution / changelog)

Fixes #40165

Purpose

HunyuanOCR / HunyuanV1 crashes with a dtype mismatch during inference:

RuntimeError: query and key must have the same dtype

Root cause: XDRotaryEmbedding.forward_native() and forward_cuda() in xdrope.py access self.cos_sin_cache[positions] directly without calling self._match_cos_sin_cache_dtype(query) first. This is the only rotary embedding variant in vLLM that skips this dtype safety call.

When the cache is float32 and query is float16/bfloat16, rotary embedding promotes query to float32 via PyTorch dtype promotion. Key gets written to the KV cache (allocated in model dtype) and cast down. Then flash_attn_varlen_func(q=float32, k_cache=float16) crashes.

Fix: Add the missing _match_cos_sin_cache_dtype(query) call in both methods, matching the pattern used by RotaryEmbedding, MRotaryEmbedding, and DeepSeekScalingRotaryEmbedding.

# Before (both methods):
cos_sin = self.cos_sin_cache[positions]

# After:
cos_sin_cache = self._match_cos_sin_cache_dtype(query)
cos_sin = cos_sin_cache[positions]

Test Plan

pytest tests/kernels/core/test_xdrope.py -xvs

Three regression tests added:

  • test_xdrope_dtype_mismatch_forward_native — cache=float32, query=fp16/bf16, tokens=1/11/128
  • test_xdrope_dtype_mismatch_forward_cuda — same for CUDA path
  • test_xdrope_native_vs_cuda_consistency — numerical equivalence between native and CUDA paths

Test Result

py_compile: PASS (both xdrope.py and test_xdrope.py)
ruff check: PASS
ruff format: PASS
mypy: PASS
pre-commit: all hooks PASS
Full pytest requires CUDA — will run in CI.

cc @Isotr0py @ywang96

Changed files

  • tests/kernels/core/test_xdrope.py (added, +216/-0)
  • vllm/model_executor/layers/rotary_embedding/xdrope.py (modified, +4/-2)

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                : Could not collect
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.12.13 | packaged by Anaconda, Inc. | (main, Mar 19 2026, 20:20:58) [GCC 14.3.0] (64-bit runtime)
Python platform              : Linux-6.17.0-20-generic-x86_64-with-glibc2.39
    
==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : Could not collect
CUDA_MODULE_LOADING set to   : 
GPU models and configuration : GPU 0: NVIDIA GeForce RTX 3050
Nvidia driver version        : 580.126.09
cuDNN version                : Could not collect
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:                           39 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  20
On-line CPU(s) list:                     0-19
Vendor ID:                               GenuineIntel
Model name:                              12th Gen Intel(R) Core(TM) i7-12700F
CPU family:                              6
Model:                                   151
Thread(s) per core:                      2
Core(s) per socket:                      12
Socket(s):                               1
Stepping:                                2
CPU(s) scaling MHz:                      82%
CPU max MHz:                             4900.0000
CPU min MHz:                             800.0000
BogoMIPS:                                4224.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx 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 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 rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               512 KiB (12 instances)
L1i cache:                               512 KiB (12 instances)
L2 cache:                                12 MiB (9 instances)
L3 cache:                                25 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-19
Vulnerability Gather data sampling:      Not affected
Vulnerability Ghostwrite:                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 Old microcode:             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] flashinfer-python==0.6.6
[pip3] numpy==2.2.6
[pip3] nvidia-cublas==13.1.0.3
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti==13.0.85
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc==13.0.88
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime==13.0.96
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-cu13==9.19.0.56
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft==12.0.0.61
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile==1.15.1.6
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand==10.4.0.35
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver==12.0.4.66
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse==12.6.3.3
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cusparselt-cu13==0.8.0
[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-nccl-cu13==2.28.9
[pip3] nvidia-nvjitlink==13.0.88
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.4.5
[pip3] nvidia-nvshmem-cu13==3.4.5
[pip3] nvidia-nvtx==13.0.85
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] onnxruntime==1.24.4
[pip3] pyzmq==27.1.0
[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] flashinfer-python                           0.6.6            pypi_0           pypi
[conda] numpy                                       2.2.6            pypi_0           pypi
[conda] nvidia-cublas                               13.1.0.3         pypi_0           pypi
[conda] nvidia-cublas-cu12                          12.8.4.1         pypi_0           pypi
[conda] nvidia-cuda-cupti                           13.0.85          pypi_0           pypi
[conda] nvidia-cuda-cupti-cu12                      12.8.90          pypi_0           pypi
[conda] nvidia-cuda-nvrtc                           13.0.88          pypi_0           pypi
[conda] nvidia-cuda-nvrtc-cu12                      12.8.93          pypi_0           pypi
[conda] nvidia-cuda-runtime                         13.0.96          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-cu13                           9.19.0.56        pypi_0           pypi
[conda] nvidia-cudnn-frontend                       1.18.0           pypi_0           pypi
[conda] nvidia-cufft                                12.0.0.61        pypi_0           pypi
[conda] nvidia-cufft-cu12                           11.3.3.83        pypi_0           pypi
[conda] nvidia-cufile                               1.15.1.6         pypi_0           pypi
[conda] nvidia-cufile-cu12                          1.13.1.3         pypi_0           pypi
[conda] nvidia-curand                               10.4.0.35        pypi_0           pypi
[conda] nvidia-curand-cu12                          10.3.9.90        pypi_0           pypi
[conda] nvidia-cusolver                             12.0.4.66        pypi_0           pypi
[conda] nvidia-cusolver-cu12                        11.7.3.90        pypi_0           pypi
[conda] nvidia-cusparse                             12.6.3.3         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-cusparselt-cu13                      0.8.0            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-nccl-cu13                            2.28.9           pypi_0           pypi
[conda] nvidia-nvjitlink                            13.0.88          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-nvshmem-cu13                         3.4.5            pypi_0           pypi
[conda] nvidia-nvtx                                 13.0.85          pypi_0           pypi
[conda] nvidia-nvtx-cu12                            12.8.90          pypi_0           pypi
[conda] pyzmq                                       27.1.0           pypi_0           pypi
[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    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      0-19    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
TORCHINDUCTOR_COMPILE_THREADS=1
TORCHINDUCTOR_CACHE_DIR=/tmp/torchinductor_txhung

---

RuntimeError: query and key must have the same dtype

---

vllm serve tencent/HunyuanOCR \
  --dtype half \
  --no-enable-prefix-caching \
  --mm-processor-cache-gb 0 \
  --gpu-memory-utilization 0.8 \
  --host 0.0.0.0 \
  --port 8082 \
  --enforce-eager

---

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8082/v1",
    api_key="EMPTY",
)

response = client.chat.completions.create(
    model="tencent/HunyuanOCR",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Extract text from this image."},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/test.png"
                    },
                },
            ],
        }
    ],
    temperature=0.0,
    max_tokens=256,
)

print(response)

---

RuntimeError: query and key must have the same dtype

---

[EngineCore] Dumping input data (vLLM 0.19.0)
- model: tencent/HunyuanOCR
- dtype: torch.float16
- enforce_eager: True

Multi-modal input:
- pixel_values dtype: torch.float16
- modality: image

---

Crash happens during attention:

File "hunyuan_v1.py", line 245:
    attn_output = self.attn(q, k, v)

→ inside vLLM attention:

File "attention.py":
    unified_attention_with_output(...)

→ backend:

File "flash_attn.py":
    flash_attn_varlen_func(...)

→ error:

RuntimeError: query and key must have the same dtype

---

(EngineCore) RuntimeError: query and key must have the same dtype

Stack trace:

- hunyuan_vision.py → language_model
- hunyuan_v1.py → model forward
- hunyuan_v1.py → decoder layer
- hunyuan_v1.py → self_attn
- attention.py → unified_attention_with_output
- flash_attn.py → flash_attn_varlen_func

Final exception:

vllm.v1.engine.exceptions.EngineDeadError: EngineCore encountered an issue
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                : Could not collect
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.12.13 | packaged by Anaconda, Inc. | (main, Mar 19 2026, 20:20:58) [GCC 14.3.0] (64-bit runtime)
Python platform              : Linux-6.17.0-20-generic-x86_64-with-glibc2.39
    
==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : Could not collect
CUDA_MODULE_LOADING set to   : 
GPU models and configuration : GPU 0: NVIDIA GeForce RTX 3050
Nvidia driver version        : 580.126.09
cuDNN version                : Could not collect
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:                           39 bits physical, 48 bits virtual
Byte Order:                              Little Endian
CPU(s):                                  20
On-line CPU(s) list:                     0-19
Vendor ID:                               GenuineIntel
Model name:                              12th Gen Intel(R) Core(TM) i7-12700F
CPU family:                              6
Model:                                   151
Thread(s) per core:                      2
Core(s) per socket:                      12
Socket(s):                               1
Stepping:                                2
CPU(s) scaling MHz:                      82%
CPU max MHz:                             4900.0000
CPU min MHz:                             800.0000
BogoMIPS:                                4224.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 tsc_known_freq pni pclmulqdq dtes64 monitor ds_cpl vmx 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 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 rdpid movdiri movdir64b fsrm md_clear serialize arch_lbr ibt flush_l1d arch_capabilities
Virtualization:                          VT-x
L1d cache:                               512 KiB (12 instances)
L1i cache:                               512 KiB (12 instances)
L2 cache:                                12 MiB (9 instances)
L3 cache:                                25 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-19
Vulnerability Gather data sampling:      Not affected
Vulnerability Ghostwrite:                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 Old microcode:             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] flashinfer-python==0.6.6
[pip3] numpy==2.2.6
[pip3] nvidia-cublas==13.1.0.3
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti==13.0.85
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc==13.0.88
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime==13.0.96
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-cu13==9.19.0.56
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft==12.0.0.61
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile==1.15.1.6
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand==10.4.0.35
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver==12.0.4.66
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse==12.6.3.3
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cusparselt-cu13==0.8.0
[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-nccl-cu13==2.28.9
[pip3] nvidia-nvjitlink==13.0.88
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.4.5
[pip3] nvidia-nvshmem-cu13==3.4.5
[pip3] nvidia-nvtx==13.0.85
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] onnxruntime==1.24.4
[pip3] pyzmq==27.1.0
[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] flashinfer-python                           0.6.6            pypi_0           pypi
[conda] numpy                                       2.2.6            pypi_0           pypi
[conda] nvidia-cublas                               13.1.0.3         pypi_0           pypi
[conda] nvidia-cublas-cu12                          12.8.4.1         pypi_0           pypi
[conda] nvidia-cuda-cupti                           13.0.85          pypi_0           pypi
[conda] nvidia-cuda-cupti-cu12                      12.8.90          pypi_0           pypi
[conda] nvidia-cuda-nvrtc                           13.0.88          pypi_0           pypi
[conda] nvidia-cuda-nvrtc-cu12                      12.8.93          pypi_0           pypi
[conda] nvidia-cuda-runtime                         13.0.96          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-cu13                           9.19.0.56        pypi_0           pypi
[conda] nvidia-cudnn-frontend                       1.18.0           pypi_0           pypi
[conda] nvidia-cufft                                12.0.0.61        pypi_0           pypi
[conda] nvidia-cufft-cu12                           11.3.3.83        pypi_0           pypi
[conda] nvidia-cufile                               1.15.1.6         pypi_0           pypi
[conda] nvidia-cufile-cu12                          1.13.1.3         pypi_0           pypi
[conda] nvidia-curand                               10.4.0.35        pypi_0           pypi
[conda] nvidia-curand-cu12                          10.3.9.90        pypi_0           pypi
[conda] nvidia-cusolver                             12.0.4.66        pypi_0           pypi
[conda] nvidia-cusolver-cu12                        11.7.3.90        pypi_0           pypi
[conda] nvidia-cusparse                             12.6.3.3         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-cusparselt-cu13                      0.8.0            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-nccl-cu13                            2.28.9           pypi_0           pypi
[conda] nvidia-nvjitlink                            13.0.88          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-nvshmem-cu13                         3.4.5            pypi_0           pypi
[conda] nvidia-nvtx                                 13.0.85          pypi_0           pypi
[conda] nvidia-nvtx-cu12                            12.8.90          pypi_0           pypi
[conda] pyzmq                                       27.1.0           pypi_0           pypi
[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    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      0-19    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
TORCHINDUCTOR_COMPILE_THREADS=1
TORCHINDUCTOR_CACHE_DIR=/tmp/torchinductor_txhung
</details>

🐛 Describe the bug

🐛 Bug Report

Description

When serving tencent/HunyuanOCR with vLLM, the server starts successfully but crashes during the first inference request.

The error occurs inside the attention backend (flash_attn_varlen_func) with:

RuntimeError: query and key must have the same dtype

This happens even when forcing:

  • --dtype half
  • --enforce-eager

So it does not appear related to CUDA graph or compilation.


Reproduction

Command

vllm serve tencent/HunyuanOCR \
  --dtype half \
  --no-enable-prefix-caching \
  --mm-processor-cache-gb 0 \
  --gpu-memory-utilization 0.8 \
  --host 0.0.0.0 \
  --port 8082 \
  --enforce-eager

Request (OpenAI API style)

from openai import OpenAI

client = OpenAI(
    base_url="http://127.0.0.1:8082/v1",
    api_key="EMPTY",
)

response = client.chat.completions.create(
    model="tencent/HunyuanOCR",
    messages=[
        {
            "role": "user",
            "content": [
                {"type": "text", "text": "Extract text from this image."},
                {
                    "type": "image_url",
                    "image_url": {
                        "url": "https://example.com/test.png"
                    },
                },
            ],
        }
    ],
    temperature=0.0,
    max_tokens=256,
)

print(response)

Expected behavior

Model should run inference normally with consistent dtype (FP16).

Environment

  • vLLM: 0.19.0
  • PyTorch: 2.10.0+cu128
  • GPU: NVIDIA GeForce RTX 3050 (Ampere)
  • CUDA: 13.0

Notes

  • Issue reproducible with both:
    • local model path
    • tencent/HunyuanOCR from HuggingFace
  • Tried:
    • --dtype half → still crashes
    • --enforce-eager → still crashes
    • upgrading vLLM from 0.18.0 → 0.19.0 → same issue
  • TORCH_SDPA backend is not available in this build
  • Issue does not occur when using Transformers inference

Observed behavior

  • Server starts successfully
  • First multimodal request (text + image) triggers model execution
  • Engine crashes during attention forward pass

The failure happens inside FlashAttention backend.

Error:

RuntimeError: query and key must have the same dtype

Logs

[EngineCore] Dumping input data (vLLM 0.19.0)
- model: tencent/HunyuanOCR
- dtype: torch.float16
- enforce_eager: True

Multi-modal input:
- pixel_values dtype: torch.float16
- modality: image

---

Crash happens during attention:

File "hunyuan_v1.py", line 245:
    attn_output = self.attn(q, k, v)

→ inside vLLM attention:

File "attention.py":
    unified_attention_with_output(...)

→ backend:

File "flash_attn.py":
    flash_attn_varlen_func(...)

→ error:

RuntimeError: query and key must have the same dtype

Full traceback:

(EngineCore) RuntimeError: query and key must have the same dtype

Stack trace:

- hunyuan_vision.py → language_model
- hunyuan_v1.py → model forward
- hunyuan_v1.py → decoder layer
- hunyuan_v1.py → self_attn
- attention.py → unified_attention_with_output
- flash_attn.py → flash_attn_varlen_func

Final exception:

vllm.v1.engine.exceptions.EngineDeadError: EngineCore encountered an issue

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.

extent analysis

TL;DR

The most likely fix is to ensure that the query and key tensors in the attention mechanism have the same data type, which can be achieved by explicitly casting them to the same dtype before passing them to the attention function.

Guidance

  • Verify that the query and key tensors have the same dtype by adding a check before calling the attention function.
  • If the dtypes are different, cast one of them to match the other using the to() method, e.g., query = query.to(key.dtype).
  • Check the documentation of the flash_attn_varlen_func function to see if it has any specific requirements or constraints on the input tensors.
  • Consider adding a debug print statement to verify the dtypes of the input tensors before the error occurs.

Example

# Assuming 'q' and 'k' are the query and key tensors
if q.dtype != k.dtype:
    q = q.to(k.dtype)  # Cast query to match key's dtype
attn_output = self.attn(q, k, v)

Notes

  • The error message suggests that the issue is specific to the attention mechanism, so focusing on the input tensors to the attention function is a good starting point.
  • The fact that the issue occurs even with --dtype half and --enforce-eager suggests that the problem is not related to CUDA graph or compilation.
  • The flash_attn_varlen_func function is not a standard PyTorch function, so its behavior and requirements may be specific to the vLLM library.

Recommendation

Apply a workaround by explicitly casting the query and key tensors to the same dtype before passing them to the attention function, as shown in the example code snippet. This should resolve the immediate issue, but it may be worth investigating why the dtypes are different in the first place to ensure that the fix is robust and correct.

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

Model should run inference normally with consistent dtype (FP16).

Still need to ship something?

×6

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

Back to top recommendations

TRENDING