Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes. See raw diff
- .gitattributes +1 -0
- vllm/lib/python3.10/site-packages/functorch/_C.cpython-310-x86_64-linux-gnu.so +3 -0
- vllm/lib/python3.10/site-packages/pydantic/parse.py +5 -0
- vllm/lib/python3.10/site-packages/pydantic/type_adapter.py +676 -0
- vllm/lib/python3.10/site-packages/pydantic/validators.py +5 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/__main__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_cell_widths.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_emoji_replace.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_export_format.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_extension.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_fileno.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_inspect.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_log_render.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_null_file.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_palettes.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_ratio.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_spinners.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_stack.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_timer.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_win32_console.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_windows.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_windows_renderer.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/_wrap.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/abc.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/align.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/ansi.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/bar.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/box.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/cells.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/color.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/color_triplet.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/columns.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/constrain.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/containers.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/control.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/diagnose.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/emoji.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/errors.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/file_proxy.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/filesize.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/highlighter.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/jupyter.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/layout.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/live.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/logging.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/markdown.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/markup.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/measure.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/padding.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/rich/__pycache__/palette.cpython-310.pyc +0 -0
.gitattributes
CHANGED
|
@@ -1586,3 +1586,4 @@ parrot/lib/python3.10/site-packages/scipy/signal/_peak_finding_utils.cpython-310
|
|
| 1586 |
parrot/lib/python3.10/site-packages/scipy/interpolate/_dfitpack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1587 |
parrot/lib/python3.10/site-packages/scipy/signal/tests/__pycache__/test_filter_design.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 1588 |
parrot/lib/python3.10/site-packages/scipy/stats/__pycache__/_continuous_distns.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
| 1586 |
parrot/lib/python3.10/site-packages/scipy/interpolate/_dfitpack.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
| 1587 |
parrot/lib/python3.10/site-packages/scipy/signal/tests/__pycache__/test_filter_design.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 1588 |
parrot/lib/python3.10/site-packages/scipy/stats/__pycache__/_continuous_distns.cpython-310.pyc filter=lfs diff=lfs merge=lfs -text
|
| 1589 |
+
vllm/lib/python3.10/site-packages/functorch/_C.cpython-310-x86_64-linux-gnu.so filter=lfs diff=lfs merge=lfs -text
|
vllm/lib/python3.10/site-packages/functorch/_C.cpython-310-x86_64-linux-gnu.so
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9d3fe8b0579d327f70965aa4078078ec8a9c0a71741bcbced65b3db69b79522c
|
| 3 |
+
size 320240
|
vllm/lib/python3.10/site-packages/pydantic/parse.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The `parse` module is a backport module from V1."""
|
| 2 |
+
|
| 3 |
+
from ._migration import getattr_migration
|
| 4 |
+
|
| 5 |
+
__getattr__ = getattr_migration(__name__)
|
vllm/lib/python3.10/site-packages/pydantic/type_adapter.py
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Type adapter specification."""
|
| 2 |
+
|
| 3 |
+
from __future__ import annotations as _annotations
|
| 4 |
+
|
| 5 |
+
import sys
|
| 6 |
+
from dataclasses import is_dataclass
|
| 7 |
+
from types import FrameType
|
| 8 |
+
from typing import (
|
| 9 |
+
Any,
|
| 10 |
+
Generic,
|
| 11 |
+
Iterable,
|
| 12 |
+
Literal,
|
| 13 |
+
TypeVar,
|
| 14 |
+
cast,
|
| 15 |
+
final,
|
| 16 |
+
overload,
|
| 17 |
+
)
|
| 18 |
+
|
| 19 |
+
from pydantic_core import CoreSchema, SchemaSerializer, SchemaValidator, Some
|
| 20 |
+
from typing_extensions import ParamSpec, is_typeddict
|
| 21 |
+
|
| 22 |
+
from pydantic.errors import PydanticUserError
|
| 23 |
+
from pydantic.main import BaseModel, IncEx
|
| 24 |
+
|
| 25 |
+
from ._internal import _config, _generate_schema, _mock_val_ser, _namespace_utils, _repr, _typing_extra, _utils
|
| 26 |
+
from .config import ConfigDict
|
| 27 |
+
from .errors import PydanticUndefinedAnnotation
|
| 28 |
+
from .json_schema import (
|
| 29 |
+
DEFAULT_REF_TEMPLATE,
|
| 30 |
+
GenerateJsonSchema,
|
| 31 |
+
JsonSchemaKeyT,
|
| 32 |
+
JsonSchemaMode,
|
| 33 |
+
JsonSchemaValue,
|
| 34 |
+
)
|
| 35 |
+
from .plugin._schema_validator import PluggableSchemaValidator, create_schema_validator
|
| 36 |
+
|
| 37 |
+
T = TypeVar('T')
|
| 38 |
+
R = TypeVar('R')
|
| 39 |
+
P = ParamSpec('P')
|
| 40 |
+
TypeAdapterT = TypeVar('TypeAdapterT', bound='TypeAdapter')
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
def _getattr_no_parents(obj: Any, attribute: str) -> Any:
|
| 44 |
+
"""Returns the attribute value without attempting to look up attributes from parent types."""
|
| 45 |
+
if hasattr(obj, '__dict__'):
|
| 46 |
+
try:
|
| 47 |
+
return obj.__dict__[attribute]
|
| 48 |
+
except KeyError:
|
| 49 |
+
pass
|
| 50 |
+
|
| 51 |
+
slots = getattr(obj, '__slots__', None)
|
| 52 |
+
if slots is not None and attribute in slots:
|
| 53 |
+
return getattr(obj, attribute)
|
| 54 |
+
else:
|
| 55 |
+
raise AttributeError(attribute)
|
| 56 |
+
|
| 57 |
+
|
| 58 |
+
def _type_has_config(type_: Any) -> bool:
|
| 59 |
+
"""Returns whether the type has config."""
|
| 60 |
+
type_ = _typing_extra.annotated_type(type_) or type_
|
| 61 |
+
try:
|
| 62 |
+
return issubclass(type_, BaseModel) or is_dataclass(type_) or is_typeddict(type_)
|
| 63 |
+
except TypeError:
|
| 64 |
+
# type is not a class
|
| 65 |
+
return False
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@final
|
| 69 |
+
class TypeAdapter(Generic[T]):
|
| 70 |
+
"""Usage docs: https://docs.pydantic.dev/2.10/concepts/type_adapter/
|
| 71 |
+
|
| 72 |
+
Type adapters provide a flexible way to perform validation and serialization based on a Python type.
|
| 73 |
+
|
| 74 |
+
A `TypeAdapter` instance exposes some of the functionality from `BaseModel` instance methods
|
| 75 |
+
for types that do not have such methods (such as dataclasses, primitive types, and more).
|
| 76 |
+
|
| 77 |
+
**Note:** `TypeAdapter` instances are not types, and cannot be used as type annotations for fields.
|
| 78 |
+
|
| 79 |
+
Args:
|
| 80 |
+
type: The type associated with the `TypeAdapter`.
|
| 81 |
+
config: Configuration for the `TypeAdapter`, should be a dictionary conforming to
|
| 82 |
+
[`ConfigDict`][pydantic.config.ConfigDict].
|
| 83 |
+
|
| 84 |
+
!!! note
|
| 85 |
+
You cannot provide a configuration when instantiating a `TypeAdapter` if the type you're using
|
| 86 |
+
has its own config that cannot be overridden (ex: `BaseModel`, `TypedDict`, and `dataclass`). A
|
| 87 |
+
[`type-adapter-config-unused`](../errors/usage_errors.md#type-adapter-config-unused) error will
|
| 88 |
+
be raised in this case.
|
| 89 |
+
_parent_depth: Depth at which to search for the [parent frame][frame-objects]. This frame is used when
|
| 90 |
+
resolving forward annotations during schema building, by looking for the globals and locals of this
|
| 91 |
+
frame. Defaults to 2, which will result in the frame where the `TypeAdapter` was instantiated.
|
| 92 |
+
|
| 93 |
+
!!! note
|
| 94 |
+
This parameter is named with an underscore to suggest its private nature and discourage use.
|
| 95 |
+
It may be deprecated in a minor version, so we only recommend using it if you're comfortable
|
| 96 |
+
with potential change in behavior/support. It's default value is 2 because internally,
|
| 97 |
+
the `TypeAdapter` class makes another call to fetch the frame.
|
| 98 |
+
module: The module that passes to plugin if provided.
|
| 99 |
+
|
| 100 |
+
Attributes:
|
| 101 |
+
core_schema: The core schema for the type.
|
| 102 |
+
validator: The schema validator for the type.
|
| 103 |
+
serializer: The schema serializer for the type.
|
| 104 |
+
pydantic_complete: Whether the core schema for the type is successfully built.
|
| 105 |
+
|
| 106 |
+
??? tip "Compatibility with `mypy`"
|
| 107 |
+
Depending on the type used, `mypy` might raise an error when instantiating a `TypeAdapter`. As a workaround, you can explicitly
|
| 108 |
+
annotate your variable:
|
| 109 |
+
|
| 110 |
+
```py
|
| 111 |
+
from typing import Union
|
| 112 |
+
|
| 113 |
+
from pydantic import TypeAdapter
|
| 114 |
+
|
| 115 |
+
ta: TypeAdapter[Union[str, int]] = TypeAdapter(Union[str, int]) # type: ignore[arg-type]
|
| 116 |
+
```
|
| 117 |
+
|
| 118 |
+
??? info "Namespace management nuances and implementation details"
|
| 119 |
+
|
| 120 |
+
Here, we collect some notes on namespace management, and subtle differences from `BaseModel`:
|
| 121 |
+
|
| 122 |
+
`BaseModel` uses its own `__module__` to find out where it was defined
|
| 123 |
+
and then looks for symbols to resolve forward references in those globals.
|
| 124 |
+
On the other hand, `TypeAdapter` can be initialized with arbitrary objects,
|
| 125 |
+
which may not be types and thus do not have a `__module__` available.
|
| 126 |
+
So instead we look at the globals in our parent stack frame.
|
| 127 |
+
|
| 128 |
+
It is expected that the `ns_resolver` passed to this function will have the correct
|
| 129 |
+
namespace for the type we're adapting. See the source code for `TypeAdapter.__init__`
|
| 130 |
+
and `TypeAdapter.rebuild` for various ways to construct this namespace.
|
| 131 |
+
|
| 132 |
+
This works for the case where this function is called in a module that
|
| 133 |
+
has the target of forward references in its scope, but
|
| 134 |
+
does not always work for more complex cases.
|
| 135 |
+
|
| 136 |
+
For example, take the following:
|
| 137 |
+
|
| 138 |
+
```python {title="a.py"}
|
| 139 |
+
from typing import Dict, List
|
| 140 |
+
|
| 141 |
+
IntList = List[int]
|
| 142 |
+
OuterDict = Dict[str, 'IntList']
|
| 143 |
+
```
|
| 144 |
+
|
| 145 |
+
```python {test="skip" title="b.py"}
|
| 146 |
+
from a import OuterDict
|
| 147 |
+
|
| 148 |
+
from pydantic import TypeAdapter
|
| 149 |
+
|
| 150 |
+
IntList = int # replaces the symbol the forward reference is looking for
|
| 151 |
+
v = TypeAdapter(OuterDict)
|
| 152 |
+
v({'x': 1}) # should fail but doesn't
|
| 153 |
+
```
|
| 154 |
+
|
| 155 |
+
If `OuterDict` were a `BaseModel`, this would work because it would resolve
|
| 156 |
+
the forward reference within the `a.py` namespace.
|
| 157 |
+
But `TypeAdapter(OuterDict)` can't determine what module `OuterDict` came from.
|
| 158 |
+
|
| 159 |
+
In other words, the assumption that _all_ forward references exist in the
|
| 160 |
+
module we are being called from is not technically always true.
|
| 161 |
+
Although most of the time it is and it works fine for recursive models and such,
|
| 162 |
+
`BaseModel`'s behavior isn't perfect either and _can_ break in similar ways,
|
| 163 |
+
so there is no right or wrong between the two.
|
| 164 |
+
|
| 165 |
+
But at the very least this behavior is _subtly_ different from `BaseModel`'s.
|
| 166 |
+
"""
|
| 167 |
+
|
| 168 |
+
core_schema: CoreSchema
|
| 169 |
+
validator: SchemaValidator | PluggableSchemaValidator
|
| 170 |
+
serializer: SchemaSerializer
|
| 171 |
+
pydantic_complete: bool
|
| 172 |
+
|
| 173 |
+
@overload
|
| 174 |
+
def __init__(
|
| 175 |
+
self,
|
| 176 |
+
type: type[T],
|
| 177 |
+
*,
|
| 178 |
+
config: ConfigDict | None = ...,
|
| 179 |
+
_parent_depth: int = ...,
|
| 180 |
+
module: str | None = ...,
|
| 181 |
+
) -> None: ...
|
| 182 |
+
|
| 183 |
+
# This second overload is for unsupported special forms (such as Annotated, Union, etc.)
|
| 184 |
+
# Currently there is no way to type this correctly
|
| 185 |
+
# See https://github.com/python/typing/pull/1618
|
| 186 |
+
@overload
|
| 187 |
+
def __init__(
|
| 188 |
+
self,
|
| 189 |
+
type: Any,
|
| 190 |
+
*,
|
| 191 |
+
config: ConfigDict | None = ...,
|
| 192 |
+
_parent_depth: int = ...,
|
| 193 |
+
module: str | None = ...,
|
| 194 |
+
) -> None: ...
|
| 195 |
+
|
| 196 |
+
def __init__(
|
| 197 |
+
self,
|
| 198 |
+
type: Any,
|
| 199 |
+
*,
|
| 200 |
+
config: ConfigDict | None = None,
|
| 201 |
+
_parent_depth: int = 2,
|
| 202 |
+
module: str | None = None,
|
| 203 |
+
) -> None:
|
| 204 |
+
if _type_has_config(type) and config is not None:
|
| 205 |
+
raise PydanticUserError(
|
| 206 |
+
'Cannot use `config` when the type is a BaseModel, dataclass or TypedDict.'
|
| 207 |
+
' These types can have their own config and setting the config via the `config`'
|
| 208 |
+
' parameter to TypeAdapter will not override it, thus the `config` you passed to'
|
| 209 |
+
' TypeAdapter becomes meaningless, which is probably not what you want.',
|
| 210 |
+
code='type-adapter-config-unused',
|
| 211 |
+
)
|
| 212 |
+
|
| 213 |
+
self._type = type
|
| 214 |
+
self._config = config
|
| 215 |
+
self._parent_depth = _parent_depth
|
| 216 |
+
self.pydantic_complete = False
|
| 217 |
+
|
| 218 |
+
parent_frame = self._fetch_parent_frame()
|
| 219 |
+
if parent_frame is not None:
|
| 220 |
+
globalns = parent_frame.f_globals
|
| 221 |
+
# Do not provide a local ns if the type adapter happens to be instantiated at the module level:
|
| 222 |
+
localns = parent_frame.f_locals if parent_frame.f_locals is not globalns else {}
|
| 223 |
+
else:
|
| 224 |
+
globalns = {}
|
| 225 |
+
localns = {}
|
| 226 |
+
|
| 227 |
+
self._module_name = module or cast(str, globalns.get('__name__', ''))
|
| 228 |
+
self._init_core_attrs(
|
| 229 |
+
ns_resolver=_namespace_utils.NsResolver(
|
| 230 |
+
namespaces_tuple=_namespace_utils.NamespacesTuple(locals=localns, globals=globalns),
|
| 231 |
+
parent_namespace=localns,
|
| 232 |
+
),
|
| 233 |
+
force=False,
|
| 234 |
+
)
|
| 235 |
+
|
| 236 |
+
def _fetch_parent_frame(self) -> FrameType | None:
|
| 237 |
+
frame = sys._getframe(self._parent_depth)
|
| 238 |
+
if frame.f_globals.get('__name__') == 'typing':
|
| 239 |
+
# Because `TypeAdapter` is generic, explicitly parametrizing the class results
|
| 240 |
+
# in a `typing._GenericAlias` instance, which proxies instantiation calls to the
|
| 241 |
+
# "real" `TypeAdapter` class and thus adding an extra frame to the call. To avoid
|
| 242 |
+
# pulling anything from the `typing` module, use the correct frame (the one before):
|
| 243 |
+
return frame.f_back
|
| 244 |
+
|
| 245 |
+
return frame
|
| 246 |
+
|
| 247 |
+
def _init_core_attrs(
|
| 248 |
+
self, ns_resolver: _namespace_utils.NsResolver, force: bool, raise_errors: bool = False
|
| 249 |
+
) -> bool:
|
| 250 |
+
"""Initialize the core schema, validator, and serializer for the type.
|
| 251 |
+
|
| 252 |
+
Args:
|
| 253 |
+
ns_resolver: The namespace resolver to use when building the core schema for the adapted type.
|
| 254 |
+
force: Whether to force the construction of the core schema, validator, and serializer.
|
| 255 |
+
If `force` is set to `False` and `_defer_build` is `True`, the core schema, validator, and serializer will be set to mocks.
|
| 256 |
+
raise_errors: Whether to raise errors if initializing any of the core attrs fails.
|
| 257 |
+
|
| 258 |
+
Returns:
|
| 259 |
+
`True` if the core schema, validator, and serializer were successfully initialized, otherwise `False`.
|
| 260 |
+
|
| 261 |
+
Raises:
|
| 262 |
+
PydanticUndefinedAnnotation: If `PydanticUndefinedAnnotation` occurs in`__get_pydantic_core_schema__`
|
| 263 |
+
and `raise_errors=True`.
|
| 264 |
+
"""
|
| 265 |
+
if not force and self._defer_build:
|
| 266 |
+
_mock_val_ser.set_type_adapter_mocks(self, str(self._type))
|
| 267 |
+
self.pydantic_complete = False
|
| 268 |
+
return False
|
| 269 |
+
|
| 270 |
+
try:
|
| 271 |
+
self.core_schema = _getattr_no_parents(self._type, '__pydantic_core_schema__')
|
| 272 |
+
self.validator = _getattr_no_parents(self._type, '__pydantic_validator__')
|
| 273 |
+
self.serializer = _getattr_no_parents(self._type, '__pydantic_serializer__')
|
| 274 |
+
|
| 275 |
+
# TODO: we don't go through the rebuild logic here directly because we don't want
|
| 276 |
+
# to repeat all of the namespace fetching logic that we've already done
|
| 277 |
+
# so we simply skip to the block below that does the actual schema generation
|
| 278 |
+
if (
|
| 279 |
+
isinstance(self.core_schema, _mock_val_ser.MockCoreSchema)
|
| 280 |
+
or isinstance(self.validator, _mock_val_ser.MockValSer)
|
| 281 |
+
or isinstance(self.serializer, _mock_val_ser.MockValSer)
|
| 282 |
+
):
|
| 283 |
+
raise AttributeError()
|
| 284 |
+
except AttributeError:
|
| 285 |
+
config_wrapper = _config.ConfigWrapper(self._config)
|
| 286 |
+
|
| 287 |
+
schema_generator = _generate_schema.GenerateSchema(config_wrapper, ns_resolver=ns_resolver)
|
| 288 |
+
|
| 289 |
+
try:
|
| 290 |
+
core_schema = schema_generator.generate_schema(self._type)
|
| 291 |
+
except PydanticUndefinedAnnotation:
|
| 292 |
+
if raise_errors:
|
| 293 |
+
raise
|
| 294 |
+
_mock_val_ser.set_type_adapter_mocks(self, str(self._type))
|
| 295 |
+
return False
|
| 296 |
+
|
| 297 |
+
try:
|
| 298 |
+
self.core_schema = schema_generator.clean_schema(core_schema)
|
| 299 |
+
except schema_generator.CollectedInvalid:
|
| 300 |
+
_mock_val_ser.set_type_adapter_mocks(self, str(self._type))
|
| 301 |
+
return False
|
| 302 |
+
|
| 303 |
+
core_config = config_wrapper.core_config(None)
|
| 304 |
+
|
| 305 |
+
self.validator = create_schema_validator(
|
| 306 |
+
schema=self.core_schema,
|
| 307 |
+
schema_type=self._type,
|
| 308 |
+
schema_type_module=self._module_name,
|
| 309 |
+
schema_type_name=str(self._type),
|
| 310 |
+
schema_kind='TypeAdapter',
|
| 311 |
+
config=core_config,
|
| 312 |
+
plugin_settings=config_wrapper.plugin_settings,
|
| 313 |
+
)
|
| 314 |
+
self.serializer = SchemaSerializer(self.core_schema, core_config)
|
| 315 |
+
|
| 316 |
+
self.pydantic_complete = True
|
| 317 |
+
return True
|
| 318 |
+
|
| 319 |
+
@property
|
| 320 |
+
def _defer_build(self) -> bool:
|
| 321 |
+
config = self._config if self._config is not None else self._model_config
|
| 322 |
+
if config:
|
| 323 |
+
return config.get('defer_build') is True
|
| 324 |
+
return False
|
| 325 |
+
|
| 326 |
+
@property
|
| 327 |
+
def _model_config(self) -> ConfigDict | None:
|
| 328 |
+
type_: Any = _typing_extra.annotated_type(self._type) or self._type # Eg FastAPI heavily uses Annotated
|
| 329 |
+
if _utils.lenient_issubclass(type_, BaseModel):
|
| 330 |
+
return type_.model_config
|
| 331 |
+
return getattr(type_, '__pydantic_config__', None)
|
| 332 |
+
|
| 333 |
+
def __repr__(self) -> str:
|
| 334 |
+
return f'TypeAdapter({_repr.display_as_type(self._type)})'
|
| 335 |
+
|
| 336 |
+
def rebuild(
|
| 337 |
+
self,
|
| 338 |
+
*,
|
| 339 |
+
force: bool = False,
|
| 340 |
+
raise_errors: bool = True,
|
| 341 |
+
_parent_namespace_depth: int = 2,
|
| 342 |
+
_types_namespace: _namespace_utils.MappingNamespace | None = None,
|
| 343 |
+
) -> bool | None:
|
| 344 |
+
"""Try to rebuild the pydantic-core schema for the adapter's type.
|
| 345 |
+
|
| 346 |
+
This may be necessary when one of the annotations is a ForwardRef which could not be resolved during
|
| 347 |
+
the initial attempt to build the schema, and automatic rebuilding fails.
|
| 348 |
+
|
| 349 |
+
Args:
|
| 350 |
+
force: Whether to force the rebuilding of the type adapter's schema, defaults to `False`.
|
| 351 |
+
raise_errors: Whether to raise errors, defaults to `True`.
|
| 352 |
+
_parent_namespace_depth: Depth at which to search for the [parent frame][frame-objects]. This
|
| 353 |
+
frame is used when resolving forward annotations during schema rebuilding, by looking for
|
| 354 |
+
the locals of this frame. Defaults to 2, which will result in the frame where the method
|
| 355 |
+
was called.
|
| 356 |
+
_types_namespace: An explicit types namespace to use, instead of using the local namespace
|
| 357 |
+
from the parent frame. Defaults to `None`.
|
| 358 |
+
|
| 359 |
+
Returns:
|
| 360 |
+
Returns `None` if the schema is already "complete" and rebuilding was not required.
|
| 361 |
+
If rebuilding _was_ required, returns `True` if rebuilding was successful, otherwise `False`.
|
| 362 |
+
"""
|
| 363 |
+
if not force and self.pydantic_complete:
|
| 364 |
+
return None
|
| 365 |
+
|
| 366 |
+
if _types_namespace is not None:
|
| 367 |
+
rebuild_ns = _types_namespace
|
| 368 |
+
elif _parent_namespace_depth > 0:
|
| 369 |
+
rebuild_ns = _typing_extra.parent_frame_namespace(parent_depth=_parent_namespace_depth, force=True) or {}
|
| 370 |
+
else:
|
| 371 |
+
rebuild_ns = {}
|
| 372 |
+
|
| 373 |
+
# we have to manually fetch globals here because there's no type on the stack of the NsResolver
|
| 374 |
+
# and so we skip the globalns = get_module_ns_of(typ) call that would normally happen
|
| 375 |
+
globalns = sys._getframe(max(_parent_namespace_depth - 1, 1)).f_globals
|
| 376 |
+
ns_resolver = _namespace_utils.NsResolver(
|
| 377 |
+
namespaces_tuple=_namespace_utils.NamespacesTuple(locals=rebuild_ns, globals=globalns),
|
| 378 |
+
parent_namespace=rebuild_ns,
|
| 379 |
+
)
|
| 380 |
+
return self._init_core_attrs(ns_resolver=ns_resolver, force=True, raise_errors=raise_errors)
|
| 381 |
+
|
| 382 |
+
def validate_python(
|
| 383 |
+
self,
|
| 384 |
+
object: Any,
|
| 385 |
+
/,
|
| 386 |
+
*,
|
| 387 |
+
strict: bool | None = None,
|
| 388 |
+
from_attributes: bool | None = None,
|
| 389 |
+
context: dict[str, Any] | None = None,
|
| 390 |
+
experimental_allow_partial: bool | Literal['off', 'on', 'trailing-strings'] = False,
|
| 391 |
+
) -> T:
|
| 392 |
+
"""Validate a Python object against the model.
|
| 393 |
+
|
| 394 |
+
Args:
|
| 395 |
+
object: The Python object to validate against the model.
|
| 396 |
+
strict: Whether to strictly check types.
|
| 397 |
+
from_attributes: Whether to extract data from object attributes.
|
| 398 |
+
context: Additional context to pass to the validator.
|
| 399 |
+
experimental_allow_partial: **Experimental** whether to enable
|
| 400 |
+
[partial validation](../concepts/experimental.md#partial-validation), e.g. to process streams.
|
| 401 |
+
* False / 'off': Default behavior, no partial validation.
|
| 402 |
+
* True / 'on': Enable partial validation.
|
| 403 |
+
* 'trailing-strings': Enable partial validation and allow trailing strings in the input.
|
| 404 |
+
|
| 405 |
+
!!! note
|
| 406 |
+
When using `TypeAdapter` with a Pydantic `dataclass`, the use of the `from_attributes`
|
| 407 |
+
argument is not supported.
|
| 408 |
+
|
| 409 |
+
Returns:
|
| 410 |
+
The validated object.
|
| 411 |
+
"""
|
| 412 |
+
return self.validator.validate_python(
|
| 413 |
+
object,
|
| 414 |
+
strict=strict,
|
| 415 |
+
from_attributes=from_attributes,
|
| 416 |
+
context=context,
|
| 417 |
+
allow_partial=experimental_allow_partial,
|
| 418 |
+
)
|
| 419 |
+
|
| 420 |
+
def validate_json(
|
| 421 |
+
self,
|
| 422 |
+
data: str | bytes | bytearray,
|
| 423 |
+
/,
|
| 424 |
+
*,
|
| 425 |
+
strict: bool | None = None,
|
| 426 |
+
context: dict[str, Any] | None = None,
|
| 427 |
+
experimental_allow_partial: bool | Literal['off', 'on', 'trailing-strings'] = False,
|
| 428 |
+
) -> T:
|
| 429 |
+
"""Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-parsing
|
| 430 |
+
|
| 431 |
+
Validate a JSON string or bytes against the model.
|
| 432 |
+
|
| 433 |
+
Args:
|
| 434 |
+
data: The JSON data to validate against the model.
|
| 435 |
+
strict: Whether to strictly check types.
|
| 436 |
+
context: Additional context to use during validation.
|
| 437 |
+
experimental_allow_partial: **Experimental** whether to enable
|
| 438 |
+
[partial validation](../concepts/experimental.md#partial-validation), e.g. to process streams.
|
| 439 |
+
* False / 'off': Default behavior, no partial validation.
|
| 440 |
+
* True / 'on': Enable partial validation.
|
| 441 |
+
* 'trailing-strings': Enable partial validation and allow trailing strings in the input.
|
| 442 |
+
|
| 443 |
+
Returns:
|
| 444 |
+
The validated object.
|
| 445 |
+
"""
|
| 446 |
+
return self.validator.validate_json(
|
| 447 |
+
data, strict=strict, context=context, allow_partial=experimental_allow_partial
|
| 448 |
+
)
|
| 449 |
+
|
| 450 |
+
def validate_strings(
|
| 451 |
+
self,
|
| 452 |
+
obj: Any,
|
| 453 |
+
/,
|
| 454 |
+
*,
|
| 455 |
+
strict: bool | None = None,
|
| 456 |
+
context: dict[str, Any] | None = None,
|
| 457 |
+
experimental_allow_partial: bool | Literal['off', 'on', 'trailing-strings'] = False,
|
| 458 |
+
) -> T:
|
| 459 |
+
"""Validate object contains string data against the model.
|
| 460 |
+
|
| 461 |
+
Args:
|
| 462 |
+
obj: The object contains string data to validate.
|
| 463 |
+
strict: Whether to strictly check types.
|
| 464 |
+
context: Additional context to use during validation.
|
| 465 |
+
experimental_allow_partial: **Experimental** whether to enable
|
| 466 |
+
[partial validation](../concepts/experimental.md#partial-validation), e.g. to process streams.
|
| 467 |
+
* False / 'off': Default behavior, no partial validation.
|
| 468 |
+
* True / 'on': Enable partial validation.
|
| 469 |
+
* 'trailing-strings': Enable partial validation and allow trailing strings in the input.
|
| 470 |
+
|
| 471 |
+
Returns:
|
| 472 |
+
The validated object.
|
| 473 |
+
"""
|
| 474 |
+
return self.validator.validate_strings(
|
| 475 |
+
obj, strict=strict, context=context, allow_partial=experimental_allow_partial
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
def get_default_value(self, *, strict: bool | None = None, context: dict[str, Any] | None = None) -> Some[T] | None:
|
| 479 |
+
"""Get the default value for the wrapped type.
|
| 480 |
+
|
| 481 |
+
Args:
|
| 482 |
+
strict: Whether to strictly check types.
|
| 483 |
+
context: Additional context to pass to the validator.
|
| 484 |
+
|
| 485 |
+
Returns:
|
| 486 |
+
The default value wrapped in a `Some` if there is one or None if not.
|
| 487 |
+
"""
|
| 488 |
+
return self.validator.get_default_value(strict=strict, context=context)
|
| 489 |
+
|
| 490 |
+
def dump_python(
|
| 491 |
+
self,
|
| 492 |
+
instance: T,
|
| 493 |
+
/,
|
| 494 |
+
*,
|
| 495 |
+
mode: Literal['json', 'python'] = 'python',
|
| 496 |
+
include: IncEx | None = None,
|
| 497 |
+
exclude: IncEx | None = None,
|
| 498 |
+
by_alias: bool = False,
|
| 499 |
+
exclude_unset: bool = False,
|
| 500 |
+
exclude_defaults: bool = False,
|
| 501 |
+
exclude_none: bool = False,
|
| 502 |
+
round_trip: bool = False,
|
| 503 |
+
warnings: bool | Literal['none', 'warn', 'error'] = True,
|
| 504 |
+
serialize_as_any: bool = False,
|
| 505 |
+
context: dict[str, Any] | None = None,
|
| 506 |
+
) -> Any:
|
| 507 |
+
"""Dump an instance of the adapted type to a Python object.
|
| 508 |
+
|
| 509 |
+
Args:
|
| 510 |
+
instance: The Python object to serialize.
|
| 511 |
+
mode: The output format.
|
| 512 |
+
include: Fields to include in the output.
|
| 513 |
+
exclude: Fields to exclude from the output.
|
| 514 |
+
by_alias: Whether to use alias names for field names.
|
| 515 |
+
exclude_unset: Whether to exclude unset fields.
|
| 516 |
+
exclude_defaults: Whether to exclude fields with default values.
|
| 517 |
+
exclude_none: Whether to exclude fields with None values.
|
| 518 |
+
round_trip: Whether to output the serialized data in a way that is compatible with deserialization.
|
| 519 |
+
warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
|
| 520 |
+
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
|
| 521 |
+
serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
|
| 522 |
+
context: Additional context to pass to the serializer.
|
| 523 |
+
|
| 524 |
+
Returns:
|
| 525 |
+
The serialized object.
|
| 526 |
+
"""
|
| 527 |
+
return self.serializer.to_python(
|
| 528 |
+
instance,
|
| 529 |
+
mode=mode,
|
| 530 |
+
by_alias=by_alias,
|
| 531 |
+
include=include,
|
| 532 |
+
exclude=exclude,
|
| 533 |
+
exclude_unset=exclude_unset,
|
| 534 |
+
exclude_defaults=exclude_defaults,
|
| 535 |
+
exclude_none=exclude_none,
|
| 536 |
+
round_trip=round_trip,
|
| 537 |
+
warnings=warnings,
|
| 538 |
+
serialize_as_any=serialize_as_any,
|
| 539 |
+
context=context,
|
| 540 |
+
)
|
| 541 |
+
|
| 542 |
+
def dump_json(
|
| 543 |
+
self,
|
| 544 |
+
instance: T,
|
| 545 |
+
/,
|
| 546 |
+
*,
|
| 547 |
+
indent: int | None = None,
|
| 548 |
+
include: IncEx | None = None,
|
| 549 |
+
exclude: IncEx | None = None,
|
| 550 |
+
by_alias: bool = False,
|
| 551 |
+
exclude_unset: bool = False,
|
| 552 |
+
exclude_defaults: bool = False,
|
| 553 |
+
exclude_none: bool = False,
|
| 554 |
+
round_trip: bool = False,
|
| 555 |
+
warnings: bool | Literal['none', 'warn', 'error'] = True,
|
| 556 |
+
serialize_as_any: bool = False,
|
| 557 |
+
context: dict[str, Any] | None = None,
|
| 558 |
+
) -> bytes:
|
| 559 |
+
"""Usage docs: https://docs.pydantic.dev/2.10/concepts/json/#json-serialization
|
| 560 |
+
|
| 561 |
+
Serialize an instance of the adapted type to JSON.
|
| 562 |
+
|
| 563 |
+
Args:
|
| 564 |
+
instance: The instance to be serialized.
|
| 565 |
+
indent: Number of spaces for JSON indentation.
|
| 566 |
+
include: Fields to include.
|
| 567 |
+
exclude: Fields to exclude.
|
| 568 |
+
by_alias: Whether to use alias names for field names.
|
| 569 |
+
exclude_unset: Whether to exclude unset fields.
|
| 570 |
+
exclude_defaults: Whether to exclude fields with default values.
|
| 571 |
+
exclude_none: Whether to exclude fields with a value of `None`.
|
| 572 |
+
round_trip: Whether to serialize and deserialize the instance to ensure round-tripping.
|
| 573 |
+
warnings: How to handle serialization errors. False/"none" ignores them, True/"warn" logs errors,
|
| 574 |
+
"error" raises a [`PydanticSerializationError`][pydantic_core.PydanticSerializationError].
|
| 575 |
+
serialize_as_any: Whether to serialize fields with duck-typing serialization behavior.
|
| 576 |
+
context: Additional context to pass to the serializer.
|
| 577 |
+
|
| 578 |
+
Returns:
|
| 579 |
+
The JSON representation of the given instance as bytes.
|
| 580 |
+
"""
|
| 581 |
+
return self.serializer.to_json(
|
| 582 |
+
instance,
|
| 583 |
+
indent=indent,
|
| 584 |
+
include=include,
|
| 585 |
+
exclude=exclude,
|
| 586 |
+
by_alias=by_alias,
|
| 587 |
+
exclude_unset=exclude_unset,
|
| 588 |
+
exclude_defaults=exclude_defaults,
|
| 589 |
+
exclude_none=exclude_none,
|
| 590 |
+
round_trip=round_trip,
|
| 591 |
+
warnings=warnings,
|
| 592 |
+
serialize_as_any=serialize_as_any,
|
| 593 |
+
context=context,
|
| 594 |
+
)
|
| 595 |
+
|
| 596 |
+
def json_schema(
|
| 597 |
+
self,
|
| 598 |
+
*,
|
| 599 |
+
by_alias: bool = True,
|
| 600 |
+
ref_template: str = DEFAULT_REF_TEMPLATE,
|
| 601 |
+
schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
|
| 602 |
+
mode: JsonSchemaMode = 'validation',
|
| 603 |
+
) -> dict[str, Any]:
|
| 604 |
+
"""Generate a JSON schema for the adapted type.
|
| 605 |
+
|
| 606 |
+
Args:
|
| 607 |
+
by_alias: Whether to use alias names for field names.
|
| 608 |
+
ref_template: The format string used for generating $ref strings.
|
| 609 |
+
schema_generator: The generator class used for creating the schema.
|
| 610 |
+
mode: The mode to use for schema generation.
|
| 611 |
+
|
| 612 |
+
Returns:
|
| 613 |
+
The JSON schema for the model as a dictionary.
|
| 614 |
+
"""
|
| 615 |
+
schema_generator_instance = schema_generator(by_alias=by_alias, ref_template=ref_template)
|
| 616 |
+
if isinstance(self.core_schema, _mock_val_ser.MockCoreSchema):
|
| 617 |
+
self.core_schema.rebuild()
|
| 618 |
+
assert not isinstance(self.core_schema, _mock_val_ser.MockCoreSchema), 'this is a bug! please report it'
|
| 619 |
+
return schema_generator_instance.generate(self.core_schema, mode=mode)
|
| 620 |
+
|
| 621 |
+
@staticmethod
|
| 622 |
+
def json_schemas(
|
| 623 |
+
inputs: Iterable[tuple[JsonSchemaKeyT, JsonSchemaMode, TypeAdapter[Any]]],
|
| 624 |
+
/,
|
| 625 |
+
*,
|
| 626 |
+
by_alias: bool = True,
|
| 627 |
+
title: str | None = None,
|
| 628 |
+
description: str | None = None,
|
| 629 |
+
ref_template: str = DEFAULT_REF_TEMPLATE,
|
| 630 |
+
schema_generator: type[GenerateJsonSchema] = GenerateJsonSchema,
|
| 631 |
+
) -> tuple[dict[tuple[JsonSchemaKeyT, JsonSchemaMode], JsonSchemaValue], JsonSchemaValue]:
|
| 632 |
+
"""Generate a JSON schema including definitions from multiple type adapters.
|
| 633 |
+
|
| 634 |
+
Args:
|
| 635 |
+
inputs: Inputs to schema generation. The first two items will form the keys of the (first)
|
| 636 |
+
output mapping; the type adapters will provide the core schemas that get converted into
|
| 637 |
+
definitions in the output JSON schema.
|
| 638 |
+
by_alias: Whether to use alias names.
|
| 639 |
+
title: The title for the schema.
|
| 640 |
+
description: The description for the schema.
|
| 641 |
+
ref_template: The format string used for generating $ref strings.
|
| 642 |
+
schema_generator: The generator class used for creating the schema.
|
| 643 |
+
|
| 644 |
+
Returns:
|
| 645 |
+
A tuple where:
|
| 646 |
+
|
| 647 |
+
- The first element is a dictionary whose keys are tuples of JSON schema key type and JSON mode, and
|
| 648 |
+
whose values are the JSON schema corresponding to that pair of inputs. (These schemas may have
|
| 649 |
+
JsonRef references to definitions that are defined in the second returned element.)
|
| 650 |
+
- The second element is a JSON schema containing all definitions referenced in the first returned
|
| 651 |
+
element, along with the optional title and description keys.
|
| 652 |
+
|
| 653 |
+
"""
|
| 654 |
+
schema_generator_instance = schema_generator(by_alias=by_alias, ref_template=ref_template)
|
| 655 |
+
|
| 656 |
+
inputs_ = []
|
| 657 |
+
for key, mode, adapter in inputs:
|
| 658 |
+
# This is the same pattern we follow for model json schemas - we attempt a core schema rebuild if we detect a mock
|
| 659 |
+
if isinstance(adapter.core_schema, _mock_val_ser.MockCoreSchema):
|
| 660 |
+
adapter.core_schema.rebuild()
|
| 661 |
+
assert not isinstance(
|
| 662 |
+
adapter.core_schema, _mock_val_ser.MockCoreSchema
|
| 663 |
+
), 'this is a bug! please report it'
|
| 664 |
+
inputs_.append((key, mode, adapter.core_schema))
|
| 665 |
+
|
| 666 |
+
json_schemas_map, definitions = schema_generator_instance.generate_definitions(inputs_)
|
| 667 |
+
|
| 668 |
+
json_schema: dict[str, Any] = {}
|
| 669 |
+
if definitions:
|
| 670 |
+
json_schema['$defs'] = definitions
|
| 671 |
+
if title:
|
| 672 |
+
json_schema['title'] = title
|
| 673 |
+
if description:
|
| 674 |
+
json_schema['description'] = description
|
| 675 |
+
|
| 676 |
+
return json_schemas_map, json_schema
|
vllm/lib/python3.10/site-packages/pydantic/validators.py
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The `validators` module is a backport module from V1."""
|
| 2 |
+
|
| 3 |
+
from ._migration import getattr_migration
|
| 4 |
+
|
| 5 |
+
__getattr__ = getattr_migration(__name__)
|
vllm/lib/python3.10/site-packages/rich/__pycache__/__main__.cpython-310.pyc
ADDED
|
Binary file (7.01 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_cell_widths.cpython-310.pyc
ADDED
|
Binary file (7.83 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_emoji_replace.cpython-310.pyc
ADDED
|
Binary file (1.16 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_export_format.cpython-310.pyc
ADDED
|
Binary file (2.29 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_extension.cpython-310.pyc
ADDED
|
Binary file (437 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_fileno.cpython-310.pyc
ADDED
|
Binary file (754 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_inspect.cpython-310.pyc
ADDED
|
Binary file (8.59 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_log_render.cpython-310.pyc
ADDED
|
Binary file (2.59 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_null_file.cpython-310.pyc
ADDED
|
Binary file (3.21 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_palettes.cpython-310.pyc
ADDED
|
Binary file (5.06 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_ratio.cpython-310.pyc
ADDED
|
Binary file (5.11 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_spinners.cpython-310.pyc
ADDED
|
Binary file (12.2 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_stack.cpython-310.pyc
ADDED
|
Binary file (804 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_timer.cpython-310.pyc
ADDED
|
Binary file (653 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_win32_console.cpython-310.pyc
ADDED
|
Binary file (18.9 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_windows.cpython-310.pyc
ADDED
|
Binary file (1.73 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_windows_renderer.cpython-310.pyc
ADDED
|
Binary file (1.99 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/_wrap.cpython-310.pyc
ADDED
|
Binary file (2.44 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/abc.cpython-310.pyc
ADDED
|
Binary file (1.27 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/align.cpython-310.pyc
ADDED
|
Binary file (7.96 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/ansi.cpython-310.pyc
ADDED
|
Binary file (5.96 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/bar.cpython-310.pyc
ADDED
|
Binary file (2.95 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/box.cpython-310.pyc
ADDED
|
Binary file (8.32 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/cells.cpython-310.pyc
ADDED
|
Binary file (4.24 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/color.cpython-310.pyc
ADDED
|
Binary file (17.7 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/color_triplet.cpython-310.pyc
ADDED
|
Binary file (1.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/columns.cpython-310.pyc
ADDED
|
Binary file (6.16 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/constrain.cpython-310.pyc
ADDED
|
Binary file (1.72 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/containers.cpython-310.pyc
ADDED
|
Binary file (6.46 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/control.cpython-310.pyc
ADDED
|
Binary file (8.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/diagnose.cpython-310.pyc
ADDED
|
Binary file (1.14 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/emoji.cpython-310.pyc
ADDED
|
Binary file (3.2 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/errors.cpython-310.pyc
ADDED
|
Binary file (1.49 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/file_proxy.cpython-310.pyc
ADDED
|
Binary file (2.37 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/filesize.cpython-310.pyc
ADDED
|
Binary file (2.58 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/highlighter.cpython-310.pyc
ADDED
|
Binary file (8.03 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/jupyter.cpython-310.pyc
ADDED
|
Binary file (3.95 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/layout.cpython-310.pyc
ADDED
|
Binary file (14.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/live.cpython-310.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/logging.cpython-310.pyc
ADDED
|
Binary file (10.3 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/markdown.cpython-310.pyc
ADDED
|
Binary file (24.9 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/markup.cpython-310.pyc
ADDED
|
Binary file (6.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/measure.cpython-310.pyc
ADDED
|
Binary file (5.04 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/padding.cpython-310.pyc
ADDED
|
Binary file (4.38 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/rich/__pycache__/palette.cpython-310.pyc
ADDED
|
Binary file (3.6 kB). View file
|
|
|