vllm - ✅(Solved) Fix [Bug]: delta_text and delta_token_ids get out of sync when stop sequences are used. [4 pull requests, 1 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#36830Fetched 2026-04-08 00:34:23
View on GitHub
Comments
1
Participants
2
Timeline
15
Reactions
0
Assignees
Timeline (top)
cross-referenced ×4referenced ×4mentioned ×2subscribed ×2

Fix Action

Fix / Workaround

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

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): 16 On-line CPU(s) list: 0-15 Vendor ID: AuthenticAMD Model name: AMD Ryzen 7 7700X 8-Core Processor CPU family: 25 Model: 97 Thread(s) per core: 2 Core(s) per socket: 8 Socket(s): 1 Stepping: 2 Frequency boost: enabled CPU(s) scaling MHz: 66% CPU max MHz: 5575.8662 CPU min MHz: 403.0750 BogoMIPS: 9000.64 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 amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 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 cpuid_fault cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 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 user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d amd_lbr_pmc_freeze Virtualization: AMD-V L1d cache: 256 KiB (8 instances) L1i cache: 256 KiB (8 instances) L2 cache: 8 MiB (8 instances) L3 cache: 32 MiB (1 instance) NUMA node(s): 1 NUMA node0 CPU(s): 0-15 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: Not affected Vulnerability Retbleed: Not affected 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; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected Vulnerability Srbds: Not affected Vulnerability Tsa: Mitigation; Clear CPU buffers Vulnerability Tsx async abort: Not affected Vulnerability Vmscape: Mitigation; IBPB before exit to userspace

PR fix notes

PR #36827: Add simple granite4 tool parser

Description (problem / solution / changelog)

Purpose

Note: this is a simpler alternative to https://github.com/vllm-project/vllm/pull/35948 based on suggestions by @sfeng33

IBM's Granite 4 models use the Hermes tool calling convention and until now had been using the hermes parser. However, due to the popularity of the Hermes format many additions have been made to this parser to serve specific needs, such as the ability to work without specialized tool calling tokens. As a result, the parser's code has become mostly unreadable. We have found bugs that arise from the interaction with other features such as stop sequences and that are very hard to fix given the state of the code. Also given the complexity of the code, it is very hard for maintainers to trust that a PR won't break other things. There is also a Granite 4 specific behavior which we need handled in the tool parser which is that the models have a tendency to generate the arguments as an escaped string instead of JSON text.

The granite4 parser in this PR has been re-written from the ground up to avoid the brittle partial json parsing that we see in other tool call parsers. By only streaming full tool call streaming, no partial json parsing is required.

Main design decisions:

  • Remove streaming of tool names ahead of arguments
  • Remove streaming of partial arguments: this complicates things and arguably doesn't benefit the end user at all
  • Rely only on text, not on tokens

Test Plan

Since the parser is compatible with Hermes tool calling, I'm reusing the Hermes tests except for one that allows incomplete input. I'm also adding tests for the lexer and parser as well as testing for known bugs.

Test Result

All the added or modified tests are passing locally.

Changed files

  • docs/features/tool_calling.md (modified, +1/-1)
  • tests/entrypoints/openai/tool_parsers/test_granite4_tool_parser.py (added, +360/-0)
  • tests/entrypoints/openai/tool_parsers/test_hermes_tool_parser.py (modified, +233/-167)
  • vllm/tool_parsers/__init__.py (modified, +4/-0)
  • vllm/tool_parsers/granite4_tool_parser.py (added, +252/-0)

Code Example

==============================
        System Info
==============================
OS                           : Fedora Linux 42 (Workstation Edition) (x86_64)
GCC version                  : (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7)
Clang version                : 20.1.8 (Fedora 20.1.8-4.fc42)
CMake version                : version 3.31.6
Libc version                 : glibc-2.41

==============================
       PyTorch Info
==============================
PyTorch version              : 2.9.1+cu128
Is debug build               : False
CUDA used to build PyTorch   : 12.8
ROCM used to build PyTorch   : N/A

==============================
      Python Environment
==============================
Python version               : 3.12.7 (main, Nov 15 2024, 10:20:47) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] (64-bit runtime)
Python platform              : Linux-6.18.8-100.fc42.x86_64-x86_64-with-glibc2.41

==============================
       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 4060 Ti
Nvidia driver version        : 590.48.01
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:                           48 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 7700X 8-Core Processor
CPU family:                              25
Model:                                   97
Thread(s) per core:                      2
Core(s) per socket:                      8
Socket(s):                               1
Stepping:                                2
Frequency boost:                         enabled
CPU(s) scaling MHz:                      66%
CPU max MHz:                             5575.8662
CPU min MHz:                             403.0750
BogoMIPS:                                9000.64
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 amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 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 cpuid_fault cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 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 user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d amd_lbr_pmc_freeze
Virtualization:                          AMD-V
L1d cache:                               256 KiB (8 instances)
L1i cache:                               256 KiB (8 instances)
L2 cache:                                8 MiB (8 instances)
L3 cache:                                32 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
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:    Not affected
Vulnerability Retbleed:                  Not affected
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; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Mitigation; Clear CPU buffers
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

==============================
Versions of relevant libraries
==============================
[pip3] flashinfer-python==0.6.2
[pip3] numpy==2.2.6
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cutlass-dsl==4.3.5
[pip3] nvidia-ml-py==13.590.48
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.3.20
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] pyzmq==27.1.0
[pip3] torch==2.9.1
[pip3] torchaudio==2.9.1
[pip3] torchvision==0.24.1
[pip3] transformers==5.2.0.dev0
[pip3] triton==3.6.0
[conda] Could not collect

==============================
         vLLM Info
==============================
ROCM Version                 : 6.3.42133-0
vLLM Version                 : 0.15.2rc1.dev23+g81a90e527.d20260205 (git sha: 81a90e527, date: 20260205)
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: 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

==============================
     Environment Variables
==============================
PYTORCH_NVML_BASED_CUDA_CHECK=1
TORCHINDUCTOR_COMPILE_THREADS=1

---

def extract_tool_calls_streaming(
        self,
        previous_text: str,
        current_text: str,
        delta_text: str,
        previous_token_ids: Sequence[int],
        current_token_ids: Sequence[int],
        delta_token_ids: Sequence[int],
        request: ChatCompletionRequest,
    ) -> DeltaMessage | None:

---

(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[100270]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[198]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[5018]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[609]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[794]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[330]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[456]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[62]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[582]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[2727]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[62]
(APIServer pid=250128) delta_text='<t'
(APIServer pid=250128) delta_token_ids=[4030]
(APIServer pid=250128) delta_text='ool_c'
(APIServer pid=250128) delta_token_ids=[1292]
(APIServer pid=250128) delta_text='all>'
(APIServer pid=250128) delta_token_ids=[5595]
(APIServer pid=250128) delta_text='\n{"name": "g'
...
(APIServer pid=250128) delta_text='467722Z", "a'
(APIServer pid=250128) delta_token_ids=[100271]
(APIServer pid=250128) delta_text='cme_region": "A9345"}}\n</tool_call>'
(APIServer pid=250128) delta_token_ids=[100257]

---

(APIServer pid=251071) delta_text='<tool_call>'
(APIServer pid=251071) delta_token_ids=[100270]
(APIServer pid=251071) delta_text='\n'
(APIServer pid=251071) delta_token_ids=[198]
(APIServer pid=251071) delta_text='{"'
(APIServer pid=251071) delta_token_ids=[5018]
(APIServer pid=251071) delta_text='name'
(APIServer pid=251071) delta_token_ids=[609]
(APIServer pid=251071) delta_text='":'
(APIServer pid=251071) delta_token_ids=[794]
(APIServer pid=251071) delta_text=' "'
(APIServer pid=251071) delta_token_ids=[330]
(APIServer pid=251071) delta_text='get'
(APIServer pid=251071) delta_token_ids=[456]
(APIServer pid=251071) delta_text='_'
(APIServer pid=251071) delta_token_ids=[62]
(APIServer pid=251071) delta_text='ac'
(APIServer pid=251071) delta_token_ids=[582]
(APIServer pid=251071) delta_text='me'
(APIServer pid=251071) delta_token_ids=[2727]
...
(APIServer pid=251071) delta_text='"}}\n'
(APIServer pid=251071) delta_token_ids=[96742]
(APIServer pid=251071) delta_text='</tool_call>'
(APIServer pid=251071) delta_token_ids=[100271]
(APIServer pid=251071) delta_text=''
(APIServer pid=251071) delta_token_ids=[100257]
RAW_BUFFERClick to expand / collapse

Your current environment

==============================
        System Info
==============================
OS                           : Fedora Linux 42 (Workstation Edition) (x86_64)
GCC version                  : (GCC) 15.2.1 20260123 (Red Hat 15.2.1-7)
Clang version                : 20.1.8 (Fedora 20.1.8-4.fc42)
CMake version                : version 3.31.6
Libc version                 : glibc-2.41

==============================
       PyTorch Info
==============================
PyTorch version              : 2.9.1+cu128
Is debug build               : False
CUDA used to build PyTorch   : 12.8
ROCM used to build PyTorch   : N/A

==============================
      Python Environment
==============================
Python version               : 3.12.7 (main, Nov 15 2024, 10:20:47) [GCC 13.3.1 20240522 (Red Hat 13.3.1-1)] (64-bit runtime)
Python platform              : Linux-6.18.8-100.fc42.x86_64-x86_64-with-glibc2.41

==============================
       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 4060 Ti
Nvidia driver version        : 590.48.01
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:                           48 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 7700X 8-Core Processor
CPU family:                              25
Model:                                   97
Thread(s) per core:                      2
Core(s) per socket:                      8
Socket(s):                               1
Stepping:                                2
Frequency boost:                         enabled
CPU(s) scaling MHz:                      66%
CPU max MHz:                             5575.8662
CPU min MHz:                             403.0750
BogoMIPS:                                9000.64
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 amd_lbr_v2 nopl xtopology nonstop_tsc cpuid extd_apicid aperfmperf rapl pni pclmulqdq monitor ssse3 fma cx16 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 cpuid_fault cpb cat_l3 cdp_l3 hw_pstate ssbd mba perfmon_v2 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 user_shstk avx512_bf16 clzero irperf xsaveerptr rdpru wbnoinvd cppc arat npt lbrv svm_lock nrip_save tsc_scale vmcb_clean flushbyasid decodeassists pausefilter pfthreshold avic vgif x2avic v_spec_ctrl vnmi avx512vbmi umip pku ospke avx512_vbmi2 gfni vaes vpclmulqdq avx512_vnni avx512_bitalg avx512_vpopcntdq rdpid overflow_recov succor smca fsrm flush_l1d amd_lbr_pmc_freeze
Virtualization:                          AMD-V
L1d cache:                               256 KiB (8 instances)
L1i cache:                               256 KiB (8 instances)
L2 cache:                                8 MiB (8 instances)
L3 cache:                                32 MiB (1 instance)
NUMA node(s):                            1
NUMA node0 CPU(s):                       0-15
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:    Not affected
Vulnerability Retbleed:                  Not affected
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; Enhanced / Automatic IBRS; IBPB conditional; STIBP always-on; PBRSB-eIBRS Not affected; BHI Not affected
Vulnerability Srbds:                     Not affected
Vulnerability Tsa:                       Mitigation; Clear CPU buffers
Vulnerability Tsx async abort:           Not affected
Vulnerability Vmscape:                   Mitigation; IBPB before exit to userspace

==============================
Versions of relevant libraries
==============================
[pip3] flashinfer-python==0.6.2
[pip3] numpy==2.2.6
[pip3] nvidia-cublas-cu12==12.8.4.1
[pip3] nvidia-cuda-cupti-cu12==12.8.90
[pip3] nvidia-cuda-nvrtc-cu12==12.8.93
[pip3] nvidia-cuda-runtime-cu12==12.8.90
[pip3] nvidia-cudnn-cu12==9.10.2.21
[pip3] nvidia-cudnn-frontend==1.18.0
[pip3] nvidia-cufft-cu12==11.3.3.83
[pip3] nvidia-cufile-cu12==1.13.1.3
[pip3] nvidia-curand-cu12==10.3.9.90
[pip3] nvidia-cusolver-cu12==11.7.3.90
[pip3] nvidia-cusparse-cu12==12.5.8.93
[pip3] nvidia-cusparselt-cu12==0.7.1
[pip3] nvidia-cutlass-dsl==4.3.5
[pip3] nvidia-ml-py==13.590.48
[pip3] nvidia-nccl-cu12==2.27.5
[pip3] nvidia-nvjitlink-cu12==12.8.93
[pip3] nvidia-nvshmem-cu12==3.3.20
[pip3] nvidia-nvtx-cu12==12.8.90
[pip3] pyzmq==27.1.0
[pip3] torch==2.9.1
[pip3] torchaudio==2.9.1
[pip3] torchvision==0.24.1
[pip3] transformers==5.2.0.dev0
[pip3] triton==3.6.0
[conda] Could not collect

==============================
         vLLM Info
==============================
ROCM Version                 : 6.3.42133-0
vLLM Version                 : 0.15.2rc1.dev23+g81a90e527.d20260205 (git sha: 81a90e527, date: 20260205)
vLLM Build Flags:
  CUDA Archs: Not Set; ROCm: 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

==============================
     Environment Variables
==============================
PYTORCH_NVML_BASED_CUDA_CHECK=1
TORCHINDUCTOR_COMPILE_THREADS=1

🐛 Describe the bug

For streaming, the tool call parser functiont that is called is:

    def extract_tool_calls_streaming(
        self,
        previous_text: str,
        current_text: str,
        delta_text: str,
        previous_token_ids: Sequence[int],
        current_token_ids: Sequence[int],
        delta_token_ids: Sequence[int],
        request: ChatCompletionRequest,
    ) -> DeltaMessage | None:

Here delta_token_ids is supposed to be the tokenized version of delta_text. And usually it is, but when stop sequences are added to the request, the text seems to be hold back somewhere.

As an example, to reproduce, in PR https://github.com/vllm-project/vllm/pull/36827 if you run test_granite4_tool_parser.py::test_stop_sequence_interference and print the deltas that arrive at the tool parser, you'll see:

(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[100270]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[198]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[5018]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[609]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[794]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[330]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[456]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[62]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[582]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[2727]
(APIServer pid=250128) delta_text=''
(APIServer pid=250128) delta_token_ids=[62]
(APIServer pid=250128) delta_text='<t'
(APIServer pid=250128) delta_token_ids=[4030]
(APIServer pid=250128) delta_text='ool_c'
(APIServer pid=250128) delta_token_ids=[1292]
(APIServer pid=250128) delta_text='all>'
(APIServer pid=250128) delta_token_ids=[5595]
(APIServer pid=250128) delta_text='\n{"name": "g'
...
(APIServer pid=250128) delta_text='467722Z", "a'
(APIServer pid=250128) delta_token_ids=[100271]
(APIServer pid=250128) delta_text='cme_region": "A9345"}}\n</tool_call>'
(APIServer pid=250128) delta_token_ids=[100257]

But if you comment out the stop argument in the request, you see:

(APIServer pid=251071) delta_text='<tool_call>'
(APIServer pid=251071) delta_token_ids=[100270]
(APIServer pid=251071) delta_text='\n'
(APIServer pid=251071) delta_token_ids=[198]
(APIServer pid=251071) delta_text='{"'
(APIServer pid=251071) delta_token_ids=[5018]
(APIServer pid=251071) delta_text='name'
(APIServer pid=251071) delta_token_ids=[609]
(APIServer pid=251071) delta_text='":'
(APIServer pid=251071) delta_token_ids=[794]
(APIServer pid=251071) delta_text=' "'
(APIServer pid=251071) delta_token_ids=[330]
(APIServer pid=251071) delta_text='get'
(APIServer pid=251071) delta_token_ids=[456]
(APIServer pid=251071) delta_text='_'
(APIServer pid=251071) delta_token_ids=[62]
(APIServer pid=251071) delta_text='ac'
(APIServer pid=251071) delta_token_ids=[582]
(APIServer pid=251071) delta_text='me'
(APIServer pid=251071) delta_token_ids=[2727]
...
(APIServer pid=251071) delta_text='"}}\n'
(APIServer pid=251071) delta_token_ids=[96742]
(APIServer pid=251071) delta_text='</tool_call>'
(APIServer pid=251071) delta_token_ids=[100271]
(APIServer pid=251071) delta_text=''
(APIServer pid=251071) delta_token_ids=[100257]

In other words, in the beginning now text reaches the parser, and at the end all remaining text arrives concatenated. Meanwhile, in the middle the two stream are completely out of sync.

cc: @chaunceyjiang

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

Fix Plan

To address the issue of delta_text being held back when stop sequences are added to the request, we need to modify the extract_tool_calls_streaming function to properly handle the stop sequences.

Here are the steps to fix the issue:

  • Check if the stop argument is present in the request and handle it accordingly.
  • Modify the function to process the delta_text in chunks, rather than waiting for the entire text to be received.
  • Ensure that the delta_token_ids are correctly generated for each chunk of delta_text.

Example code:

def extract_tool_calls_streaming(
    self,
    previous_text: str,
    current_text: str,
    delta_text: str,
    previous_token_ids: Sequence[int],
    current_token_ids: Sequence[int],
    delta_token_ids: Sequence[int],
    request: ChatCompletionRequest,
) -> DeltaMessage | None:
    if request.stop:
        # Handle stop sequence
        # Process delta_text in chunks
        chunk_size = 100
        for i in range(0, len(delta_text), chunk_size):
            chunk = delta_text[i:i+chunk_size]
            # Generate delta_token_ids for the chunk
            chunk_token_ids = self.tokenize(chunk)
            # Process the chunk
            self.process_chunk(chunk, chunk_token_ids)
    else:
        # No stop sequence, process delta_text as before
        delta_token_ids = self.tokenize(delta_text)
        # Process delta_text
        self.process_delta_text(delta_text, delta_token_ids)

Note: The tokenize and process_chunk functions are assumed to be implemented elsewhere in the codebase.

Verification

To verify that the fix worked, run the test_granite4_tool_parser.py::test_stop_sequence_interference test case and check that the delta_text and delta_token_ids are correctly processed when the stop argument is present in the request.

Extra Tips

  • Ensure that the tokenize function is correctly implemented to handle the chunking of delta_text.
  • Consider adding additional logging or debugging statements to help diagnose any further issues with the extract_tool_calls_streaming function.

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…

Still need to ship something?

×6

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

Back to top recommendations

TRENDING

vllm - ✅(Solved) Fix [Bug]: delta_text and delta_token_ids get out of sync when stop sequences are used. [4 pull requests, 1 comments, 2 participants]