Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: Speculative decoding breaks guided decoding. #9423

Open
1 task done
roberthoenig opened this issue Oct 16, 2024 · 12 comments · May be fixed by #12537
Open
1 task done

[Bug]: Speculative decoding breaks guided decoding. #9423

roberthoenig opened this issue Oct 16, 2024 · 12 comments · May be fixed by #12537
Labels
bug Something isn't working structured-output

Comments

@roberthoenig
Copy link

Your current environment

The output of `python collect_env.py`
Collecting environment information...
PyTorch version: N/A
Is debug build: N/A
CUDA used to build PyTorch: N/A
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.4 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

Python version: 3.10.12 (main, Jul 29 2024, 16:56:48) [GCC 11.4.0] (64-bit runtime)
Python platform: Linux-5.15.0-1063-azure-x86_64-with-glibc2.35
Is CUDA available: N/A
CUDA runtime version: 12.4.131
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: 
GPU 0: NVIDIA A100 80GB PCIe
GPU 1: NVIDIA A100 80GB PCIe

Nvidia driver version: 535.161.08
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: N/A

CPU:
Architecture:                       x86_64
CPU op-mode(s):                     32-bit, 64-bit
Address sizes:                      48 bits physical, 48 bits virtual
Byte Order:                         Little Endian
CPU(s):                             48
On-line CPU(s) list:                0-47
Vendor ID:                          AuthenticAMD
Model name:                         AMD EPYC 7V13 64-Core Processor
CPU family:                         25
Model:                              1
Thread(s) per core:                 1
Core(s) per socket:                 48
Socket(s):                          1
Stepping:                           1
BogoMIPS:                           4890.88
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 tsc_reliable nonstop_tsc cpuid extd_apicid aperfmperf pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 movbe popcnt aes xsave avx f16c rdrand hypervisor lahf_lm cmp_legacy cr8_legacy abm sse4a misalignsse 3dnowprefetch osvw topoext perfctr_core invpcid_single vmmcall fsgsbase bmi1 avx2 smep bmi2 erms invpcid rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 xsaves clzero xsaveerptr rdpru arat umip vaes vpclmulqdq rdpid fsrm
Hypervisor vendor:                  Microsoft
Virtualization type:                full
L1d cache:                          1.5 MiB (48 instances)
L1i cache:                          1.5 MiB (48 instances)
L2 cache:                           24 MiB (48 instances)
L3 cache:                           192 MiB (6 instances)
NUMA node(s):                       2
NUMA node0 CPU(s):                  0-23
NUMA node1 CPU(s):                  24-47
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 Retbleed:             Not affected
Vulnerability Spec rstack overflow: Mitigation; safe RET, no microcode
Vulnerability Spec store bypass:    Vulnerable
Vulnerability Spectre v1:           Mitigation; usercopy/swapgs barriers and __user pointer sanitization
Vulnerability Spectre v2:           Mitigation; Retpolines; STIBP disabled; 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.21.5
[conda] Could not collect
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: N/A
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
�[4mGPU0	GPU1	NIC0	CPU Affinity	NUMA Affinity	GPU NUMA ID�[0m
GPU0	 X 	NV12	NODE	0-23	0		N/A
GPU1	NV12	 X 	SYS	24-47	1		N/A
NIC0	NODE	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_an0

Model Input Dumps

No response

🐛 Describe the bug

I run the vLLM server with speculative decoding as follows:

NCCL_GRAPH_FILE="/home/azureuser/apps/ai-kyc_vu/vllm_server/gpu_graph.xml" python -m vllm.entrypoints.openai.api_server
--model "neuralmagic/Meta-Llama-3.1-70B-Instruct-FP8"
--served-model-name ""
--guided-decoding-backend "outlines"
--gpu-memory-utilization 0.9 
--port 7999
--worker_use_ray
--max-model-len 40000
--tensor-parallel-size 2
--speculative-model="[ngram]"
--num_speculative_tokens 5
--ngram_prompt_lookup_max=4
--use-v2-block-manager

I then prompt the LLM with guided json created from the following pydantic model:

class A(BaseModel):
    a: int

I incorporate the guided json into the following testing prompt:

{
    "model": "",
    "messages": [
      {
        "role": "system",
        "content": ""
      },
      {
        "role": "user",
        "content": "How are you?"
      }
    ],
    "guided_decoding_backend": "outlines",
    "guided_json": {"properties": {"a": {"title": "A", "type": "integer"}}, "required": ["a"], "title": "A", "type": "object"},
    "max_tokens": 200,
    "top_k": 1,
    "stream": false
}

The json guidance should ensure that the output is a valid json object. However, vLLM returns the following incomplete json object:

{"a": 1

When I disable ngram-speculative decoding, the same prompt works, and returns a complete json object:

{"a": 1}

This means that somehow, ngram-speculative decoding breaks json guidance.

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.
@roberthoenig roberthoenig added the bug Something isn't working label Oct 16, 2024
@nvu99
Copy link

nvu99 commented Oct 16, 2024

same issue here

@arunpatala
Copy link

hi I am facing a similar issue. Is there a place this is being tracked?

If anyone can guide me, I can try to fix this? Thanks

@Peng-YM
Copy link

Peng-YM commented Nov 25, 2024

same issue here

@oloflarsson
Copy link

Used this a couple of days ago with the latest docker:

python3 -m vllm.entrypoints.openai.api_server \
--max-model-len 8192 \
--model nm-testing/Llama-3.3-70B-Instruct-FP8-dynamic \
--speculative-model neuralmagic/Llama-3.2-3B-Instruct-FP8-dynamic \
--num-speculative-tokens 5

vLLM crashed and stopped completely upon sending a curl with response_format: json_object.

@oloflarsson
Copy link

@cadedaniel I'd like to put a $100 bounty on this ticket if that is alright?

I'll wire the money to an IBAN+BIC, provided by the author that fixed the bug, once speculative and guided works together, and I'm no longer able to reproduce the crash above on the latest vLLM docker image.

@honne23
Copy link

honne23 commented Jan 5, 2025

I would likewise add $100 to that bounty :)

@llsj14
Copy link
Contributor

llsj14 commented Jan 27, 2025

I’m not sure if the differences in results are due to floating-point operations, but when I used the --speculative-disable-mqa-scorer option, the results were consistent (identical across w/o spec decode, w/ spec decode using a different small model, and w/ spec decode with n-gram speculation).

I’m looking into the MQA scorer, but I haven’t found any incorrect operations so far.
@roberthoenig, could you also check if your results change when using the --speculative-disable-mqa-scorer option?

@roberthoenig
Copy link
Author

@llsj14 I can confirm that with vLLM 0.6.6 and --speculative-disable-mqa-scorer, ngrams + spec. decoding produces a valid response:

{\"a\": 1}

conversely, without --speculative-disable-mqa-scorer, I still get the invalid response

{\"a\": 

To understand this option correctly, is the MQA Scorer referring to tree-based attention scoring? If so, does disabling it have any performance effect on ngrams spec. decoding (it shouldn't, right, since ngrams doesn't create a tree of speculations, but rather just a single speculation)?

@llsj14
Copy link
Contributor

llsj14 commented Jan 27, 2025

@roberthoenig
Thank you for checking. The MQA scorer itself is not directly related to tree-based speculations like Medusa, Eagle, or DySpec. (However, I believe it can create good synergy with them.) The MQA scorer is an approach designed to speed up attention operations with speculated tokens, avoiding duplicated KV loads.

@LiuXiaoxuanPKU
Sorry for tagging you suddenly. I'm not sure whether this is due to a bug or simply differences arising from floating-point operations. However, in this case, the results differ depending on whether the MQA scorer is utilized or not. When you have time, could you check if there are any issues between the MQA scorer and n-gram speculations?

@roberthoenig
Copy link
Author

@llsj14 just a quick remark: floating-point differences alone can't explain the observed output, because guided decoding should give a hard guarantee on generating valid JSON output, yet {\"a\": is not valid JSON. Or am I misunderstanding something?

@llsj14
Copy link
Contributor

llsj14 commented Jan 27, 2025

I found that before guided decoding, the target model generated a different token while processing n+1 tokens (n from n-gram drafts and 1 from the target model) during the scoring process. In the verification operation, different batch sizes or matrices might be utilized, which could lead to different results. I initially suspected a bug, but I haven't found a specific reason so far. Let's investigate further.

  1. execute_model_req and proposals contain identical fields and values.

@nvtx_range("BatchExpansionTop1Scorer.score_proposals")
def score_proposals(
self,
execute_model_req: ExecuteModelRequest,
proposals: SpeculativeProposals,
) -> SpeculativeScores:
"""Score the proposed tokens via the scorer model.

def score_proposals(
self,
execute_model_req: ExecuteModelRequest,
proposals: SpeculativeProposals,
) -> SpeculativeScores:

  1. With the flash attention results(decode_output), they both show the exact same value.
    out=decode_output.unsqueeze(1),
    fa_version=self.fa_version,
    )
    return output
Image Image

@llsj14
Copy link
Contributor

llsj14 commented Jan 28, 2025

They produce different logits even though both batch expansion and the MQA scorer generate the same hidden states, because they use different forms of sampling metadata.

logits = self.model.compute_logits(hidden_or_intermediate_states,
model_input.sampling_metadata)

This seems to be a bug not related to n-gram speculations, but rather to the computation of logits with sampling metadata configured by the MQA scorer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working structured-output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants