Support Python 3.10 runtime compatibility (#5366)
Signed-off-by: Xiaodong Ye <xiaodong.ye@mthreads.com>
This commit is contained in:
1 parent
18be2ba3df
commit
7be7e0d249
6 files changed
+38
-71
No files matched your search
@@ -1,12 +1,8 @@
|
|||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from enum import Enum, auto
|
from enum import Enum, auto
|
||||||
from typing import (
|
from typing import Any, Literal, TypeAlias
|
||||||
Any,
|
|
||||||
Literal,
|
from typing_extensions import NotRequired, TypedDict
|
||||||
NotRequired,
|
|
||||||
TypeAlias,
|
|
||||||
TypedDict,
|
|
||||||
)
|
|
||||||
|
|
||||||
AudioFormat: TypeAlias = Literal["mp3", "opus", "aac", "flac", "wav", "pcm"]
|
AudioFormat: TypeAlias = Literal["mp3", "opus", "aac", "flac", "wav", "pcm"]
|
||||||
|
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import multiprocessing
|
|||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
from collections.abc import Iterable, Sequence
|
from collections.abc import Iterable, Sequence
|
||||||
from enum import StrEnum, auto
|
from enum import Enum
|
||||||
from types import SimpleNamespace
|
from types import SimpleNamespace
|
||||||
from typing import Any, NamedTuple
|
from typing import Any, NamedTuple
|
||||||
|
|
||||||
@@ -57,15 +57,15 @@ class SamplingCase(NamedTuple):
|
|||||||
lora: dict | None = None
|
lora: dict | None = None
|
||||||
|
|
||||||
|
|
||||||
class SamplingKind(StrEnum):
|
class SamplingKind(str, Enum):
|
||||||
IMAGE_NONE = auto()
|
IMAGE_NONE = "image_none"
|
||||||
IMAGE_DIFFUSION_SINGLE = auto()
|
IMAGE_DIFFUSION_SINGLE = "image_diffusion_single"
|
||||||
UNDERSTANDING_NONE = auto()
|
UNDERSTANDING_NONE = "understanding_none"
|
||||||
UNDERSTANDING_AR_LIST = auto()
|
UNDERSTANDING_AR_LIST = "understanding_ar_list"
|
||||||
TTS_NONE = auto()
|
TTS_NONE = "tts_none"
|
||||||
TTS_DIFFUSION_SINGLE = auto()
|
TTS_DIFFUSION_SINGLE = "tts_diffusion_single"
|
||||||
VIDEO_NONE = auto()
|
VIDEO_NONE = "video_none"
|
||||||
VIDEO_DIFFUSION_SINGLE = auto()
|
VIDEO_DIFFUSION_SINGLE = "video_diffusion_single"
|
||||||
|
|
||||||
|
|
||||||
# Pre-defined arguments to be used in function calls during the tests
|
# Pre-defined arguments to be used in function calls during the tests
|
||||||
|
|||||||
@@ -16,20 +16,10 @@ Key invariants tested:
|
|||||||
- voice/speaker parameter compatibility in chat completions
|
- voice/speaker parameter compatibility in chat completions
|
||||||
"""
|
"""
|
||||||
|
|
||||||
import enum
|
|
||||||
import json
|
import json
|
||||||
from unittest.mock import MagicMock
|
from unittest.mock import MagicMock
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
# Python 3.10 compat: StrEnum was added in 3.11
|
|
||||||
if not hasattr(enum, "StrEnum"):
|
|
||||||
|
|
||||||
class _StrEnum(str, enum.Enum):
|
|
||||||
"""Minimal StrEnum backport for Python 3.10."""
|
|
||||||
|
|
||||||
enum.StrEnum = _StrEnum # type: ignore[attr-defined]
|
|
||||||
|
|
||||||
from vllm.entrypoints.openai.chat_completion.protocol import (
|
from vllm.entrypoints.openai.chat_completion.protocol import (
|
||||||
ChatCompletionRequest,
|
ChatCompletionRequest,
|
||||||
ChatCompletionResponseStreamChoice,
|
ChatCompletionResponseStreamChoice,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ Common definitions for controlling what tests run where.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from collections.abc import Callable
|
from collections.abc import Callable
|
||||||
from enum import StrEnum, auto
|
from enum import Enum
|
||||||
from typing import NamedTuple, TypeAlias
|
from typing import NamedTuple, TypeAlias
|
||||||
|
|
||||||
from pytest import MarkDecorator
|
from pytest import MarkDecorator
|
||||||
@@ -15,26 +15,26 @@ from vllm_omni.entrypoints.omni import Omni
|
|||||||
TinyDiffusionBuilder: TypeAlias = Callable[[], str]
|
TinyDiffusionBuilder: TypeAlias = Callable[[], str]
|
||||||
|
|
||||||
|
|
||||||
class DiffusionAccs(StrEnum):
|
class DiffusionAccs(str, Enum):
|
||||||
"""Supported acceleration types / test settings for Diffusion Models."""
|
"""Supported acceleration types / test settings for Diffusion Models."""
|
||||||
|
|
||||||
HSDP = auto()
|
HSDP = "hsdp"
|
||||||
TEA_CACHE = auto()
|
TEA_CACHE = "tea_cache"
|
||||||
CACHE_DIT = auto()
|
CACHE_DIT = "cache_dit"
|
||||||
SEQUENCE_PARALLEL = auto()
|
SEQUENCE_PARALLEL = "sequence_parallel"
|
||||||
CFG_PARALLEL = auto()
|
CFG_PARALLEL = "cfg_parallel"
|
||||||
TENSOR_PARALLEL = auto()
|
TENSOR_PARALLEL = "tensor_parallel"
|
||||||
CPU_OFFLOAD = auto()
|
CPU_OFFLOAD = "cpu_offload"
|
||||||
LAYERWISE_OFFLOAD = auto()
|
LAYERWISE_OFFLOAD = "layerwise_offload"
|
||||||
VAE_PATCH_PARALLEL = auto()
|
VAE_PATCH_PARALLEL = "vae_patch_parallel"
|
||||||
|
|
||||||
|
|
||||||
class DiffusionTasks(StrEnum):
|
class DiffusionTasks(str, Enum):
|
||||||
"""Supported tasks for Diffusion Models."""
|
"""Supported tasks for Diffusion Models."""
|
||||||
|
|
||||||
TEXT_TO_IMAGE = auto()
|
TEXT_TO_IMAGE = "text_to_image"
|
||||||
IMAGE_TO_IMAGE = auto()
|
IMAGE_TO_IMAGE = "image_to_image"
|
||||||
TEXT_TO_VIDEO = auto()
|
TEXT_TO_VIDEO = "text_to_video"
|
||||||
# Text to audio, etc should be added here as needed
|
# Text to audio, etc should be added here as needed
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,24 +1,16 @@
|
|||||||
import copy
|
import copy
|
||||||
import pprint
|
import pprint
|
||||||
from dataclasses import asdict, dataclass, field
|
from dataclasses import asdict, dataclass, field
|
||||||
from typing import Any, TypeAlias, TypedDict
|
from typing import Any, TypeAlias
|
||||||
|
|
||||||
from vllm.inputs import PromptType
|
import torch
|
||||||
|
from typing_extensions import NotRequired, TypedDict
|
||||||
|
from vllm.inputs import EmbedsPrompt, PromptType, TextPrompt, TokensPrompt
|
||||||
|
from vllm.inputs.engine import TokensInput
|
||||||
from vllm.sampling_params import SamplingParams
|
from vllm.sampling_params import SamplingParams
|
||||||
|
|
||||||
from vllm_omni.lora.request import LoRARequest
|
from vllm_omni.lora.request import LoRARequest
|
||||||
|
|
||||||
try:
|
|
||||||
from typing import NotRequired
|
|
||||||
except ImportError:
|
|
||||||
# Python < 3.11: use typing_extensions
|
|
||||||
from typing_extensions import NotRequired
|
|
||||||
|
|
||||||
|
|
||||||
import torch
|
|
||||||
from vllm.inputs import EmbedsPrompt, TextPrompt, TokensPrompt
|
|
||||||
from vllm.inputs.engine import TokensInput
|
|
||||||
|
|
||||||
|
|
||||||
class OmniTextPrompt(TextPrompt):
|
class OmniTextPrompt(TextPrompt):
|
||||||
"""Text prompt with optional embeddings and stage payloads.
|
"""Text prompt with optional embeddings and stage payloads.
|
||||||
|
|||||||
@@ -8,23 +8,8 @@ for type-safe multimodal output routing and tensor merging.
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import re
|
import re
|
||||||
import sys
|
|
||||||
from enum import Enum, Flag, auto
|
from enum import Enum, Flag, auto
|
||||||
|
|
||||||
if sys.version_info >= (3, 11):
|
|
||||||
from enum import StrEnum
|
|
||||||
else:
|
|
||||||
# TODO: Remove this Python 3.10 compatibility shim when Python 3.10 support is dropped.
|
|
||||||
class StrEnum(str, Enum):
|
|
||||||
"""``enum.StrEnum`` for Python 3.10, which predates it.
|
|
||||||
|
|
||||||
``__str__`` is taken from ``str`` so ``str(member)`` yields the member
|
|
||||||
value rather than ``"ClassName.MEMBER"``, matching 3.11 semantics.
|
|
||||||
"""
|
|
||||||
|
|
||||||
__str__ = str.__str__
|
|
||||||
|
|
||||||
|
|
||||||
_MODALITY_ALIASES: dict[str, str] = {
|
_MODALITY_ALIASES: dict[str, str] = {
|
||||||
"speech": "audio",
|
"speech": "audio",
|
||||||
"images": "image",
|
"images": "image",
|
||||||
@@ -38,13 +23,17 @@ _MODALITY_ALIASES: dict[str, str] = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class OutputModalityNames(StrEnum):
|
class OutputModalityNames(str, Enum):
|
||||||
"""Keys for output modalities.
|
"""Keys for output modalities.
|
||||||
|
|
||||||
TODO: (Alex) Integrate this with the big-flag enum below + throughout the code
|
TODO: (Alex) Integrate this with the big-flag enum below + throughout the code
|
||||||
for better type safety (currently only used for output processor).
|
for better type safety (currently only used for output processor).
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Keep the string conversion provided by ``enum.StrEnum`` while using the
|
||||||
|
# Python 3.10-compatible ``str, Enum`` form.
|
||||||
|
__str__ = str.__str__
|
||||||
|
|
||||||
TEXT = "text"
|
TEXT = "text"
|
||||||
IMAGE = "image"
|
IMAGE = "image"
|
||||||
AUDIO = "audio"
|
AUDIO = "audio"
|
||||||
|
|||||||
Reference in new issue
Block a user