Skip to content

[Bug]: calculate_kv_scales leads to dynamo compilation issue; enforce_eager=True leads to another issue #21640

@CharlieFRuan

Description

@CharlieFRuan

Your current environment

The output of python collect_env.py
# For security purposes, please feel free to check the contents of collect_env.py before running it.
python collect_env.py
--2025-07-26 00:45:07--  https://raw.githubusercontent.com/vllm-project/vllm/main/vllm/collect_env.py
Resolving raw.githubusercontent.com (raw.githubusercontent.com)... 185.199.108.133, 185.199.109.133, 185.199.110.133, ...
Connecting to raw.githubusercontent.com (raw.githubusercontent.com)|185.199.108.133|:443... connected.
HTTP request sent, awaiting response... 200 OK
Length: 28526 (28K) [text/plain]
Saving to: ‘collect_env.py’

collect_env.py                                                                           100%[================================================================================================================================================================================================================================>]  27.86K  --.-KB/s    in 0.006s  

2025-07-26 00:45:08 (4.52 MB/s) - ‘collect_env.py’ saved [28526/28526]

Collecting environment information...
==============================
        System Info
==============================
OS                           : Ubuntu 22.04.5 LTS (x86_64)
GCC version                  : (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Clang version                : Could not collect
CMake version                : version 3.22.1
Libc version                 : glibc-2.35

==============================
       PyTorch Info
==============================
PyTorch version              : 2.7.1+cu126
Is debug build               : False
CUDA used to build PyTorch   : 12.6
ROCM used to build PyTorch   : N/A

==============================
      Python Environment
==============================
Python version               : 3.10.18 (main, Jun  5 2025, 13:14:17) [GCC 11.2.0] (64-bit runtime)
Python platform              : Linux-6.8.0-60-generic-x86_64-with-glibc2.35

==============================
       CUDA / GPU Info
==============================
Is CUDA available            : True
CUDA runtime version         : 12.8.93
CUDA_MODULE_LOADING set to   : LAZY
GPU models and configuration : 
GPU 0: NVIDIA H100 80GB HBM3
GPU 1: NVIDIA H100 80GB HBM3
GPU 2: NVIDIA H100 80GB HBM3
GPU 3: NVIDIA H100 80GB HBM3
GPU 4: NVIDIA H100 80GB HBM3
GPU 5: NVIDIA H100 80GB HBM3
GPU 6: NVIDIA H100 80GB HBM3
GPU 7: NVIDIA H100 80GB HBM3

Nvidia driver version        : 570.148.08
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:                        52 bits physical, 57 bits virtual
Byte Order:                           Little Endian
CPU(s):                               208
On-line CPU(s) list:                  0-207
Vendor ID:                            GenuineIntel
Model name:                           Intel(R) Xeon(R) Platinum 8480+
CPU family:                           6
Model:                                143
Thread(s) per core:                   2
Core(s) per socket:                   52
Socket(s):                            2
Stepping:                             8
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 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon rep_good nopl xtopology cpuid tsc_known_freq pni pclmulqdq vmx ssse3 fma cx16 pdcm pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor 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 avx512f avx512dq rdseed adx smap avx512ifma clflushopt clwb avx512cd sha_ni avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves avx_vnni avx512_bf16 wbnoinvd arat vnmi avx512vbmi umip pku ospke waitpkg avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq la57 rdpid bus_lock_detect cldemote movdiri movdir64b fsrm md_clear serialize tsxldtrk avx512_fp16 arch_capabilities
Virtualization:                       VT-x
Hypervisor vendor:                    KVM
Virtualization type:                  full
L1d cache:                            6.5 MiB (208 instances)
L1i cache:                            6.5 MiB (208 instances)
L2 cache:                             416 MiB (104 instances)
L3 cache:                             32 MiB (2 instances)
NUMA node(s):                         2
NUMA node0 CPU(s):                    0-103
NUMA node1 CPU(s):                    104-207
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:        Unknown: No mitigations
Vulnerability Reg file data sampling: Not affected
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; RSB filling; PBRSB-eIBRS SW sequence; BHI SW loop, KVM SW loop
Vulnerability Srbds:                  Not affected
Vulnerability Tsx async abort:        Mitigation; TSX disabled

==============================
Versions of relevant libraries
==============================
[pip3] numpy==2.2.6
[pip3] nvidia-cublas-cu12==12.6.4.1
[pip3] nvidia-cuda-cupti-cu12==12.6.80
[pip3] nvidia-cuda-nvrtc-cu12==12.6.77
[pip3] nvidia-cuda-runtime-cu12==12.6.77
[pip3] nvidia-cudnn-cu12==9.5.1.17
[pip3] nvidia-cufft-cu12==11.3.0.4
[pip3] nvidia-cufile-cu12==1.11.1.6
[pip3] nvidia-curand-cu12==10.3.7.77
[pip3] nvidia-cusolver-cu12==11.7.1.2
[pip3] nvidia-cusparse-cu12==12.5.4.2
[pip3] nvidia-cusparselt-cu12==0.6.3
[pip3] nvidia-nccl-cu12==2.26.2
[pip3] nvidia-nvjitlink-cu12==12.6.85
[pip3] nvidia-nvtx-cu12==12.6.77
[pip3] pyzmq==27.0.0
[pip3] torch==2.7.1
[pip3] torchaudio==2.7.1
[pip3] torchvision==0.22.1
[pip3] transformers==4.54.0
[pip3] triton==3.3.1
[conda] numpy                                2.2.6            pypi_0           pypi
[conda] nvidia-cublas-cu12                   12.6.4.1         pypi_0           pypi
[conda] nvidia-cuda-cupti-cu12               12.6.80          pypi_0           pypi
[conda] nvidia-cuda-nvrtc-cu12               12.6.77          pypi_0           pypi
[conda] nvidia-cuda-runtime-cu12             12.6.77          pypi_0           pypi
[conda] nvidia-cudnn-cu12                    9.5.1.17         pypi_0           pypi
[conda] nvidia-cufft-cu12                    11.3.0.4         pypi_0           pypi
[conda] nvidia-cufile-cu12                   1.11.1.6         pypi_0           pypi
[conda] nvidia-curand-cu12                   10.3.7.77        pypi_0           pypi
[conda] nvidia-cusolver-cu12                 11.7.1.2         pypi_0           pypi
[conda] nvidia-cusparse-cu12                 12.5.4.2         pypi_0           pypi
[conda] nvidia-cusparselt-cu12               0.6.3            pypi_0           pypi
[conda] nvidia-nccl-cu12                     2.26.2           pypi_0           pypi
[conda] nvidia-nvjitlink-cu12                12.6.85          pypi_0           pypi
[conda] nvidia-nvtx-cu12                     12.6.77          pypi_0           pypi
[conda] pyzmq                                27.0.0           pypi_0           pypi
[conda] torch                                2.7.1            pypi_0           pypi
[conda] torchaudio                           2.7.1            pypi_0           pypi
[conda] torchvision                          0.22.1           pypi_0           pypi
[conda] transformers                         4.54.0           pypi_0           pypi
[conda] triton                               3.3.1            pypi_0           pypi

==============================
         vLLM Info
==============================
ROCM Version                 : Could not collect
Neuron SDK Version           : N/A
vLLM Version                 : 0.10.0
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
        GPU0    GPU1    GPU2    GPU3    GPU4    GPU5    GPU6    GPU7    NIC0    CPU Affinity    NUMA Affinity   GPU NUMA ID
GPU0     X      NV18    NV18    NV18    NV18    NV18    NV18    NV18    SYS     0-103   0               N/A
GPU1    NV18     X      NV18    NV18    NV18    NV18    NV18    NV18    SYS     0-103   0               N/A
GPU2    NV18    NV18     X      NV18    NV18    NV18    NV18    NV18    SYS     0-103   0               N/A
GPU3    NV18    NV18    NV18     X      NV18    NV18    NV18    NV18    SYS     0-103   0               N/A
GPU4    NV18    NV18    NV18    NV18     X      NV18    NV18    NV18    SYS     104-207 1               N/A
GPU5    NV18    NV18    NV18    NV18    NV18     X      NV18    NV18    SYS     104-207 1               N/A
GPU6    NV18    NV18    NV18    NV18    NV18    NV18     X      NV18    SYS     104-207 1               N/A
GPU7    NV18    NV18    NV18    NV18    NV18    NV18    NV18     X      SYS     104-207 1               N/A
NIC0    SYS     SYS     SYS     SYS     SYS     SYS     SYS     SYS      X 

Legend:

  X    = Self
  SYS  = Connection traversing PCIe as well as the SMP interconnect between NUMA nodes (e.g., QPI/UPI)
  NODE = Connection traversing PCIe as well as the interconnect between PCIe Host Bridges within a NUMA node
  PHB  = Connection traversing PCIe as well as a PCIe Host Bridge (typically the CPU)
  PXB  = Connection traversing multiple PCIe bridges (without traversing the PCIe Host Bridge)
  PIX  = Connection traversing at most a single PCIe bridge
  NV#  = Connection traversing a bonded set of # NVLinks

NIC Legend:

  NIC0: mlx5_0

==============================
     Environment Variables
==============================
LD_LIBRARY_PATH=/usr/mpi/gcc/openmpi-4.1.7rc1/lib:/usr/mpi/gcc/openmpi-4.1.7rc1/lib64
NCCL_CUMEM_ENABLE=0
PYTORCH_NVML_BASED_CUDA_CHECK=1
TORCHINDUCTOR_COMPILE_THREADS=1
CUDA_MODULE_LOADING=LAZY

🐛 Describe the bug

I am on v0.10.0. The argument calculate_kv_scales=True does not seem to work.

If enforce_eager=False

With code:

import vllm

def main():
    engine = vllm.LLM(
        model="/home/ubuntu/models/Qwen3-8B",
        tensor_parallel_size=2,
        kv_cache_dtype="fp8_e4m3",
        calculate_kv_scales=True,
    )
    output = engine.generate("Hello, world!")
    print(output)


if __name__ == "__main__":
    main()

I run into

RuntimeError: Worker failed with error 'Data-dependent branching
  Explanation: Detected data-dependent branching (e.g. `if my_tensor.sum() > 0:`). Dynamo does not support tracing dynamic control flow.
  Hint: This graph break is fundamental - it is unlikely that Dynamo will ever be able to trace through your code. Consider finding a workaround.
  Hint: Use `torch.cond` to express dynamic control flow.

  Developer debug context: attempted to jump with GetAttrVariable(ConstantVariable(NoneType: None), enable_kv_scales_calculation)


from user code:
   File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/vllm/model_executor/models/qwen2.py", line 354, in forward
    hidden_states, residual = layer(
  File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/vllm/model_executor/models/qwen3.py", line 214, in forward
    hidden_states = self.self_attn(
  File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/vllm/model_executor/models/qwen3.py", line 145, in forward
    attn_output = self.attn(q, k, v)
  File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/vllm/attention/layer.py", line 239, in forward
    if attn_metadata.enable_kv_scales_calculation:

Full log here https://gist.github.com/CharlieFRuan/7bfa12f029ddeef496996e5864979530

If enforce_eager=True

With code:

import vllm

def main():
    engine = vllm.LLM(
        model="/home/ubuntu/models/Qwen3-8B",
        tensor_parallel_size=2,
        kv_cache_dtype="fp8_e4m3",
        calculate_kv_scales=True,
        enforce_eager=True,
    )
    output = engine.generate("Hello, world!")
    print(output)


if __name__ == "__main__":
    main()

I run into

(VllmWorker rank=1 pid=87573) ERROR 07-26 00:49:21 [multiproc_executor.py:546]   File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/torch/nn/modules/module.py", line 1762, in _call_impl
(VllmWorker rank=1 pid=87573) ERROR 07-26 00:49:21 [multiproc_executor.py:546]     return forward_call(*args, **kwargs)
(VllmWorker rank=1 pid=87573) ERROR 07-26 00:49:21 [multiproc_executor.py:546]   File "/home/ubuntu/miniconda3/envs/vllm-new/lib/python3.10/site-packages/vllm/attention/layer.py", line 239, in forward
(VllmWorker rank=1 pid=87573) ERROR 07-26 00:49:21 [multiproc_executor.py:546]     if attn_metadata.enable_kv_scales_calculation:
(VllmWorker rank=1 pid=87573) ERROR 07-26 00:49:21 [multiproc_executor.py:546] AttributeError: 'NoneType' object has no attribute 'enable_kv_scales_calculation'

Full log here: https://gist.github.com/CharlieFRuan/6bd380cb135c35aa0a70b80cf9e6eebd

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.

Metadata

Metadata

Assignees

Labels

actionableThere is clear action for a vLLM developer to takebugSomething isn't workingtorch.compile

Type

No type

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions