Remove Python 3.10 support now that it is EOL (#60402)
Signed-off-by: Harry Mellor <19981378+hmellor@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
0004536dd0
commit
21d9758459
@@ -253,7 +253,7 @@ async def fetch_spec_decode_metrics(
|
||||
num_accepted_tokens=num_accepted_tokens,
|
||||
accepted_per_pos=accepted_per_pos,
|
||||
)
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError):
|
||||
except (TimeoutError, aiohttp.ClientError):
|
||||
return None
|
||||
|
||||
|
||||
@@ -315,7 +315,7 @@ async def fetch_diffusion_metrics(
|
||||
num_canvas_positions=num_canvas_positions,
|
||||
num_committed_tokens=num_committed_tokens,
|
||||
)
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError):
|
||||
except (TimeoutError, aiohttp.ClientError):
|
||||
return None
|
||||
|
||||
|
||||
|
||||
@@ -8,9 +8,9 @@ from dataclasses import dataclass
|
||||
from functools import partial
|
||||
from pathlib import Path
|
||||
from types import TracebackType
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
from typing import TYPE_CHECKING, ClassVar, Self
|
||||
|
||||
from typing_extensions import Self, override
|
||||
from typing_extensions import override
|
||||
|
||||
from vllm.utils.argparse_utils import FlexibleArgumentParser
|
||||
from vllm.utils.collection_utils import full_groupby
|
||||
|
||||
@@ -4,10 +4,9 @@ import argparse
|
||||
import math
|
||||
from dataclasses import dataclass, fields
|
||||
from pathlib import Path
|
||||
from typing import ClassVar, Literal, get_args
|
||||
from typing import ClassVar, Literal, assert_never, get_args
|
||||
|
||||
import numpy as np
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.benchmarks.datasets import DEFAULT_NUM_PROMPTS
|
||||
from vllm.utils.argparse_utils import FlexibleArgumentParser
|
||||
|
||||
@@ -6,9 +6,9 @@ import signal
|
||||
import subprocess
|
||||
import time
|
||||
from types import TracebackType
|
||||
from typing import Self
|
||||
|
||||
import requests
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class ServerProcess:
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, Self
|
||||
|
||||
from pydantic import model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config.utils import config, get_hash_factors, hash_factors
|
||||
|
||||
|
||||
+1
-2
@@ -2,11 +2,10 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import os
|
||||
from typing import TYPE_CHECKING, Any, Literal
|
||||
from typing import TYPE_CHECKING, Any, Literal, Self
|
||||
|
||||
import torch
|
||||
from pydantic import ConfigDict, Field, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm import envs
|
||||
from vllm.config.utils import config
|
||||
|
||||
@@ -5,13 +5,12 @@ import os
|
||||
import socket
|
||||
from collections.abc import Callable
|
||||
from datetime import timedelta
|
||||
from typing import TYPE_CHECKING, Any, Literal, overload
|
||||
from typing import TYPE_CHECKING, Any, Literal, Self, overload
|
||||
|
||||
import regex as re
|
||||
import torch
|
||||
from pydantic import Field, field_validator, model_validator
|
||||
from torch.distributed import ProcessGroup, ReduceOp, Store
|
||||
from typing_extensions import Self
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config.fault_tolerance import FaultToleranceConfig
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import os
|
||||
from typing import Any, Literal
|
||||
from typing import Any, Literal, Self
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config.utils import config
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
from collections.abc import Callable
|
||||
from dataclasses import InitVar
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Literal, cast
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Literal, Self, cast
|
||||
|
||||
from pydantic import Field, field_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config.utils import config
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
import copy
|
||||
import functools
|
||||
from collections.abc import Callable, Mapping
|
||||
from typing import TYPE_CHECKING, Any, Literal, get_args
|
||||
from typing import TYPE_CHECKING, Any, Literal, Self, get_args
|
||||
|
||||
from pydantic import Field, SkipValidation, field_validator, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config import LoadConfig
|
||||
from vllm.config.cache import CacheDType
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
from typing import Any, Literal
|
||||
from typing import Any, Literal, Self
|
||||
|
||||
from pydantic import model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config.utils import config
|
||||
from vllm.utils.hashing import safe_hash
|
||||
|
||||
@@ -2,10 +2,9 @@
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
|
||||
import hashlib
|
||||
from typing import Literal
|
||||
from typing import Literal, Self
|
||||
|
||||
from pydantic import Field, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.config.utils import config
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -38,9 +38,7 @@ logger = init_logger(__name__)
|
||||
# We prefer to use os.sched_yield as it results in tighter polling loops,
|
||||
# measured to be around 3e-7 seconds. However on earlier versions of Python
|
||||
# os.sched_yield() does not release the GIL, so we fall back to time.sleep(0)
|
||||
USE_SCHED_YIELD = (sys.version_info[:3] >= (3, 11, 1)) or (
|
||||
sys.version_info[:2] == (3, 10) and sys.version_info[2] >= 8
|
||||
)
|
||||
USE_SCHED_YIELD = sys.version_info[:3] >= (3, 11, 1)
|
||||
|
||||
|
||||
def sched_yield():
|
||||
@@ -52,8 +50,8 @@ def sched_yield():
|
||||
|
||||
def ensure_divisibility(numerator, denominator):
|
||||
"""Ensure that numerator is divisible by the denominator."""
|
||||
assert numerator % denominator == 0, "{} is not divisible by {}".format(
|
||||
numerator, denominator
|
||||
assert numerator % denominator == 0, (
|
||||
f"{numerator} is not divisible by {denominator}"
|
||||
)
|
||||
|
||||
|
||||
@@ -146,9 +144,7 @@ def get_pp_indices(
|
||||
try:
|
||||
partitions = [int(layer) for layer in partition_list_str.split(",")]
|
||||
except ValueError as err:
|
||||
raise ValueError(
|
||||
"Invalid partition string: {}".format(partition_list_str)
|
||||
) from err
|
||||
raise ValueError(f"Invalid partition string: {partition_list_str}") from err
|
||||
if len(partitions) != pp_size:
|
||||
raise ValueError(f"{len(partitions)=} does not match {pp_size=}.")
|
||||
if sum(partitions) != num_hidden_layers:
|
||||
|
||||
@@ -11,12 +11,12 @@ from typing import (
|
||||
ClassVar,
|
||||
Generic,
|
||||
Protocol,
|
||||
Self,
|
||||
TypeVar,
|
||||
runtime_checkable,
|
||||
)
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.config import VllmConfig
|
||||
|
||||
@@ -4,12 +4,11 @@
|
||||
|
||||
import pickle
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import TYPE_CHECKING, Any, ClassVar
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Self
|
||||
|
||||
import pybase64 as base64
|
||||
import torch
|
||||
from torch.multiprocessing.reductions import rebuild_cuda_tensor, reduce_tensor
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm import envs
|
||||
from vllm.config.weight_transfer import WeightTransferConfig
|
||||
|
||||
@@ -15,10 +15,9 @@ in every caller.
|
||||
|
||||
from concurrent.futures import Future, ThreadPoolExecutor
|
||||
from dataclasses import dataclass, field
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, cast
|
||||
from typing import TYPE_CHECKING, Any, ClassVar, Self, cast
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.distributed.weight_transfer.base import (
|
||||
TrainerInitInfo,
|
||||
|
||||
@@ -5,10 +5,9 @@
|
||||
from collections.abc import Iterator
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
from typing import TYPE_CHECKING, ClassVar, Self
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.config import VllmConfig
|
||||
|
||||
@@ -24,7 +24,7 @@ import uuid
|
||||
from collections.abc import Callable, Collection
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import Any, ClassVar
|
||||
from typing import Any, ClassVar, Self
|
||||
|
||||
import ray
|
||||
import torch
|
||||
@@ -33,7 +33,6 @@ from torch.multiprocessing.reductions import (
|
||||
rebuild_cuda_tensor,
|
||||
reduce_tensor,
|
||||
)
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.distributed.weight_transfer.base import (
|
||||
ParamMeta,
|
||||
|
||||
@@ -11,10 +11,9 @@ from collections.abc import Iterable
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from contextlib import nullcontext
|
||||
from dataclasses import asdict, dataclass
|
||||
from typing import TYPE_CHECKING, ClassVar
|
||||
from typing import TYPE_CHECKING, ClassVar, Self
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from vllm.config import VllmConfig
|
||||
|
||||
@@ -17,6 +17,7 @@ from typing import (
|
||||
Final,
|
||||
Generic,
|
||||
Literal,
|
||||
Required,
|
||||
TypeAlias,
|
||||
TypeVar,
|
||||
Union,
|
||||
@@ -48,7 +49,7 @@ from PIL import Image
|
||||
from pydantic import BaseModel, ConfigDict, TypeAdapter
|
||||
|
||||
# pydantic needs the TypedDict from typing_extensions
|
||||
from typing_extensions import Required, TypedDict, override
|
||||
from typing_extensions import TypedDict, override
|
||||
|
||||
from vllm import envs
|
||||
from vllm.config import ModelConfig
|
||||
|
||||
@@ -200,7 +200,7 @@ async def _probe_endpoint(
|
||||
# vLLM returns 503 on EngineDeadError, so we should return
|
||||
# immediately if vLLM responds with a non-200 status code.
|
||||
return response.status == HTTPStatus.OK
|
||||
except (aiohttp.ClientError, asyncio.TimeoutError) as e:
|
||||
except (TimeoutError, aiohttp.ClientError) as e:
|
||||
# Allow retry of connection errors.
|
||||
logger.debug(
|
||||
"Probe attempt %d/%d failed on port %d: %r",
|
||||
|
||||
@@ -3,13 +3,12 @@
|
||||
|
||||
from collections.abc import Callable, Sequence
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING, Any
|
||||
from typing import TYPE_CHECKING, Any, overload
|
||||
|
||||
import cloudpickle
|
||||
import torch.nn as nn
|
||||
from pydantic import ValidationError
|
||||
from tqdm.auto import tqdm
|
||||
from typing_extensions import overload
|
||||
|
||||
from vllm.config import (
|
||||
AttentionConfig,
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import TypeAlias, cast
|
||||
from typing import TypeAlias, assert_never, cast
|
||||
|
||||
from fastapi.responses import JSONResponse, Response, StreamingResponse
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.outputs import PoolingRequestOutput
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from typing import cast
|
||||
from typing import assert_never, cast
|
||||
|
||||
from fastapi.responses import JSONResponse, Response, StreamingResponse
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from dataclasses import dataclass
|
||||
from typing import TypeAlias
|
||||
from typing import Required, TypeAlias
|
||||
|
||||
from typing_extensions import Required, TypedDict
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from vllm.entrypoints.chat_utils import (
|
||||
ChatCompletionContentPartImageEmbedsParam,
|
||||
|
||||
@@ -3,10 +3,10 @@
|
||||
|
||||
|
||||
from http import HTTPStatus
|
||||
from typing import assert_never
|
||||
|
||||
from fastapi import APIRouter, Depends, FastAPI, Request
|
||||
from fastapi.responses import JSONResponse
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.entrypoints.serve.engine.protocol import ErrorResponse
|
||||
from vllm.entrypoints.serve.tokenize.protocol import (
|
||||
|
||||
@@ -3,9 +3,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import TYPE_CHECKING, Literal, TypeAlias
|
||||
from typing import TYPE_CHECKING, Literal, NotRequired, TypeAlias, assert_never
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict, assert_never
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
from vllm.exceptions import VLLMValidationError
|
||||
|
||||
|
||||
+2
-2
@@ -3,9 +3,9 @@
|
||||
# SPDX-License-Identifier: Apache-2.0
|
||||
# SPDX-FileCopyrightText: Copyright contributors to the vLLM project
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import TYPE_CHECKING, Any, TypeAlias, TypeVar, final
|
||||
from typing import TYPE_CHECKING, Any, NotRequired, TypeAlias, TypeVar, final
|
||||
|
||||
from typing_extensions import NotRequired, TypedDict
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import torch
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import Any, ClassVar, Generic, TypeVar
|
||||
from typing import Any, ClassVar, Generic, Self, TypeVar
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.model_executor.layers.quantization.utils.quant_utils import QuantKey
|
||||
|
||||
|
||||
@@ -3,10 +3,9 @@
|
||||
|
||||
from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import ClassVar
|
||||
from typing import ClassVar, Self
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.model_executor.layers.quantization.input_quant_fp8 import QuantFP8
|
||||
from vllm.model_executor.layers.quantization.utils.fp8_utils import (
|
||||
|
||||
@@ -6,11 +6,10 @@ import inspect
|
||||
import time
|
||||
import warnings
|
||||
from contextlib import contextmanager, nullcontext
|
||||
from typing import Any
|
||||
from typing import Any, assert_never
|
||||
|
||||
import torch
|
||||
from torch import nn
|
||||
from typing_extensions import assert_never
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import (
|
||||
|
||||
@@ -21,6 +21,7 @@ from typing import (
|
||||
ClassVar,
|
||||
Literal,
|
||||
Protocol,
|
||||
Self,
|
||||
TypeAlias,
|
||||
overload,
|
||||
runtime_checkable,
|
||||
@@ -31,7 +32,7 @@ import torch
|
||||
import torch.nn as nn
|
||||
from torch import Tensor
|
||||
from transformers.models.whisper.tokenization_whisper import LANGUAGES
|
||||
from typing_extensions import Self, TypeIs
|
||||
from typing_extensions import TypeIs
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.model_executor.layers.quantization import QuantizationConfig
|
||||
|
||||
@@ -22,13 +22,12 @@ reference's out-of-vocab scheme.
|
||||
|
||||
import math
|
||||
from collections.abc import Mapping, Sequence
|
||||
from typing import Any
|
||||
from typing import Any, assert_never
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from PIL import Image, ImageOps
|
||||
from transformers import BatchFeature
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.config.multimodal import MultiModalDummyOptions
|
||||
from vllm.inputs import MultiModalDataDict
|
||||
|
||||
@@ -13,11 +13,11 @@ from typing import (
|
||||
TypeAlias,
|
||||
TypeGuard,
|
||||
TypeVar,
|
||||
assert_never,
|
||||
)
|
||||
|
||||
import numpy as np
|
||||
import torch
|
||||
from typing_extensions import assert_never
|
||||
|
||||
from vllm.inputs import ModalityData, MultiModalDataDict, MultiModalUUIDDict
|
||||
from vllm.utils.collection_utils import is_list_of
|
||||
|
||||
@@ -13,10 +13,11 @@ from typing import (
|
||||
NamedTuple,
|
||||
Protocol,
|
||||
TypeAlias,
|
||||
assert_never,
|
||||
)
|
||||
|
||||
import torch
|
||||
from typing_extensions import TypeVar, assert_never
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from vllm.config import SchedulerConfig
|
||||
from vllm.inputs import (
|
||||
|
||||
@@ -1000,7 +1000,7 @@ class HfRenderer(BaseRenderer[HfTokenizer]):
|
||||
return await coro
|
||||
try:
|
||||
return await asyncio.wait_for(coro, timeout=timeout)
|
||||
except asyncio.TimeoutError:
|
||||
except TimeoutError:
|
||||
self._replace_executor()
|
||||
raise TimeoutError(
|
||||
f"Chat template rendering timed out after "
|
||||
|
||||
@@ -6,7 +6,7 @@ import math
|
||||
import os
|
||||
import stat
|
||||
from pathlib import Path
|
||||
from typing import Annotated, Any, Literal
|
||||
from typing import Annotated, Any, Literal, Self
|
||||
|
||||
from pydantic import (
|
||||
BaseModel,
|
||||
@@ -19,7 +19,6 @@ from pydantic import (
|
||||
field_validator,
|
||||
model_validator,
|
||||
)
|
||||
from typing_extensions import Self
|
||||
|
||||
|
||||
class SnapshotCompatibilityError(RuntimeError):
|
||||
|
||||
@@ -24,7 +24,7 @@ import urllib.request
|
||||
from collections.abc import Iterable
|
||||
from contextlib import suppress
|
||||
from dataclasses import dataclass
|
||||
from datetime import datetime, timezone
|
||||
from datetime import UTC, datetime
|
||||
from pathlib import Path
|
||||
from typing import NoReturn
|
||||
|
||||
@@ -872,7 +872,7 @@ class LocalSnapshotTools:
|
||||
return SnapshotManifest(
|
||||
schema_version=1,
|
||||
boundary="post-engine-init-reloadable-state-released",
|
||||
created_at=datetime.now(timezone.utc).isoformat(),
|
||||
created_at=datetime.now(UTC).isoformat(),
|
||||
artifact_bytes=self._artifact_bytes(workdir),
|
||||
**identity.model_dump(),
|
||||
model=source_model,
|
||||
|
||||
@@ -4,10 +4,10 @@ import contextlib
|
||||
from dataclasses import dataclass, field
|
||||
from functools import lru_cache
|
||||
from pathlib import Path
|
||||
from typing import TYPE_CHECKING
|
||||
from typing import TYPE_CHECKING, assert_never
|
||||
|
||||
import huggingface_hub
|
||||
from typing_extensions import TypeVar, assert_never
|
||||
from typing_extensions import TypeVar
|
||||
|
||||
from vllm import envs
|
||||
from vllm.logger import init_logger
|
||||
|
||||
@@ -69,7 +69,7 @@ def is_usage_stats_enabled():
|
||||
|
||||
|
||||
def _get_current_timestamp_ns() -> int:
|
||||
return int(datetime.datetime.now(datetime.timezone.utc).timestamp() * 1e9)
|
||||
return int(datetime.datetime.now(datetime.UTC).timestamp() * 1e9)
|
||||
|
||||
|
||||
def _detect_cloud_provider() -> str:
|
||||
|
||||
@@ -8,9 +8,9 @@ This is similar in concept to the `collections` module.
|
||||
import math
|
||||
from collections import defaultdict
|
||||
from collections.abc import Callable, Generator, Hashable, Iterable, Mapping, Sequence
|
||||
from typing import Generic, Literal, TypeVar
|
||||
from typing import Generic, Literal, TypeVar, assert_never, overload
|
||||
|
||||
from typing_extensions import TypeIs, assert_never, overload
|
||||
from typing_extensions import TypeIs
|
||||
|
||||
T = TypeVar("T")
|
||||
|
||||
|
||||
@@ -12,10 +12,9 @@ import os
|
||||
import sys
|
||||
from functools import cache
|
||||
from types import ModuleType
|
||||
from typing import Any
|
||||
from typing import Any, Never
|
||||
|
||||
import regex as re
|
||||
from typing_extensions import Never
|
||||
|
||||
from vllm.logger import init_logger
|
||||
|
||||
|
||||
@@ -11,10 +11,9 @@ from enum import Enum, IntEnum
|
||||
from fractions import Fraction
|
||||
from functools import cached_property
|
||||
from math import prod
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
from typing import TYPE_CHECKING, Self, TypeVar
|
||||
|
||||
import torch
|
||||
from typing_extensions import Self
|
||||
|
||||
from vllm.logger import init_logger
|
||||
from vllm.utils.math_utils import cdiv, round_up
|
||||
|
||||
@@ -10,12 +10,11 @@ import time
|
||||
from abc import ABC, abstractmethod
|
||||
from collections.abc import Iterable
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from typing import Any, Protocol
|
||||
from typing import Any, Protocol, Self
|
||||
|
||||
import prometheus_client
|
||||
import torch
|
||||
from pydantic import BaseModel, Field, ValidationError, model_validator
|
||||
from typing_extensions import Self
|
||||
|
||||
import vllm.envs as envs
|
||||
from vllm.config import VllmConfig
|
||||
|
||||
@@ -4,10 +4,9 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import ast
|
||||
import importlib
|
||||
import json
|
||||
import sys
|
||||
from dataclasses import dataclass, field
|
||||
from re import _constants, _parser # type: ignore[attr-defined]
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
import torch
|
||||
@@ -36,19 +35,6 @@ else:
|
||||
oc = LazyLoader("oc", globals(), "outlines_core")
|
||||
json_schema = LazyLoader("json_schema", globals(), "outlines_core.json_schema")
|
||||
|
||||
# Python 3.11+ sre_parse and sre_constants
|
||||
# are deprecated, so we must import them from re
|
||||
if sys.version_info >= (3, 11):
|
||||
# Hack to get around pre-commit regex module rule
|
||||
# because going through re is the only way to get sre_parse
|
||||
# and sre_constants in Python 3.11+
|
||||
_re = importlib.import_module("re")
|
||||
sre_parse = _re._parser
|
||||
sre_constants = _re._constants
|
||||
else:
|
||||
import sre_constants
|
||||
import sre_parse
|
||||
|
||||
|
||||
@dataclass
|
||||
class OutlinesBackend(StructuredOutputBackend):
|
||||
@@ -261,20 +247,20 @@ def _prefix_needs_context(parsed) -> bool:
|
||||
tokens = parsed.data if hasattr(parsed, "data") else parsed
|
||||
for ttype, tval in tokens:
|
||||
# literal, character class, or dot always consumes
|
||||
if ttype in (sre_parse.LITERAL, sre_parse.IN, sre_parse.ANY):
|
||||
if ttype in (_parser.LITERAL, _parser.IN, _parser.ANY):
|
||||
return True
|
||||
# quantified subpattern: check inner pattern
|
||||
elif ttype == sre_parse.MAX_REPEAT:
|
||||
elif ttype == _parser.MAX_REPEAT:
|
||||
_, mx, sub = tval
|
||||
if mx != 0 and subpattern_consumes(sub):
|
||||
return True
|
||||
# alternation: if any branch consumes, the whole does
|
||||
elif ttype == sre_parse.BRANCH:
|
||||
elif ttype == _parser.BRANCH:
|
||||
_, branches = tval
|
||||
if any(subpattern_consumes(br) for br in branches):
|
||||
return True
|
||||
# grouped subpattern: recurse into its contents
|
||||
elif ttype == sre_parse.SUBPATTERN and subpattern_consumes(tval[3]):
|
||||
elif ttype == _parser.SUBPATTERN and subpattern_consumes(tval[3]):
|
||||
return True
|
||||
# No consumers, return False
|
||||
return False
|
||||
@@ -282,14 +268,11 @@ def _prefix_needs_context(parsed) -> bool:
|
||||
tokens = parsed.data if hasattr(parsed, "data") else parsed
|
||||
for ttype, tval in tokens:
|
||||
# Direct anchors or look-around
|
||||
if ttype == sre_parse.AT or ttype in (
|
||||
sre_constants.ASSERT,
|
||||
sre_constants.ASSERT_NOT,
|
||||
):
|
||||
if ttype == _parser.AT or ttype in (_constants.ASSERT, _constants.ASSERT_NOT):
|
||||
return True
|
||||
|
||||
# Nested subpattern: check
|
||||
if ttype == sre_parse.SUBPATTERN:
|
||||
if ttype == _parser.SUBPATTERN:
|
||||
# tval: (group, add_flags, del_flags, subpattern)
|
||||
if _prefix_needs_context(tval[3]):
|
||||
return True
|
||||
@@ -298,7 +281,7 @@ def _prefix_needs_context(parsed) -> bool:
|
||||
|
||||
# if any branch has a prefix anchor => True,
|
||||
# else if at least one branch consumes => prefix ends => False
|
||||
elif ttype == sre_parse.BRANCH:
|
||||
elif ttype == _parser.BRANCH:
|
||||
saw_consumer = False
|
||||
for br in tval[1]:
|
||||
if _prefix_needs_context(br):
|
||||
@@ -309,11 +292,11 @@ def _prefix_needs_context(parsed) -> bool:
|
||||
return False
|
||||
|
||||
# Immediate consumer tokens
|
||||
elif ttype in (sre_parse.LITERAL, sre_parse.IN, sre_parse.ANY):
|
||||
elif ttype in (_parser.LITERAL, _parser.IN, _parser.ANY):
|
||||
return False
|
||||
|
||||
# if subpattern has anchor => True, if it can consume => stop
|
||||
elif ttype == sre_parse.MAX_REPEAT:
|
||||
elif ttype == _parser.MAX_REPEAT:
|
||||
if _prefix_needs_context(tval[2]):
|
||||
return True
|
||||
if subpattern_consumes(tval[2]):
|
||||
@@ -327,25 +310,25 @@ def _check_unsupported(parsed) -> None:
|
||||
tokens = parsed.data if hasattr(parsed, "data") else parsed
|
||||
for ttype, tval in tokens:
|
||||
# backreference
|
||||
if ttype in (sre_parse.GROUPREF, sre_parse.GROUPREF_EXISTS):
|
||||
if ttype in (_parser.GROUPREF, _parser.GROUPREF_EXISTS):
|
||||
raise ValueError("Backreferences are unsupported.")
|
||||
|
||||
# look-around assertion
|
||||
elif ttype in (sre_constants.ASSERT, sre_constants.ASSERT_NOT):
|
||||
elif ttype in (_constants.ASSERT, _constants.ASSERT_NOT):
|
||||
raise ValueError("Look-Around assertion are unsupported.")
|
||||
|
||||
# unicode word boundaries
|
||||
elif ttype == sre_parse.AT:
|
||||
if tval in (sre_constants.AT_BOUNDARY, sre_constants.AT_NON_BOUNDARY):
|
||||
elif ttype == _parser.AT:
|
||||
if tval in (_constants.AT_BOUNDARY, _constants.AT_NON_BOUNDARY):
|
||||
raise ValueError("Unicode word boundaries are unsupported.")
|
||||
|
||||
elif ttype == sre_parse.BRANCH:
|
||||
elif ttype == _parser.BRANCH:
|
||||
# tval is (None, branches)
|
||||
for branch in tval[1]:
|
||||
_check_unsupported(branch)
|
||||
|
||||
# tval is (min, max, subpattern)
|
||||
elif ttype == sre_parse.MAX_REPEAT:
|
||||
elif ttype == _parser.MAX_REPEAT:
|
||||
_check_unsupported(tval[2])
|
||||
|
||||
|
||||
@@ -357,9 +340,9 @@ def validate_regex_is_buildable(pattern: str) -> None:
|
||||
https://docs.rs/regex-automata/latest/regex_automata/dfa/trait.Automaton.html#method.universal_start_state
|
||||
"""
|
||||
try:
|
||||
parsed = sre_parse.parse(pattern)
|
||||
parsed = _parser.parse(pattern)
|
||||
|
||||
except sre_constants.error as e:
|
||||
except _constants.error as e:
|
||||
raise VLLMValidationError(f"Error parsing regex: {e}") from e
|
||||
|
||||
try:
|
||||
|
||||
@@ -229,12 +229,7 @@ class WorkspaceManager:
|
||||
# Walk up the stack skipping WorkspaceManager frames
|
||||
curr_frame = curr_frame.f_back
|
||||
while curr_frame is not None:
|
||||
# TODO: This only catches instance methods (self), missing
|
||||
# classmethods and staticmethods. Once Python 3.11+ is the
|
||||
# minimum supported version, use co_qualname instead:
|
||||
# qualname = curr_frame.f_code.co_qualname
|
||||
# if qualname.startswith("WorkspaceManager."):
|
||||
if isinstance(curr_frame.f_locals.get("self"), WorkspaceManager):
|
||||
if curr_frame.f_code.co_qualname.startswith("WorkspaceManager."):
|
||||
curr_frame = curr_frame.f_back
|
||||
continue
|
||||
filename = os.path.basename(curr_frame.f_code.co_filename)
|
||||
|
||||
Reference in New Issue
Block a user