[Bugfix] Migrate to REGEX Library to prevent catastrophic backtracking (#18454)

Signed-off-by: Crucifixion-Fxl <xmufxl@gmail.com>
Co-authored-by: Crucifixion-Fxl <xmufxl@gmail.com>
This commit is contained in:
Feng XiaoLong
2025-05-23 16:16:26 -07:00
committed by GitHub
co-authored by Crucifixion-Fxl
parent f2036734fb
commit 4fc1bf813a
52 changed files with 62 additions and 58 deletions
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
import weakref
from enum import Enum
import jsonschema
import pytest
import regex as re
from pydantic import BaseModel
from vllm.distributed import cleanup_dist_env_and_memory
+1 -1
View File
@@ -2,13 +2,13 @@
# imports for guided decoding tests
import json
import re
from typing import Optional
import jsonschema
import openai # use the official client for correctness check
import pytest
import pytest_asyncio
import regex as re
import requests
import torch
from openai import BadRequestError, OpenAI
+1 -2
View File
@@ -1,8 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
# imports for guided decoding tests
import json
import re
import shutil
from tempfile import TemporaryDirectory
from typing import Optional
@@ -11,6 +9,7 @@ import jsonschema
import openai # use the official client for correctness check
import pytest
import pytest_asyncio
import regex as re
# downloading lora to test lora requests
from huggingface_hub import snapshot_download
from openai import BadRequestError
@@ -1,10 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
# imports for guided decoding tests
import re
import openai
import pytest
import regex as re
from ...utils import RemoteOpenAIServer
@@ -32,7 +31,7 @@ async def test_out_of_vocab_token_ids():
client = remote_server.get_async_client()
with pytest.raises(openai.BadRequestError,
match=re.compile('.*out of vocabulary.*')):
match=re.compile('.*out of vocabulary.*').pattern):
await client.completions.create(model=model_name,
prompt=[999999],
max_tokens=5,
@@ -46,9 +45,10 @@ async def test_reject_multistep_with_guided_decoding():
with RemoteOpenAIServer(model_name, server_args) as remote_server:
client = remote_server.get_async_client()
with pytest.raises(openai.BadRequestError,
match=re.compile(
'.*Guided decoding .* multi-step decoding.*')):
with pytest.raises(
openai.BadRequestError,
match=re.compile(
'.*Guided decoding .* multi-step decoding.*').pattern):
await client.completions.create(
model=model_name,
prompt="Hello",
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
import os
import re
from collections.abc import Sequence
from typing import Optional
import librosa
import pytest
import regex as re
from huggingface_hub import snapshot_download
from transformers import AutoTokenizer
@@ -3,11 +3,11 @@
for manipulating the input / output of HF & vLLM test runners, which are
typically specific to a small subset of models.
"""
import re
import types
from pathlib import PosixPath
from typing import Optional, Union
import regex as re
import torch
from PIL.Image import Image
from transformers import (AutoConfig, AutoTokenizer, BatchFeature,
+2 -2
View File
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from copy import deepcopy
from unittest.mock import MagicMock
import pytest
import regex as re
from pydantic import TypeAdapter
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
@@ -333,4 +333,4 @@ def test_streaming_output_valid(output, empty_params, delta_len):
combined_messages += message.tool_calls[0].function.arguments
combined_messages += "}]"
assert json.loads(combined_messages) == output
assert json.dumps(json.loads(combined_messages)) == output_json
assert json.dumps(json.loads(combined_messages)) == output_json
@@ -4,12 +4,12 @@
from __future__ import annotations
import json
import re
from enum import Enum
from typing import TYPE_CHECKING, Any
import jsonschema
import pytest
import regex as re
from pydantic import BaseModel
from tests.reasoning.utils import run_reasoning_extraction
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
import re
from typing import Optional
import openai # use the official client for correctness check
import pytest
import pytest_asyncio
import regex as re
from openai import BadRequestError
from tests.utils import RemoteOpenAIServer
+2 -1
View File
@@ -1,9 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import re
from enum import Enum
from typing import Optional
import regex as re
from vllm import CompletionOutput