Skip to content

[Bug]: DeepSeek R1 with outlines structured engine stops generation after </think> #14113

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

Closed
1 task done
gaocegege opened this issue Mar 3, 2025 · 13 comments · Fixed by #14114
Closed
1 task done

[Bug]: DeepSeek R1 with outlines structured engine stops generation after </think> #14113

gaocegege opened this issue Mar 3, 2025 · 13 comments · Fixed by #14114
Labels
bug Something isn't working

Comments

@gaocegege
Copy link
Contributor

gaocegege commented Mar 3, 2025

Your current environment

The output of `python collect_env.py`
PyTorch version: 2.5.1+cu124
Is debug build: False
CUDA used to build PyTorch: 12.4
ROCM used to build PyTorch: N/A

OS: Ubuntu 22.04.5 LTS (x86_64)
GCC version: (Ubuntu 12.3.0-1ubuntu1~22.04) 12.3.0
Clang version: 10.0.0-4ubuntu1 
CMake version: version 3.22.1
Libc version: glibc-2.35

Python version: 3.12.8 | packaged by Anaconda, Inc. | (main, Dec 11 2024, 16:31:09) [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-6.8.0-52-generic-x86_64-with-glibc2.35
Is CUDA available: True
CUDA runtime version: 11.4.100
CUDA_MODULE_LOADING set to: LAZY
GPU models and configuration: GPU 0: NVIDIA GeForce RTX 3070
Nvidia driver version: 550.120
cuDNN version: Could not collect
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:                         x86_64
CPU op-mode(s):                       32-bit, 64-bit
Address sizes:                        43 bits physical, 48 bits virtual
Byte Order:                           Little Endian
CPU(s):                               16
On-line CPU(s) list:                  0-15
Vendor ID:                            AuthenticAMD
Model name:                           AMD Ryzen 7 3800XT 8-Core Processor
CPU family:                           23
Model:                                113
Thread(s) per core:                   2
Core(s) per socket:                   8
Socket(s):                            1
Stepping:                             0
Frequency boost:                      enabled
CPU max MHz:                          4722.6558
CPU min MHz:                          2200.0000
BogoMIPS:                             7800.08
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 sse4_1 sse4_2 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 hw_pstate ssbd mba ibpb stibp vmmcall fsgsbase bmi1 avx2 smep bmi2 cqm rdt_a rdseed adx smap clflushopt clwb sha_ni xsaveopt xsavec xgetbv1 cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local clzero irperf xsaveerptr rdpru wbnoinvd arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic v_vmsave_vmload vgif v_spec_ctrl umip rdpid overflow_recov succor smca sev sev_es
Virtualization:                       AMD-V
L1d cache:                            256 KiB (8 instances)
L1i cache:                            256 KiB (8 instances)
L2 cache:                             4 MiB (8 instances)
L3 cache:                             32 MiB (2 instances)
NUMA node(s):                         1
NUMA node0 CPU(s):                    0-15
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:               Mitigation; untrained return thunk; SMT enabled with STIBP protection
Vulnerability Spec rstack overflow:   Mitigation; Safe RET
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; Retpolines; 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] nvidia-cublas-cu12==12.4.5.8
[pip3] nvidia-cuda-cupti-cu12==12.4.127
[pip3] nvidia-cuda-nvrtc-cu12==12.4.127
[pip3] nvidia-cuda-runtime-cu12==12.4.127
[pip3] nvidia-cudnn-cu12==9.1.0.70
[pip3] nvidia-cufft-cu12==11.2.1.3
[pip3] nvidia-curand-cu12==10.3.5.147
[pip3] nvidia-cusolver-cu12==11.6.1.9
[pip3] nvidia-cusparse-cu12==12.3.1.170
[pip3] nvidia-ml-py==12.570.86
[pip3] nvidia-nccl-cu12==2.21.5
[pip3] nvidia-nvjitlink-cu12==12.4.127
[pip3] nvidia-nvtx-cu12==12.4.127
[pip3] pyzmq==26.2.0
[pip3] torch==2.5.1
[pip3] torchaudio==2.5.1
[pip3] torchvision==0.20.1
[pip3] transformers==4.48.3
[pip3] triton==3.1.0
[pip3] zmq==0.0.0
[conda] numpy                     1.26.4                   pypi_0    pypi
[conda] nvidia-cublas-cu12        12.4.5.8                 pypi_0    pypi
[conda] nvidia-cuda-cupti-cu12    12.4.127                 pypi_0    pypi
[conda] nvidia-cuda-nvrtc-cu12    12.4.127                 pypi_0    pypi
[conda] nvidia-cuda-runtime-cu12  12.4.127                 pypi_0    pypi
[conda] nvidia-cudnn-cu12         9.1.0.70                 pypi_0    pypi
[conda] nvidia-cufft-cu12         11.2.1.3                 pypi_0    pypi
[conda] nvidia-curand-cu12        10.3.5.147               pypi_0    pypi
[conda] nvidia-cusolver-cu12      11.6.1.9                 pypi_0    pypi
[conda] nvidia-cusparse-cu12      12.3.1.170               pypi_0    pypi
[conda] nvidia-ml-py              12.570.86                pypi_0    pypi
[conda] nvidia-nccl-cu12          2.21.5                   pypi_0    pypi
[conda] nvidia-nvjitlink-cu12     12.4.127                 pypi_0    pypi
[conda] nvidia-nvtx-cu12          12.4.127                 pypi_0    pypi
[conda] pyzmq                     26.2.0                   pypi_0    pypi
[conda] torch                     2.5.1                    pypi_0    pypi
[conda] torchaudio                2.5.1                    pypi_0    pypi
[conda] torchvision               0.20.1                   pypi_0    pypi
[conda] transformers              4.48.3                   pypi_0    pypi
[conda] triton                    3.1.0                    pypi_0    pypi
[conda] zmq                       0.0.0                    pypi_0    pypi
ROCM Version: Could not collect
Neuron SDK Version: N/A
vLLM Version: 0.7.4.dev178+g09e56f92
vLLM Build Flags:
CUDA Archs: Not Set; ROCm: Disabled; Neuron: Disabled
GPU Topology:
GPU0	CPU Affinity	NUMA Affinity	GPU NUMA ID
GPU0	 X 	0-15	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

VLLM_LOGGING_LEVEL=DEBUG
NCCL_CUMEM_ENABLE=0
TORCHINDUCTOR_COMPILE_THREADS=1
CUDA_MODULE_LOADING=LAZY

🐛 Describe the bug

vllm serve deepseek-ai/DeepSeek-R1-Distill-Qwen-1.5B --enable-reasoning --reasoning-parser deepseek_r1 --enforce-eager

Runs with this example. It falls back to outlines engine because it has Enum in the JSON schema (Our xgrammar does not support this), and will generate token ids until . Then it stops. Did not encounter it with xgrammar.

# Guided decoding by JSON using Pydantic schema
class CarType(str, Enum):
    sedan = "sedan"
    suv = "SUV"
    truck = "Truck"
    coupe = "Coupe"


class CarDescription(BaseModel):
    brand: str
    model: str
    car_type: CarType


json_schema = CarDescription.model_json_schema()

prompt = ("Generate a JSON with the brand, model and car_type of"
          "the most iconic car from the 90's, think in 100 tokens")
completion = client.chat.completions.create(
    model=model,
    messages=[{
        "role": "user",
        "content": prompt,
    }],
    extra_body={"guided_json": json_schema},
)
print("reasoning_content: ", completion.choices[0].message.reasoning_content)
print("content: ", completion.choices[0].message.content)

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.
@gaocegege gaocegege added the bug Something isn't working label Mar 3, 2025
@gaocegege gaocegege changed the title [Bug]: DeepSeek R1 with outliner structured engine stops generation after </think> [Bug]: DeepSeek R1 with outlines structured engine stops generation after </think> Mar 3, 2025
@gaocegege
Copy link
Contributor Author

You may also be interested in this issue. /cc @jacobthebanana @liuyanyi

Maybe outlines added an eos token for it. Haven't dived deep into it.

@shen-shanshan
Copy link
Contributor

shen-shanshan commented Mar 4, 2025

I have tested the same example on my device, and have got a None content. It’s unclear whether this problem stems from my npu device or the implementation itself.

The logs are shown below:

reasoning_content:  Okay, so I just got this query where演奏 wantsiliate a JSON with the brand  It, model, and car_type of the most iconic car fromconomy, 90s. They even asked me to limit it to 100 tokens. Hmm, okay, let me break it down.

First, I need to figure out which iconic car was iconic in the '90s. My mind jumps to time-traveling when I'm imagining cars from the future, but I need to think back to the 90s. The亲人iv is definitely iconic, especially for its sleek design and VR simulation features. Wow, that's a mouthful. But maybe I don't need to explain it extensively. Just the key details about the brand, model, and car_type should suffice.

Wait, the query says "cryptocurrency? Or perhaps it's a play on words for a crypto car? But the user mentioned "iconic car from the 90s," so I think it's safe to go with国产 vehicles. So, Exchange Collaboration Chains are from 1995, so nope, not crypto anymore. So the original meaning was correct.

Breaking it down: Elegant &这项wise brings phones & versatile cars aroundModifiedDate 1000. So, model could be Elegant Exchange Collaboration Chains. Brand would be Elegant, car_type would be Car.

Putting it together: {"brand": "Elegant", "model": "Exchange Collaboration Chains", "car_type": "Car"}. Let me count the tokens. Brand:5, model:6, car_type:4. Wait, that's 15 tokens. Hmm, maybe I should try again.

Wait a minute, maybe the model name can be expanded. Exchange Collaboration Chains sounds like a brand since Contribution Chains were created隐蔽 Way. But that's still part of et pricing. Alternatively, the model could be DesulGeneral Exchange Collaboration Chains. That might help. Or perhaps Exchange Collaboration Chains is a specific model.

Wait, but the user wants to limit to 100 tokens. Let me make sure each field is exactly one to two words or phrases. So, "brand" is 2 words, "model" is 5, "car_type" is 2. Total of 9 words, which is way below 100. But maybe the user has a more literal definition in mind.

Alternatively, thinking creatively, maybe "most iconic car" refers to something else. But, I don't think there's another car from the 90s as iconic as Exchange Collaboration Chains. Payment chains from Google were certainly in the 90s, but Exchange Collaboration Chains sounds like it's more Russian, perhaps.

Another thought: maybe Exchange Chains were actually phones from the 90s, but that seems less likely. So, I stick with Elegant Exchange Collaboration Chains. Got it.

content None

@gaocegege
Copy link
Contributor Author

gaocegege commented Mar 5, 2025

I have tested the same example on my device, and have got a None content. It’s unclear whether this problem stems from my npu device or the implementation itself.

The logs are shown below:

reasoning_content: Okay, so I just got this query where演奏 wantsiliate a JSON with the brand It, model, and car_type of the most iconic car fromconomy, 90s. They even asked me to limit it to 100 tokens. Hmm, okay, let me break it down.

First, I need to figure out which iconic car was iconic in the '90s. My mind jumps to time-traveling when I'm imagining cars from the future, but I need to think back to the 90s. The亲人iv is definitely iconic, especially for its sleek design and VR simulation features. Wow, that's a mouthful. But maybe I don't need to explain it extensively. Just the key details about the brand, model, and car_type should suffice.

Wait, the query says "cryptocurrency? Or perhaps it's a play on words for a crypto car? But the user mentioned "iconic car from the 90s," so I think it's safe to go with国产 vehicles. So, Exchange Collaboration Chains are from 1995, so nope, not crypto anymore. So the original meaning was correct.

Breaking it down: Elegant &这项wise brings phones & versatile cars aroundModifiedDate 1000. So, model could be Elegant Exchange Collaboration Chains. Brand would be Elegant, car_type would be Car.

Putting it together: {"brand": "Elegant", "model": "Exchange Collaboration Chains", "car_type": "Car"}. Let me count the tokens. Brand:5, model:6, car_type:4. Wait, that's 15 tokens. Hmm, maybe I should try again.

Wait a minute, maybe the model name can be expanded. Exchange Collaboration Chains sounds like a brand since Contribution Chains were created隐蔽 Way. But that's still part of et pricing. Alternatively, the model could be DesulGeneral Exchange Collaboration Chains. That might help. Or perhaps Exchange Collaboration Chains is a specific model.

Wait, but the user wants to limit to 100 tokens. Let me make sure each field is exactly one to two words or phrases. So, "brand" is 2 words, "model" is 5, "car_type" is 2. Total of 9 words, which is way below 100. But maybe the user has a more literal definition in mind.

Alternatively, thinking creatively, maybe "most iconic car" refers to something else. But, I don't think there's another car from the 90s as iconic as Exchange Collaboration Chains. Payment chains from Google were certainly in the 90s, but Exchange Collaboration Chains sounds like it's more Russian, perhaps.

Another thought: maybe Exchange Chains were actually phones from the 90s, but that seems less likely. So, I stick with Elegant Exchange Collaboration Chains. Got it.

content None

Yes, I’m able to reproduce the issue. In this example, the outlines engine is being used, and the token generation stops at </think>. I’m not entirely sure why this happens. However, if I comment out extra_body={"guided_json": json_schema}, the full output is generated as expected.

I think it is caused by our implementation. I can get the result successfully several weeks ago, with my first implementation in the PR #12955.

I had a fix to disable reasoning outputs with outlines request in #14114, and will try to figure out why outlines is not supported.

@gaocegege
Copy link
Contributor Author

It’s unclear whether this problem stems from my npu device or the implementation itself.

It is not from your side, or NPU. I can reproduce it with GPU.

@gaocegege
Copy link
Contributor Author

gaocegege commented Mar 5, 2025

@shen-shanshan, you could check out this PR and test the provided example to verify whether it works on the NPU. #14114

@shen-shanshan
Copy link
Contributor

@shen-shanshan, you could check out this PR and test the provided example to verify whether it works on the NPU. #14114

I have tested this PR on my device and it worked well with xgrammar backend~

@gaocegege
Copy link
Contributor Author

OK, thanks for your test, I will work on the fix for outlines.

@gaocegege
Copy link
Contributor Author

@shen-shanshan I fixed the outlines engine and added more examples in the PR #14114

You could test your NPU with it if you like.

@github-project-automation github-project-automation bot moved this from Backlog to Done in DeepSeek V3/R1 Mar 6, 2025
@Freder-chen
Copy link

Hi @gaocegege,
I found r1's guided_json is not available in vllm==0.8.2. Can you help me check the configuration? Here is my code:

# start by `vllm serve ${qwq_path} --enable-reasoning --reasoning-parser deepseek_r1`

class CarDescription(BaseModel):
    brand: str
    model: str

completion = client.chat.completions.create(
    model=model_name,
    messages=[
        {"role": "system", "content": "You are a helpful assistant designed to output JSON."},
        {"role": "user", "content": prompt},
    ],
    extra_body={
        "guided_json": CarDescription.model_json_schema(),
    }
)
print("reasoning_content: ", completion.choices[0].message.reasoning_content)
print("content: ", completion.choices[0].message.content)

# output: 
# reasoning_content: json response
# content: None

@gaocegege
Copy link
Contributor Author

What's the output? I tried this, and it works.

# Guided decoding by JSON using Pydantic schema
class CarType(str, Enum):
    sedan = "sedan"
    suv = "SUV"
    truck = "Truck"
    coupe = "Coupe"


class CarDescription(BaseModel):
    brand: str
    model: str
    car_type: CarType


json_schema = CarDescription.model_json_schema()

prompt = ("Generate a JSON with the brand, model and car_type of"
          "the most iconic car from the 90's")
completion = client.chat.completions.create(
    model=model,
    messages=[{
        "role": "user",
        "content": prompt,
    }],
    extra_body={"guided_json": json_schema},
)
print("reasoning_content: ", completion.choices[0].message.reasoning_content)
print("content: ", completion.choices[0].message.content)

@Freder-chen
Copy link

When I implement your code, I encounter the following error:

openai.BadRequestError: Error code: 400 - {'object': 'error', 'message': 'The provided JSON schema contains features not supported by xgrammar.', 'type': 'BadRequestError', 'param': None, 'code': 400}

And, when I exclude car_type, the result I receive is:

reasoning_content:  {
  "brand": "Ford",
  "model": "Mustang Shelby GT500 (Cobra) Snake Logo Edition"
  
}
content:  None

@gaocegege
Copy link
Contributor Author

gaocegege commented Mar 27, 2025

VLLM_USE_V1=0 vllm serve Please use v0 engine. Does it work?

@Freder-chen
Copy link

Thank you. Setting VLLM_USE_V1=0 resolved my issue.

VLLM_USE_V1=0 vllm serve Please use v0 engine. Does it work?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Status: Done
3 participants