[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 -1
View File
@@ -815,4 +815,4 @@ def main():
if __name__ == '__main__':
main()
main()
+1 -1
View File
@@ -6,7 +6,6 @@ import enum
import hashlib
import inspect
import json
import re
import textwrap
import uuid
import warnings
@@ -20,6 +19,7 @@ from pathlib import Path
from typing import (TYPE_CHECKING, Any, Callable, ClassVar, Literal, Optional,
Protocol, TypeVar, Union, cast, get_args, get_origin)
import regex as re
import torch
from torch.distributed import ProcessGroup, ReduceOp
from transformers import PretrainedConfig
+1 -1
View File
@@ -4,7 +4,6 @@
import argparse
import dataclasses
import json
import re
import sys
import threading
import warnings
@@ -13,6 +12,7 @@ from itertools import permutations
from typing import (Annotated, Any, Callable, Dict, List, Literal, Optional,
Type, TypeVar, Union, cast, get_args, get_origin)
import regex as re
import torch
from typing_extensions import TypeIs, deprecated
+1 -1
View File
@@ -7,7 +7,6 @@ import importlib
import inspect
import multiprocessing
import os
import re
import signal
import socket
import tempfile
@@ -21,6 +20,7 @@ from json import JSONDecodeError
from typing import Annotated, Optional, Union
import prometheus_client
import regex as re
import uvloop
from fastapi import APIRouter, Depends, FastAPI, Form, HTTPException, Request
from fastapi.exceptions import RequestValidationError
+1 -1
View File
@@ -3,11 +3,11 @@
# Adapted from
# https://github.com/lm-sys/FastChat/blob/168ccc29d3f7edc50823016105c024fe2282732a/fastchat/protocol/openai_api_protocol.py
import json
import re
import time
from http import HTTPStatus
from typing import Annotated, Any, ClassVar, Literal, Optional, Union
import regex as re
import torch
from fastapi import HTTPException, UploadFile
from pydantic import (BaseModel, ConfigDict, Field, TypeAdapter,
+1 -1
View File
@@ -2,7 +2,6 @@
import asyncio
import json
import re
import time
from collections.abc import AsyncGenerator, AsyncIterator
from collections.abc import Sequence as GenericSequence
@@ -10,6 +9,7 @@ from typing import Callable, Final, Optional, Union
import jinja2
import partial_json_parser
import regex as re
from fastapi import Request
from pydantic import TypeAdapter
@@ -1,9 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import re
from collections.abc import Sequence
from typing import Union
import regex as re
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
DeltaFunctionCall, DeltaMessage,
DeltaToolCall,
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from json import JSONDecoder
from typing import Union
import partial_json_parser
import regex as re
from partial_json_parser.core.options import Allow
from vllm.entrypoints.chat_utils import random_tool_call_id
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from typing import Union
import partial_json_parser
import regex as re
from partial_json_parser.core.options import Allow
from vllm.entrypoints.chat_utils import random_tool_call_id
@@ -1,11 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from typing import Union
import partial_json_parser
import regex as re
from partial_json_parser.core.options import Allow
from vllm.entrypoints.chat_utils import random_tool_call_id
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from json import JSONDecoder
from typing import Union
import partial_json_parser
import regex as re
from partial_json_parser.core.options import Allow
from transformers import PreTrainedTokenizerBase
@@ -1,13 +1,13 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from random import choices
from string import ascii_letters, digits
from typing import Union
import partial_json_parser
import regex as re
from partial_json_parser.core.options import Allow
from pydantic import Field
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
from collections.abc import Sequence
from typing import Any, Optional
import regex as re
from transformers import PreTrainedTokenizerBase
from vllm.entrypoints.chat_utils import random_tool_call_id
@@ -2,10 +2,10 @@
import ast
import json
import re
from collections.abc import Sequence
from typing import Any, Union
import regex as re
from transformers import PreTrainedTokenizerBase
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
+1 -1
View File
@@ -3,11 +3,11 @@
import copy
import math
import os
import re
from collections.abc import Sequence
from dataclasses import dataclass, field
from typing import Any, Callable, Optional, Union
import regex as re
import safetensors.torch
import torch
from torch import nn
+1 -1
View File
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import os
import re
from typing import Optional, Union
import huggingface_hub
import regex as re
from huggingface_hub.utils import (EntryNotFoundError, HfHubHTTPError,
HFValidationError, RepositoryNotFoundError)
from torch import nn
+1 -1
View File
@@ -1,6 +1,6 @@
# SPDX-License-Identifier: Apache-2.0
import re
import regex as re
def has_xgrammar_unsupported_json_features(schema: dict) -> bool:
@@ -4,10 +4,10 @@
from __future__ import annotations
import json
import re
from dataclasses import dataclass, field
from typing import TYPE_CHECKING, Any
import regex as re
import torch
import vllm.envs
@@ -1,10 +1,10 @@
# SPDX-License-Identifier: Apache-2.0
import re
from collections.abc import Iterable, Mapping
from types import MappingProxyType
from typing import Optional
import regex as re
from compressed_tensors import CompressionFormat
from torch.nn import Module
@@ -228,7 +228,7 @@ class ModelOptNvFp4Config(QuantizationConfig):
exclude_modules, group_size)
def is_layer_excluded(self, prefix: str, exclude_modules: list):
import re
import regex as re
for pattern in exclude_modules:
regex_str = pattern.replace('.', r'\.').replace('*', r'.*')
if re.fullmatch(regex_str, prefix):
@@ -1,10 +1,11 @@
# SPDX-License-Identifier: Apache-2.0
import re
from collections.abc import Iterable, Mapping
from types import MappingProxyType
from typing import Any, Optional
import regex as re
def deep_compare(dict1: Any, dict2: Any) -> bool:
if type(dict1) is not type(dict2):
@@ -1,8 +1,8 @@
# SPDX-License-Identifier: Apache-2.0
import re
from copy import deepcopy
from typing import Optional, Union
import regex as re
import torch
from vllm.config import QuantizationConfig
@@ -7,7 +7,6 @@ import dataclasses
import io
import json
import os
import re
import threading
import time
from collections.abc import Generator
@@ -15,6 +14,7 @@ from dataclasses import dataclass
from functools import partial
from typing import Any, BinaryIO, Optional, Union
import regex as re
import torch
from torch import nn
from torch.utils._python_dispatch import TorchDispatchMode
+1 -1
View File
@@ -250,7 +250,7 @@ class MiMoMTP(nn.Module):
return loaded_params
def map_model_name_to_mtp_param_name(self, name: str) -> str:
import re
import regex as re
name_without_prefix = [
"token_layernorm", "hidden_layernorm", "input_proj",
"final_layernorm"
@@ -2,10 +2,10 @@
"""Inference-only MiniMaxText01 model."""
import copy
import math
import re
from collections.abc import Iterable
from typing import Optional, Union
import regex as re
import torch
import torch.distributed
import torch.nn.functional as F
+1 -1
View File
@@ -14,10 +14,10 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import re
from collections.abc import Iterable, Mapping, Sequence
from typing import Any, Literal, Optional, TypedDict, Union
import regex as re
import torch
import torch.nn as nn
from transformers import (BatchFeature, CLIPVisionConfig, PretrainedConfig,
+1 -1
View File
@@ -7,12 +7,12 @@
import copy
import math
import re
import unicodedata
from collections.abc import Collection, Mapping, Sequence, Set
from functools import lru_cache, partial
from typing import Callable, Literal, Optional, TypedDict, Union
import regex as re
import torch
from torch import nn
from torchvision import transforms
+1 -1
View File
@@ -14,11 +14,11 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Wrapper around `transformers` models"""
import re
from collections.abc import Iterable
from contextlib import nullcontext
from typing import Literal, Optional, Union
import regex as re
import torch
from torch import nn
from transformers import AutoModel, PretrainedConfig, PreTrainedModel
+1 -1
View File
@@ -1,6 +1,5 @@
# SPDX-License-Identifier: Apache-2.0
import json
import re
import sys
from abc import ABC, abstractmethod
from collections import defaultdict
@@ -12,6 +11,7 @@ from functools import lru_cache
from typing import (TYPE_CHECKING, Generic, NamedTuple, Optional, Protocol,
TypeVar, Union, cast)
import regex as re
import torch
from typing_extensions import assert_never
+1 -1
View File
@@ -1,9 +1,9 @@
# SPDX-License-Identifier: Apache-2.0
import re
from collections.abc import Sequence
from typing import Optional, Union
import regex as re
from transformers import PreTrainedTokenizerBase
from vllm.entrypoints.openai.protocol import (ChatCompletionRequest,
@@ -1,12 +1,12 @@
# SPDX-License-Identifier: Apache-2.0
import os
import re
from dataclasses import dataclass
from pathlib import Path
from typing import TYPE_CHECKING, Any, Optional, Union, cast
import huggingface_hub
import regex as re
from huggingface_hub import HfApi, hf_hub_download
from vllm.logger import init_logger
+1 -1
View File
@@ -19,7 +19,6 @@ import json
import multiprocessing
import os
import pickle
import re
import signal
import socket
import subprocess
@@ -54,6 +53,7 @@ import cloudpickle
import numpy as np
import numpy.typing as npt
import psutil
import regex as re
import torch
import torch.types
import yaml
+1 -1
View File
@@ -2,7 +2,7 @@
from __future__ import annotations
import re
import regex as re
def grammar_is_likely_lark(grammar_str: str) -> bool: