Add files using upload-large-folder tool
Browse filesThis view is limited to 50 files because it contains too many changes.
See raw diff
- vllm/lib/python3.10/site-packages/wandb/vendor/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/conftest.py +30 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/setup.py +64 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/conftest.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_awaitable.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_awaitable_35.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_benchmark.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_complex_threads.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader_awaitable_35.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader_extra.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_extra.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_issues.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_thread_safety.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/conftest.py +8 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_awaitable.py +32 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py +47 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_benchmark.py +116 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_complex_threads.py +23 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader.py +452 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py +99 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py +65 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_extra.py +670 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_issues.py +132 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_promise_list.py +70 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_spec.py +584 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_thread_safety.py +115 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/utils.py +3 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__init__.py +38 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/async_.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/compat.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/dataloader.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/iterate_promise.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/promise.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/promise_list.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/utils.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/async_.py +135 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/compat.py +32 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/dataloader.py +326 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py +12 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/promise.py +848 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py +151 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__pycache__/__init__.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__pycache__/version.cpython-310.pyc +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py +83 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py +0 -0
- vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__pycache__/__init__.cpython-310.pyc +0 -0
vllm/lib/python3.10/site-packages/wandb/vendor/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (162 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/conftest.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Configuration for pytest to automatically collect types.
|
| 2 |
+
# Thanks to Guilherme Salgado.
|
| 3 |
+
import pytest
|
| 4 |
+
|
| 5 |
+
try:
|
| 6 |
+
import pyannotate_runtime
|
| 7 |
+
PYANOTATE_PRESENT = True
|
| 8 |
+
except ImportError:
|
| 9 |
+
PYANOTATE_PRESENT = False
|
| 10 |
+
|
| 11 |
+
if PYANOTATE_PRESENT:
|
| 12 |
+
def pytest_collection_finish(session):
|
| 13 |
+
"""Handle the pytest collection finish hook: configure pyannotate.
|
| 14 |
+
Explicitly delay importing `collect_types` until all tests have
|
| 15 |
+
been collected. This gives gevent a chance to monkey patch the
|
| 16 |
+
world before importing pyannotate.
|
| 17 |
+
"""
|
| 18 |
+
from pyannotate_runtime import collect_types
|
| 19 |
+
collect_types.init_types_collection()
|
| 20 |
+
|
| 21 |
+
@pytest.fixture(autouse=True)
|
| 22 |
+
def collect_types_fixture():
|
| 23 |
+
from pyannotate_runtime import collect_types
|
| 24 |
+
collect_types.resume()
|
| 25 |
+
yield
|
| 26 |
+
collect_types.pause()
|
| 27 |
+
|
| 28 |
+
def pytest_sessionfinish(session, exitstatus):
|
| 29 |
+
from pyannotate_runtime import collect_types
|
| 30 |
+
collect_types.dump_stats("type_info.json")
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/setup.py
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import sys
|
| 2 |
+
from setuptools import setup, find_packages
|
| 3 |
+
|
| 4 |
+
if sys.version_info[0] < 3:
|
| 5 |
+
import __builtin__ as builtins
|
| 6 |
+
else:
|
| 7 |
+
import builtins
|
| 8 |
+
|
| 9 |
+
builtins.__SETUP__ = True
|
| 10 |
+
|
| 11 |
+
version = __import__("promise").get_version()
|
| 12 |
+
|
| 13 |
+
|
| 14 |
+
IS_PY3 = sys.hexversion >= 0x03000000
|
| 15 |
+
|
| 16 |
+
tests_require = [
|
| 17 |
+
"pytest>=2.7.3",
|
| 18 |
+
"pytest-cov",
|
| 19 |
+
"coveralls",
|
| 20 |
+
"futures",
|
| 21 |
+
"pytest-benchmark",
|
| 22 |
+
"mock",
|
| 23 |
+
]
|
| 24 |
+
if IS_PY3:
|
| 25 |
+
tests_require += ["pytest-asyncio"]
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
setup(
|
| 29 |
+
name="promise",
|
| 30 |
+
version=version,
|
| 31 |
+
description="Promises/A+ implementation for Python",
|
| 32 |
+
long_description=open("README.rst").read(),
|
| 33 |
+
url="https://github.com/syrusakbary/promise",
|
| 34 |
+
download_url="https://github.com/syrusakbary/promise/releases",
|
| 35 |
+
author="Syrus Akbary",
|
| 36 |
+
author_email="me@syrusakbary.com",
|
| 37 |
+
license="MIT",
|
| 38 |
+
classifiers=[
|
| 39 |
+
"Development Status :: 5 - Production/Stable",
|
| 40 |
+
"Intended Audience :: Developers",
|
| 41 |
+
"Topic :: Software Development :: Libraries",
|
| 42 |
+
"Programming Language :: Python :: 2",
|
| 43 |
+
"Programming Language :: Python :: 2.7",
|
| 44 |
+
"Programming Language :: Python :: 3",
|
| 45 |
+
"Programming Language :: Python :: 3.3",
|
| 46 |
+
"Programming Language :: Python :: 3.4",
|
| 47 |
+
"Programming Language :: Python :: 3.5",
|
| 48 |
+
"Programming Language :: Python :: 3.6",
|
| 49 |
+
"Programming Language :: Python :: 3.7",
|
| 50 |
+
"Programming Language :: Python :: 3.8",
|
| 51 |
+
"Programming Language :: Python :: Implementation :: PyPy",
|
| 52 |
+
"License :: OSI Approved :: MIT License",
|
| 53 |
+
],
|
| 54 |
+
keywords="concurrent future deferred promise",
|
| 55 |
+
packages=find_packages(exclude=["tests"]),
|
| 56 |
+
# PEP-561: https://www.python.org/dev/peps/pep-0561/
|
| 57 |
+
package_data={"promise": ["py.typed"]},
|
| 58 |
+
extras_require={"test": tests_require},
|
| 59 |
+
install_requires=[
|
| 60 |
+
"typing>=3.6.4; python_version < '3.5'",
|
| 61 |
+
"six"
|
| 62 |
+
],
|
| 63 |
+
tests_require=tests_require,
|
| 64 |
+
)
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/conftest.cpython-310.pyc
ADDED
|
Binary file (433 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_awaitable.cpython-310.pyc
ADDED
|
Binary file (1.16 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_awaitable_35.cpython-310.pyc
ADDED
|
Binary file (2.01 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_benchmark.cpython-310.pyc
ADDED
|
Binary file (4.39 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_complex_threads.cpython-310.pyc
ADDED
|
Binary file (943 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader.cpython-310.pyc
ADDED
|
Binary file (11.6 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader_awaitable_35.cpython-310.pyc
ADDED
|
Binary file (2.94 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_dataloader_extra.cpython-310.pyc
ADDED
|
Binary file (195 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_extra.cpython-310.pyc
ADDED
|
Binary file (18.4 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_issues.cpython-310.pyc
ADDED
|
Binary file (5.14 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/__pycache__/test_thread_safety.cpython-310.pyc
ADDED
|
Binary file (3.94 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/conftest.py
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from sys import version_info
|
| 2 |
+
|
| 3 |
+
collect_ignore = []
|
| 4 |
+
if version_info[:2] < (3, 4):
|
| 5 |
+
collect_ignore.append("test_awaitable.py")
|
| 6 |
+
if version_info[:2] < (3, 5):
|
| 7 |
+
collect_ignore.append("test_awaitable_35.py")
|
| 8 |
+
collect_ignore.append("test_dataloader_awaitable_35.py")
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_awaitable.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from asyncio import coroutine
|
| 2 |
+
from pytest import mark
|
| 3 |
+
from time import sleep
|
| 4 |
+
from promise import Promise
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
@mark.asyncio
|
| 8 |
+
@coroutine
|
| 9 |
+
def test_await():
|
| 10 |
+
yield from Promise.resolve(True)
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
@mark.asyncio
|
| 14 |
+
@coroutine
|
| 15 |
+
def test_await_time():
|
| 16 |
+
def resolve_or_reject(resolve, reject):
|
| 17 |
+
sleep(.1)
|
| 18 |
+
resolve(True)
|
| 19 |
+
|
| 20 |
+
p = Promise(resolve_or_reject)
|
| 21 |
+
assert p.get() is True
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
@mark.asyncio
|
| 25 |
+
@coroutine
|
| 26 |
+
def test_promise_coroutine():
|
| 27 |
+
@coroutine
|
| 28 |
+
def my_coro():
|
| 29 |
+
yield from Promise.resolve(True)
|
| 30 |
+
|
| 31 |
+
promise = Promise.resolve(my_coro())
|
| 32 |
+
assert isinstance(promise, Promise)
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_awaitable_35.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from asyncio import sleep, Future, wait, FIRST_COMPLETED
|
| 2 |
+
from pytest import mark
|
| 3 |
+
from promise import Promise, is_thenable
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
@mark.asyncio
|
| 7 |
+
async def test_await():
|
| 8 |
+
assert await Promise.resolve(True)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
@mark.asyncio
|
| 12 |
+
async def test_promisify_coroutine():
|
| 13 |
+
async def my_coroutine():
|
| 14 |
+
await sleep(.01)
|
| 15 |
+
return True
|
| 16 |
+
|
| 17 |
+
assert await Promise.resolve(my_coroutine())
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@mark.asyncio
|
| 21 |
+
async def test_coroutine_is_thenable():
|
| 22 |
+
async def my_coroutine():
|
| 23 |
+
await sleep(.01)
|
| 24 |
+
return True
|
| 25 |
+
|
| 26 |
+
assert is_thenable(my_coroutine())
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
@mark.asyncio
|
| 30 |
+
async def test_promisify_future():
|
| 31 |
+
future = Future()
|
| 32 |
+
future.set_result(True)
|
| 33 |
+
assert await Promise.resolve(future)
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
@mark.asyncio
|
| 37 |
+
async def test_await_in_safe_promise():
|
| 38 |
+
async def inner():
|
| 39 |
+
@Promise.safe
|
| 40 |
+
def x():
|
| 41 |
+
promise = Promise.resolve(True).then(lambda x: x)
|
| 42 |
+
return promise
|
| 43 |
+
|
| 44 |
+
return await x()
|
| 45 |
+
|
| 46 |
+
result = await inner()
|
| 47 |
+
assert result == True
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_benchmark.py
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
import time
|
| 3 |
+
from promise import Promise, promisify, is_thenable
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def test_benchmark_promise_creation(benchmark):
|
| 7 |
+
@benchmark
|
| 8 |
+
def create_promise(): # unnecessary function call
|
| 9 |
+
p = Promise()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
def test_benchmark_promise_resolve(benchmark):
|
| 13 |
+
def create_promise():
|
| 14 |
+
return Promise.resolve(True)
|
| 15 |
+
|
| 16 |
+
result = benchmark(create_promise).get()
|
| 17 |
+
assert result == True
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_benchmark_is_thenable_basic_type(benchmark):
|
| 21 |
+
def create_promise():
|
| 22 |
+
return is_thenable(True)
|
| 23 |
+
|
| 24 |
+
result = benchmark(create_promise)
|
| 25 |
+
assert result == False
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def test_benchmark_is_thenable_custom_type(benchmark):
|
| 29 |
+
class MyType(object):
|
| 30 |
+
pass
|
| 31 |
+
|
| 32 |
+
my_type_instance = MyType()
|
| 33 |
+
|
| 34 |
+
def create_promise():
|
| 35 |
+
return is_thenable(my_type_instance)
|
| 36 |
+
|
| 37 |
+
result = benchmark(create_promise)
|
| 38 |
+
assert result == False
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def test_benchmark_promise_creation_with_resolve(benchmark):
|
| 42 |
+
do_resolve = lambda resolve, reject: resolve(True)
|
| 43 |
+
|
| 44 |
+
def create_promise(): # unnecessary function call
|
| 45 |
+
p = Promise(do_resolve)
|
| 46 |
+
# p._wait()
|
| 47 |
+
return p
|
| 48 |
+
|
| 49 |
+
result = benchmark(create_promise).get()
|
| 50 |
+
assert result == True
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def test_benchmark_promise_creation_with_reject(benchmark):
|
| 54 |
+
do_resolve = lambda resolve, reject: reject(Exception("Error"))
|
| 55 |
+
|
| 56 |
+
def create_promise(): # unnecessary function call
|
| 57 |
+
p = Promise(do_resolve)
|
| 58 |
+
# p._wait()
|
| 59 |
+
return p
|
| 60 |
+
|
| 61 |
+
with raises(Exception) as exc_info:
|
| 62 |
+
result = benchmark(create_promise).get()
|
| 63 |
+
|
| 64 |
+
assert str(exc_info.value) == "Error"
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
# def test_benchmark_promisify_promise(benchmark):
|
| 68 |
+
# instance = Promise()
|
| 69 |
+
|
| 70 |
+
# def create_promise(): # unnecessary function call
|
| 71 |
+
# return promisify(instance)
|
| 72 |
+
|
| 73 |
+
# result = benchmark(create_promise)
|
| 74 |
+
|
| 75 |
+
# assert isinstance(result, Promise)
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def test_benchmark_promisify_custom_type(benchmark):
|
| 79 |
+
class CustomThenable(object):
|
| 80 |
+
pass
|
| 81 |
+
# def then(self, resolve, reject):
|
| 82 |
+
# return resolve(True)
|
| 83 |
+
|
| 84 |
+
instance = CustomThenable()
|
| 85 |
+
|
| 86 |
+
def create_promise(): # unnecessary function call
|
| 87 |
+
return Promise.resolve(instance)
|
| 88 |
+
|
| 89 |
+
result = benchmark(create_promise)
|
| 90 |
+
|
| 91 |
+
assert isinstance(result, Promise)
|
| 92 |
+
assert result.get() == instance
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
def test_benchmark_promise_all(benchmark):
|
| 96 |
+
values = range(1000)
|
| 97 |
+
|
| 98 |
+
def create_promise(): # unnecessary function call
|
| 99 |
+
return Promise.all(values)
|
| 100 |
+
|
| 101 |
+
result = benchmark(create_promise)
|
| 102 |
+
|
| 103 |
+
assert isinstance(result, Promise)
|
| 104 |
+
assert result.get() == list(range(1000))
|
| 105 |
+
|
| 106 |
+
|
| 107 |
+
def test_benchmark_promise_all_promise(benchmark):
|
| 108 |
+
values = [Promise.resolve(i) for i in range(100000)]
|
| 109 |
+
|
| 110 |
+
def create_promise(): # unnecessary function call
|
| 111 |
+
return Promise.all(values)
|
| 112 |
+
|
| 113 |
+
result = benchmark(create_promise)
|
| 114 |
+
|
| 115 |
+
assert isinstance(result, Promise)
|
| 116 |
+
assert result.get() == list(range(100000))
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_complex_threads.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from time import sleep
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 3 |
+
from promise import Promise
|
| 4 |
+
from operator import mul
|
| 5 |
+
|
| 6 |
+
executor = ThreadPoolExecutor(max_workers=40000)
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
def promise_factorial(n):
|
| 10 |
+
if n < 2:
|
| 11 |
+
return 1
|
| 12 |
+
sleep(.02)
|
| 13 |
+
a = executor.submit(promise_factorial, n - 1)
|
| 14 |
+
|
| 15 |
+
def promise_then(r):
|
| 16 |
+
return mul(r, n)
|
| 17 |
+
|
| 18 |
+
return Promise.resolve(a).then(promise_then)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def test_factorial():
|
| 22 |
+
p = promise_factorial(10)
|
| 23 |
+
assert p.get() == 3628800
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader.py
ADDED
|
@@ -0,0 +1,452 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
|
| 3 |
+
from promise import Promise, async_instance
|
| 4 |
+
from promise.dataloader import DataLoader
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def id_loader(**options):
|
| 8 |
+
load_calls = []
|
| 9 |
+
|
| 10 |
+
resolve = options.pop("resolve", Promise.resolve)
|
| 11 |
+
|
| 12 |
+
def fn(keys):
|
| 13 |
+
load_calls.append(keys)
|
| 14 |
+
return resolve(keys)
|
| 15 |
+
|
| 16 |
+
identity_loader = DataLoader(fn, **options)
|
| 17 |
+
return identity_loader, load_calls
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
def test_build_a_simple_data_loader():
|
| 21 |
+
def call_fn(keys):
|
| 22 |
+
return Promise.resolve(keys)
|
| 23 |
+
|
| 24 |
+
identity_loader = DataLoader(call_fn)
|
| 25 |
+
|
| 26 |
+
promise1 = identity_loader.load(1)
|
| 27 |
+
assert isinstance(promise1, Promise)
|
| 28 |
+
|
| 29 |
+
value1 = promise1.get()
|
| 30 |
+
assert value1 == 1
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def test_supports_loading_multiple_keys_in_one_call():
|
| 34 |
+
def call_fn(keys):
|
| 35 |
+
return Promise.resolve(keys)
|
| 36 |
+
|
| 37 |
+
identity_loader = DataLoader(call_fn)
|
| 38 |
+
|
| 39 |
+
promise_all = identity_loader.load_many([1, 2])
|
| 40 |
+
assert isinstance(promise_all, Promise)
|
| 41 |
+
|
| 42 |
+
values = promise_all.get()
|
| 43 |
+
assert values == [1, 2]
|
| 44 |
+
|
| 45 |
+
promise_all = identity_loader.load_many([])
|
| 46 |
+
assert isinstance(promise_all, Promise)
|
| 47 |
+
|
| 48 |
+
values = promise_all.get()
|
| 49 |
+
assert values == []
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def test_batches_multiple_requests():
|
| 53 |
+
@Promise.safe
|
| 54 |
+
def do():
|
| 55 |
+
identity_loader, load_calls = id_loader()
|
| 56 |
+
|
| 57 |
+
promise1 = identity_loader.load(1)
|
| 58 |
+
promise2 = identity_loader.load(2)
|
| 59 |
+
|
| 60 |
+
p = Promise.all([promise1, promise2])
|
| 61 |
+
|
| 62 |
+
value1, value2 = p.get()
|
| 63 |
+
|
| 64 |
+
assert value1 == 1
|
| 65 |
+
assert value2 == 2
|
| 66 |
+
|
| 67 |
+
assert load_calls == [[1, 2]]
|
| 68 |
+
|
| 69 |
+
do().get()
|
| 70 |
+
|
| 71 |
+
|
| 72 |
+
def test_batches_multiple_requests_with_max_batch_sizes():
|
| 73 |
+
@Promise.safe
|
| 74 |
+
def do():
|
| 75 |
+
identity_loader, load_calls = id_loader(max_batch_size=2)
|
| 76 |
+
|
| 77 |
+
promise1 = identity_loader.load(1)
|
| 78 |
+
promise2 = identity_loader.load(2)
|
| 79 |
+
promise3 = identity_loader.load(3)
|
| 80 |
+
|
| 81 |
+
p = Promise.all([promise1, promise2, promise3])
|
| 82 |
+
|
| 83 |
+
value1, value2, value3 = p.get()
|
| 84 |
+
|
| 85 |
+
assert value1 == 1
|
| 86 |
+
assert value2 == 2
|
| 87 |
+
assert value3 == 3
|
| 88 |
+
|
| 89 |
+
assert load_calls == [[1, 2], [3]]
|
| 90 |
+
|
| 91 |
+
do().get()
|
| 92 |
+
|
| 93 |
+
|
| 94 |
+
def test_coalesces_identical_requests():
|
| 95 |
+
@Promise.safe
|
| 96 |
+
def do():
|
| 97 |
+
identity_loader, load_calls = id_loader()
|
| 98 |
+
|
| 99 |
+
promise1 = identity_loader.load(1)
|
| 100 |
+
promise2 = identity_loader.load(1)
|
| 101 |
+
|
| 102 |
+
assert promise1 == promise2
|
| 103 |
+
p = Promise.all([promise1, promise2])
|
| 104 |
+
|
| 105 |
+
value1, value2 = p.get()
|
| 106 |
+
|
| 107 |
+
assert value1 == 1
|
| 108 |
+
assert value2 == 1
|
| 109 |
+
|
| 110 |
+
assert load_calls == [[1]]
|
| 111 |
+
|
| 112 |
+
do().get()
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_caches_repeated_requests():
|
| 116 |
+
@Promise.safe
|
| 117 |
+
def do():
|
| 118 |
+
identity_loader, load_calls = id_loader()
|
| 119 |
+
|
| 120 |
+
a, b = Promise.all([identity_loader.load("A"), identity_loader.load("B")]).get()
|
| 121 |
+
|
| 122 |
+
assert a == "A"
|
| 123 |
+
assert b == "B"
|
| 124 |
+
|
| 125 |
+
assert load_calls == [["A", "B"]]
|
| 126 |
+
|
| 127 |
+
a2, c = Promise.all(
|
| 128 |
+
[identity_loader.load("A"), identity_loader.load("C")]
|
| 129 |
+
).get()
|
| 130 |
+
|
| 131 |
+
assert a2 == "A"
|
| 132 |
+
assert c == "C"
|
| 133 |
+
|
| 134 |
+
assert load_calls == [["A", "B"], ["C"]]
|
| 135 |
+
|
| 136 |
+
a3, b2, c2 = Promise.all(
|
| 137 |
+
[
|
| 138 |
+
identity_loader.load("A"),
|
| 139 |
+
identity_loader.load("B"),
|
| 140 |
+
identity_loader.load("C"),
|
| 141 |
+
]
|
| 142 |
+
).get()
|
| 143 |
+
|
| 144 |
+
assert a3 == "A"
|
| 145 |
+
assert b2 == "B"
|
| 146 |
+
assert c2 == "C"
|
| 147 |
+
|
| 148 |
+
assert load_calls == [["A", "B"], ["C"]]
|
| 149 |
+
|
| 150 |
+
do().get()
|
| 151 |
+
|
| 152 |
+
|
| 153 |
+
def test_clears_single_value_in_loader():
|
| 154 |
+
@Promise.safe
|
| 155 |
+
def do():
|
| 156 |
+
identity_loader, load_calls = id_loader()
|
| 157 |
+
|
| 158 |
+
a, b = Promise.all([identity_loader.load("A"), identity_loader.load("B")]).get()
|
| 159 |
+
|
| 160 |
+
assert a == "A"
|
| 161 |
+
assert b == "B"
|
| 162 |
+
|
| 163 |
+
assert load_calls == [["A", "B"]]
|
| 164 |
+
|
| 165 |
+
identity_loader.clear("A")
|
| 166 |
+
|
| 167 |
+
a2, b2 = Promise.all(
|
| 168 |
+
[identity_loader.load("A"), identity_loader.load("B")]
|
| 169 |
+
).get()
|
| 170 |
+
|
| 171 |
+
assert a2 == "A"
|
| 172 |
+
assert b2 == "B"
|
| 173 |
+
|
| 174 |
+
assert load_calls == [["A", "B"], ["A"]]
|
| 175 |
+
|
| 176 |
+
do().get()
|
| 177 |
+
|
| 178 |
+
|
| 179 |
+
def test_clears_all_values_in_loader():
|
| 180 |
+
@Promise.safe
|
| 181 |
+
def do():
|
| 182 |
+
identity_loader, load_calls = id_loader()
|
| 183 |
+
|
| 184 |
+
a, b = Promise.all([identity_loader.load("A"), identity_loader.load("B")]).get()
|
| 185 |
+
|
| 186 |
+
assert a == "A"
|
| 187 |
+
assert b == "B"
|
| 188 |
+
|
| 189 |
+
assert load_calls == [["A", "B"]]
|
| 190 |
+
|
| 191 |
+
identity_loader.clear_all()
|
| 192 |
+
|
| 193 |
+
a2, b2 = Promise.all(
|
| 194 |
+
[identity_loader.load("A"), identity_loader.load("B")]
|
| 195 |
+
).get()
|
| 196 |
+
|
| 197 |
+
assert a2 == "A"
|
| 198 |
+
assert b2 == "B"
|
| 199 |
+
|
| 200 |
+
assert load_calls == [["A", "B"], ["A", "B"]]
|
| 201 |
+
|
| 202 |
+
do().get()
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
def test_does_not_replace_cache_map():
|
| 206 |
+
@Promise.safe
|
| 207 |
+
def do():
|
| 208 |
+
identity_loader, _ = id_loader()
|
| 209 |
+
a, b = Promise.all([identity_loader.load("A"), identity_loader.load("B")]).get()
|
| 210 |
+
|
| 211 |
+
assert a == "A"
|
| 212 |
+
assert b == "B"
|
| 213 |
+
|
| 214 |
+
cache_map = identity_loader._promise_cache
|
| 215 |
+
|
| 216 |
+
identity_loader.clear_all()
|
| 217 |
+
|
| 218 |
+
assert id(identity_loader._promise_cache) == id(cache_map)
|
| 219 |
+
|
| 220 |
+
do().get()
|
| 221 |
+
|
| 222 |
+
|
| 223 |
+
def test_allows_priming_the_cache():
|
| 224 |
+
@Promise.safe
|
| 225 |
+
def do():
|
| 226 |
+
identity_loader, load_calls = id_loader()
|
| 227 |
+
|
| 228 |
+
identity_loader.prime("A", "A")
|
| 229 |
+
|
| 230 |
+
a, b = Promise.all([identity_loader.load("A"), identity_loader.load("B")]).get()
|
| 231 |
+
|
| 232 |
+
assert a == "A"
|
| 233 |
+
assert b == "B"
|
| 234 |
+
|
| 235 |
+
assert load_calls == [["B"]]
|
| 236 |
+
|
| 237 |
+
do().get()
|
| 238 |
+
|
| 239 |
+
|
| 240 |
+
def test_does_not_prime_keys_that_already_exist():
|
| 241 |
+
@Promise.safe
|
| 242 |
+
def do():
|
| 243 |
+
identity_loader, load_calls = id_loader()
|
| 244 |
+
|
| 245 |
+
identity_loader.prime("A", "X")
|
| 246 |
+
|
| 247 |
+
a1 = identity_loader.load("A").get()
|
| 248 |
+
b1 = identity_loader.load("B").get()
|
| 249 |
+
|
| 250 |
+
assert a1 == "X"
|
| 251 |
+
assert b1 == "B"
|
| 252 |
+
|
| 253 |
+
identity_loader.prime("A", "Y")
|
| 254 |
+
identity_loader.prime("B", "Y")
|
| 255 |
+
|
| 256 |
+
a2 = identity_loader.load("A").get()
|
| 257 |
+
b2 = identity_loader.load("B").get()
|
| 258 |
+
|
| 259 |
+
assert a2 == "X"
|
| 260 |
+
assert b2 == "B"
|
| 261 |
+
|
| 262 |
+
assert load_calls == [["B"]]
|
| 263 |
+
|
| 264 |
+
do().get()
|
| 265 |
+
|
| 266 |
+
|
| 267 |
+
# Represents Errors
|
| 268 |
+
|
| 269 |
+
|
| 270 |
+
def test_resolves_to_error_to_indicate_failure():
|
| 271 |
+
@Promise.safe
|
| 272 |
+
def do():
|
| 273 |
+
def resolve(keys):
|
| 274 |
+
mapped_keys = [
|
| 275 |
+
key if key % 2 == 0 else Exception("Odd: {}".format(key))
|
| 276 |
+
for key in keys
|
| 277 |
+
]
|
| 278 |
+
return Promise.resolve(mapped_keys)
|
| 279 |
+
|
| 280 |
+
even_loader, load_calls = id_loader(resolve=resolve)
|
| 281 |
+
|
| 282 |
+
with raises(Exception) as exc_info:
|
| 283 |
+
even_loader.load(1).get()
|
| 284 |
+
|
| 285 |
+
assert str(exc_info.value) == "Odd: 1"
|
| 286 |
+
|
| 287 |
+
value2 = even_loader.load(2).get()
|
| 288 |
+
assert value2 == 2
|
| 289 |
+
assert load_calls == [[1], [2]]
|
| 290 |
+
|
| 291 |
+
do().get()
|
| 292 |
+
|
| 293 |
+
|
| 294 |
+
def test_can_represent_failures_and_successes_simultaneously():
|
| 295 |
+
@Promise.safe
|
| 296 |
+
def do():
|
| 297 |
+
def resolve(keys):
|
| 298 |
+
mapped_keys = [
|
| 299 |
+
key if key % 2 == 0 else Exception("Odd: {}".format(key))
|
| 300 |
+
for key in keys
|
| 301 |
+
]
|
| 302 |
+
return Promise.resolve(mapped_keys)
|
| 303 |
+
|
| 304 |
+
even_loader, load_calls = id_loader(resolve=resolve)
|
| 305 |
+
|
| 306 |
+
promise1 = even_loader.load(1)
|
| 307 |
+
promise2 = even_loader.load(2)
|
| 308 |
+
|
| 309 |
+
with raises(Exception) as exc_info:
|
| 310 |
+
promise1.get()
|
| 311 |
+
|
| 312 |
+
assert str(exc_info.value) == "Odd: 1"
|
| 313 |
+
value2 = promise2.get()
|
| 314 |
+
assert value2 == 2
|
| 315 |
+
assert load_calls == [[1, 2]]
|
| 316 |
+
|
| 317 |
+
do().get()
|
| 318 |
+
|
| 319 |
+
|
| 320 |
+
def test_caches_failed_fetches():
|
| 321 |
+
@Promise.safe
|
| 322 |
+
def do():
|
| 323 |
+
def resolve(keys):
|
| 324 |
+
mapped_keys = [Exception("Error: {}".format(key)) for key in keys]
|
| 325 |
+
return Promise.resolve(mapped_keys)
|
| 326 |
+
|
| 327 |
+
error_loader, load_calls = id_loader(resolve=resolve)
|
| 328 |
+
|
| 329 |
+
with raises(Exception) as exc_info:
|
| 330 |
+
error_loader.load(1).get()
|
| 331 |
+
|
| 332 |
+
assert str(exc_info.value) == "Error: 1"
|
| 333 |
+
|
| 334 |
+
with raises(Exception) as exc_info:
|
| 335 |
+
error_loader.load(1).get()
|
| 336 |
+
|
| 337 |
+
assert str(exc_info.value) == "Error: 1"
|
| 338 |
+
|
| 339 |
+
assert load_calls == [[1]]
|
| 340 |
+
|
| 341 |
+
do().get()
|
| 342 |
+
|
| 343 |
+
|
| 344 |
+
def test_caches_failed_fetches():
|
| 345 |
+
@Promise.safe
|
| 346 |
+
def do():
|
| 347 |
+
identity_loader, load_calls = id_loader()
|
| 348 |
+
|
| 349 |
+
identity_loader.prime(1, Exception("Error: 1"))
|
| 350 |
+
|
| 351 |
+
with raises(Exception) as exc_info:
|
| 352 |
+
identity_loader.load(1).get()
|
| 353 |
+
|
| 354 |
+
assert load_calls == []
|
| 355 |
+
|
| 356 |
+
do().get()
|
| 357 |
+
|
| 358 |
+
|
| 359 |
+
# It is resilient to job queue ordering
|
| 360 |
+
# def test_batches_loads_occuring_within_promises():
|
| 361 |
+
# @Promise.safe
|
| 362 |
+
# def do():
|
| 363 |
+
# identity_loader, load_calls = id_loader()
|
| 364 |
+
# values = Promise.all([
|
| 365 |
+
# identity_loader.load('A'),
|
| 366 |
+
# Promise.resolve(None).then(lambda v: Promise.resolve(None)).then(
|
| 367 |
+
# lambda v: identity_loader.load('B')
|
| 368 |
+
# )
|
| 369 |
+
# ]).get()
|
| 370 |
+
|
| 371 |
+
# assert values == ['A', 'B']
|
| 372 |
+
# assert load_calls == [['A', 'B']]
|
| 373 |
+
|
| 374 |
+
# do().get()
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def test_catches_error_if_loader_resolver_fails():
|
| 378 |
+
@Promise.safe
|
| 379 |
+
def do():
|
| 380 |
+
def do_resolve(x):
|
| 381 |
+
raise Exception("AOH!")
|
| 382 |
+
|
| 383 |
+
a_loader, a_load_calls = id_loader(resolve=do_resolve)
|
| 384 |
+
|
| 385 |
+
with raises(Exception) as exc_info:
|
| 386 |
+
a_loader.load("A1").get()
|
| 387 |
+
|
| 388 |
+
assert str(exc_info.value) == "AOH!"
|
| 389 |
+
|
| 390 |
+
do().get()
|
| 391 |
+
|
| 392 |
+
|
| 393 |
+
def test_can_call_a_loader_from_a_loader():
|
| 394 |
+
@Promise.safe
|
| 395 |
+
def do():
|
| 396 |
+
deep_loader, deep_load_calls = id_loader()
|
| 397 |
+
a_loader, a_load_calls = id_loader(
|
| 398 |
+
resolve=lambda keys: deep_loader.load(tuple(keys))
|
| 399 |
+
)
|
| 400 |
+
b_loader, b_load_calls = id_loader(
|
| 401 |
+
resolve=lambda keys: deep_loader.load(tuple(keys))
|
| 402 |
+
)
|
| 403 |
+
|
| 404 |
+
a1, b1, a2, b2 = Promise.all(
|
| 405 |
+
[
|
| 406 |
+
a_loader.load("A1"),
|
| 407 |
+
b_loader.load("B1"),
|
| 408 |
+
a_loader.load("A2"),
|
| 409 |
+
b_loader.load("B2"),
|
| 410 |
+
]
|
| 411 |
+
).get()
|
| 412 |
+
|
| 413 |
+
assert a1 == "A1"
|
| 414 |
+
assert b1 == "B1"
|
| 415 |
+
assert a2 == "A2"
|
| 416 |
+
assert b2 == "B2"
|
| 417 |
+
|
| 418 |
+
assert a_load_calls == [["A1", "A2"]]
|
| 419 |
+
assert b_load_calls == [["B1", "B2"]]
|
| 420 |
+
assert deep_load_calls == [[("A1", "A2"), ("B1", "B2")]]
|
| 421 |
+
|
| 422 |
+
do().get()
|
| 423 |
+
|
| 424 |
+
|
| 425 |
+
def test_dataloader_clear_with_missing_key_works():
|
| 426 |
+
@Promise.safe
|
| 427 |
+
def do():
|
| 428 |
+
def do_resolve(x):
|
| 429 |
+
return x
|
| 430 |
+
|
| 431 |
+
a_loader, a_load_calls = id_loader(resolve=do_resolve)
|
| 432 |
+
assert a_loader.clear("A1") == a_loader
|
| 433 |
+
|
| 434 |
+
do().get()
|
| 435 |
+
|
| 436 |
+
|
| 437 |
+
def test_wrong_loader_return_type_does_not_block_async_instance():
|
| 438 |
+
@Promise.safe
|
| 439 |
+
def do():
|
| 440 |
+
def do_resolve(x):
|
| 441 |
+
return x
|
| 442 |
+
|
| 443 |
+
a_loader, a_load_calls = id_loader(resolve=do_resolve)
|
| 444 |
+
|
| 445 |
+
with raises(Exception):
|
| 446 |
+
a_loader.load("A1").get()
|
| 447 |
+
assert async_instance.have_drained_queues
|
| 448 |
+
with raises(Exception):
|
| 449 |
+
a_loader.load("A2").get()
|
| 450 |
+
assert async_instance.have_drained_queues
|
| 451 |
+
|
| 452 |
+
do().get()
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader_awaitable_35.py
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import mark
|
| 2 |
+
from promise import Promise
|
| 3 |
+
from promise.dataloader import DataLoader
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
def id_loader(**options):
|
| 7 |
+
load_calls = []
|
| 8 |
+
|
| 9 |
+
resolve = options.pop("resolve", Promise.resolve)
|
| 10 |
+
|
| 11 |
+
def fn(keys):
|
| 12 |
+
load_calls.append(keys)
|
| 13 |
+
return resolve(keys)
|
| 14 |
+
|
| 15 |
+
identity_loader = DataLoader(fn, **options)
|
| 16 |
+
return identity_loader, load_calls
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
@mark.asyncio
|
| 20 |
+
async def test_await_dataloader():
|
| 21 |
+
identity_loader, load_calls = id_loader()
|
| 22 |
+
|
| 23 |
+
async def load_multiple(identity_loader):
|
| 24 |
+
one = identity_loader.load("load1")
|
| 25 |
+
two = identity_loader.load("load2")
|
| 26 |
+
return await Promise.all([one, two])
|
| 27 |
+
|
| 28 |
+
result = await load_multiple(identity_loader)
|
| 29 |
+
assert result == ["load1", "load2"]
|
| 30 |
+
assert load_calls == [["load1"], ["load2"]]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
@mark.asyncio
|
| 34 |
+
async def test_await_dataloader_safe_promise():
|
| 35 |
+
identity_loader, load_calls = id_loader()
|
| 36 |
+
|
| 37 |
+
@Promise.safe
|
| 38 |
+
async def load_multiple(identity_loader):
|
| 39 |
+
one = identity_loader.load("load1")
|
| 40 |
+
two = identity_loader.load("load2")
|
| 41 |
+
return await Promise.all([one, two])
|
| 42 |
+
|
| 43 |
+
result = await load_multiple(identity_loader)
|
| 44 |
+
assert result == ["load1", "load2"]
|
| 45 |
+
assert load_calls == [["load1"], ["load2"]]
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@mark.asyncio
|
| 49 |
+
async def test_await_dataloader_individual():
|
| 50 |
+
identity_loader, load_calls = id_loader()
|
| 51 |
+
|
| 52 |
+
async def load_one_then_two(identity_loader):
|
| 53 |
+
one = await identity_loader.load("load1")
|
| 54 |
+
two = await identity_loader.load("load2")
|
| 55 |
+
return [one, two]
|
| 56 |
+
|
| 57 |
+
result = await load_one_then_two(identity_loader)
|
| 58 |
+
assert result == ["load1", "load2"]
|
| 59 |
+
assert load_calls == [["load1"], ["load2"]]
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@mark.asyncio
|
| 63 |
+
async def test_await_dataloader_individual_safe_promise():
|
| 64 |
+
identity_loader, load_calls = id_loader()
|
| 65 |
+
|
| 66 |
+
@Promise.safe
|
| 67 |
+
async def load_one_then_two(identity_loader):
|
| 68 |
+
one = await identity_loader.load("load1")
|
| 69 |
+
two = await identity_loader.load("load2")
|
| 70 |
+
return [one, two]
|
| 71 |
+
|
| 72 |
+
result = await load_one_then_two(identity_loader)
|
| 73 |
+
assert result == ["load1", "load2"]
|
| 74 |
+
assert load_calls == [["load1"], ["load2"]]
|
| 75 |
+
|
| 76 |
+
|
| 77 |
+
@mark.asyncio
|
| 78 |
+
async def test_await_dataloader_two():
|
| 79 |
+
identity_loader, load_calls = id_loader()
|
| 80 |
+
|
| 81 |
+
async def load_one_then_two(identity_loader):
|
| 82 |
+
one = await identity_loader.load("load1")
|
| 83 |
+
two = await identity_loader.load("load2")
|
| 84 |
+
return (one, two)
|
| 85 |
+
|
| 86 |
+
result12 = await Promise.all([load_one_then_two(identity_loader)])
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
@mark.asyncio
|
| 90 |
+
async def test_await_dataloader_two_safe_promise():
|
| 91 |
+
identity_loader, load_calls = id_loader()
|
| 92 |
+
|
| 93 |
+
@Promise.safe
|
| 94 |
+
async def load_one_then_two(identity_loader):
|
| 95 |
+
one = await identity_loader.load("load1")
|
| 96 |
+
two = await identity_loader.load("load2")
|
| 97 |
+
return (one, two)
|
| 98 |
+
|
| 99 |
+
result12 = await Promise.all([load_one_then_two(identity_loader)])
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_dataloader_extra.py
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# from promise import Promise
|
| 2 |
+
# from promise.dataloader import DataLoader
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
# def id_loader(**options):
|
| 6 |
+
# load_calls = []
|
| 7 |
+
|
| 8 |
+
# def fn(keys):
|
| 9 |
+
# load_calls.append(keys)
|
| 10 |
+
# return Promise.resolve(keys)
|
| 11 |
+
|
| 12 |
+
# identity_loader = DataLoader(fn, **options)
|
| 13 |
+
# return identity_loader, load_calls
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
# def test_batches_multiple_requests():
|
| 17 |
+
# identity_loader, load_calls = id_loader()
|
| 18 |
+
|
| 19 |
+
# @Promise.safe
|
| 20 |
+
# def safe():
|
| 21 |
+
# promise1 = identity_loader.load(1)
|
| 22 |
+
# promise2 = identity_loader.load(2)
|
| 23 |
+
# return promise1, promise2
|
| 24 |
+
|
| 25 |
+
# promise1, promise2 = safe()
|
| 26 |
+
# value1, value2 = Promise.all([promise1, promise2]).get()
|
| 27 |
+
# assert value1 == 1
|
| 28 |
+
# assert value2 == 2
|
| 29 |
+
|
| 30 |
+
# assert load_calls == [[1, 2]]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
# def test_batches_multiple_requests_two():
|
| 34 |
+
# identity_loader, load_calls = id_loader()
|
| 35 |
+
|
| 36 |
+
# @Promise.safe
|
| 37 |
+
# def safe():
|
| 38 |
+
# promise1 = identity_loader.load(1)
|
| 39 |
+
# promise2 = identity_loader.load(2)
|
| 40 |
+
# return Promise.all([promise1, promise2])
|
| 41 |
+
|
| 42 |
+
# p = safe()
|
| 43 |
+
# value1, value2 = p.get()
|
| 44 |
+
|
| 45 |
+
# assert value1 == 1
|
| 46 |
+
# assert value2 == 2
|
| 47 |
+
|
| 48 |
+
# assert load_calls == [[1, 2]]
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
# @Promise.safe
|
| 52 |
+
# def test_batches_multiple_requests_safe():
|
| 53 |
+
# identity_loader, load_calls = id_loader()
|
| 54 |
+
|
| 55 |
+
# promise1 = identity_loader.load(1)
|
| 56 |
+
# promise2 = identity_loader.load(2)
|
| 57 |
+
|
| 58 |
+
# p = Promise.all([promise1, promise2])
|
| 59 |
+
|
| 60 |
+
# value1, value2 = p.get()
|
| 61 |
+
|
| 62 |
+
# assert value1 == 1
|
| 63 |
+
# assert value2 == 2
|
| 64 |
+
|
| 65 |
+
# assert load_calls == [[1, 2]]
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_extra.py
ADDED
|
@@ -0,0 +1,670 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This exercises some capabilities above and beyond
|
| 2 |
+
# the Promises/A+ test suite
|
| 3 |
+
from time import sleep
|
| 4 |
+
from pytest import raises, fixture
|
| 5 |
+
|
| 6 |
+
from threading import Event
|
| 7 |
+
from promise import (
|
| 8 |
+
Promise,
|
| 9 |
+
is_thenable,
|
| 10 |
+
promisify,
|
| 11 |
+
promise_for_dict as free_promise_for_dict,
|
| 12 |
+
)
|
| 13 |
+
from concurrent.futures import Future
|
| 14 |
+
from threading import Thread
|
| 15 |
+
|
| 16 |
+
from .utils import assert_exception
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
class DelayedFulfill(Thread):
|
| 20 |
+
def __init__(self, d, p, v):
|
| 21 |
+
self.delay = d
|
| 22 |
+
self.promise = p
|
| 23 |
+
self.value = v
|
| 24 |
+
Thread.__init__(self)
|
| 25 |
+
|
| 26 |
+
def run(self):
|
| 27 |
+
sleep(self.delay)
|
| 28 |
+
self.promise.do_resolve(self.value)
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
class DelayedRejection(Thread):
|
| 32 |
+
def __init__(self, d, p, r):
|
| 33 |
+
self.delay = d
|
| 34 |
+
self.promise = p
|
| 35 |
+
self.reason = r
|
| 36 |
+
Thread.__init__(self)
|
| 37 |
+
|
| 38 |
+
def run(self):
|
| 39 |
+
sleep(self.delay)
|
| 40 |
+
self.promise.do_reject(self.reason)
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
class FakeThenPromise:
|
| 44 |
+
def __init__(self, raises=True):
|
| 45 |
+
self.raises = raises
|
| 46 |
+
|
| 47 |
+
def then(self, s=None, f=None):
|
| 48 |
+
if self.raises:
|
| 49 |
+
raise Exception("FakeThenPromise raises in 'then'")
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
def df(value, dtime):
|
| 53 |
+
p = Promise()
|
| 54 |
+
t = DelayedFulfill(dtime, p, value)
|
| 55 |
+
t.start()
|
| 56 |
+
|
| 57 |
+
return p
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
def dr(reason, dtime):
|
| 61 |
+
p = Promise()
|
| 62 |
+
t = DelayedRejection(dtime, p, reason)
|
| 63 |
+
t.start()
|
| 64 |
+
|
| 65 |
+
return p
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
# Static methods
|
| 69 |
+
def test_fulfilled():
|
| 70 |
+
p = Promise.fulfilled(4)
|
| 71 |
+
assert p.is_fulfilled
|
| 72 |
+
assert p.get() == 4
|
| 73 |
+
|
| 74 |
+
|
| 75 |
+
def test_rejected():
|
| 76 |
+
p = Promise.rejected(Exception("Static rejected"))
|
| 77 |
+
assert p.is_rejected
|
| 78 |
+
with raises(Exception) as exc_info:
|
| 79 |
+
p.get()
|
| 80 |
+
assert str(exc_info.value) == "Static rejected"
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
# Fulfill
|
| 84 |
+
def test_fulfill_self():
|
| 85 |
+
p = Promise()
|
| 86 |
+
with raises(TypeError) as excinfo:
|
| 87 |
+
p.do_resolve(p)
|
| 88 |
+
p.get()
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# Exceptions
|
| 92 |
+
def test_exceptions():
|
| 93 |
+
def throws(v):
|
| 94 |
+
assert False
|
| 95 |
+
|
| 96 |
+
p1 = Promise()
|
| 97 |
+
p1.then(throws)
|
| 98 |
+
p1.do_resolve(5)
|
| 99 |
+
|
| 100 |
+
p2 = Promise()
|
| 101 |
+
p2.catch(throws)
|
| 102 |
+
p2.do_reject(Exception())
|
| 103 |
+
|
| 104 |
+
with raises(Exception) as excinfo:
|
| 105 |
+
p2.get()
|
| 106 |
+
|
| 107 |
+
|
| 108 |
+
def test_thrown_exceptions_have_stacktrace():
|
| 109 |
+
def throws(v):
|
| 110 |
+
assert False
|
| 111 |
+
|
| 112 |
+
p3 = Promise.resolve("a").then(throws)
|
| 113 |
+
with raises(AssertionError) as assert_exc:
|
| 114 |
+
p3.get()
|
| 115 |
+
|
| 116 |
+
assert assert_exc.traceback[-1].path.strpath == __file__
|
| 117 |
+
|
| 118 |
+
|
| 119 |
+
def test_thrown_exceptions_preserve_stacktrace():
|
| 120 |
+
def throws(v):
|
| 121 |
+
assert False
|
| 122 |
+
|
| 123 |
+
def after_throws(v):
|
| 124 |
+
pass
|
| 125 |
+
|
| 126 |
+
p3 = Promise.resolve("a").then(throws).then(after_throws)
|
| 127 |
+
with raises(AssertionError) as assert_exc:
|
| 128 |
+
p3.get()
|
| 129 |
+
|
| 130 |
+
assert assert_exc.traceback[-1].path.strpath == __file__
|
| 131 |
+
|
| 132 |
+
|
| 133 |
+
# WAIT
|
| 134 |
+
# def test_wait_when():
|
| 135 |
+
# p1 = df(5, 0.01)
|
| 136 |
+
# assert p1.is_pending
|
| 137 |
+
# p1._wait()
|
| 138 |
+
# assert p1.is_fulfilled
|
| 139 |
+
|
| 140 |
+
|
| 141 |
+
def test_wait_if():
|
| 142 |
+
p1 = Promise()
|
| 143 |
+
p1.do_resolve(5)
|
| 144 |
+
p1._wait()
|
| 145 |
+
assert p1.is_fulfilled
|
| 146 |
+
|
| 147 |
+
|
| 148 |
+
# def test_wait_timeout():
|
| 149 |
+
# p1 = df(5, 0.1)
|
| 150 |
+
# assert p1.is_pending
|
| 151 |
+
# with raises(Exception) as exc_info:
|
| 152 |
+
# p1._wait(timeout=0.05)
|
| 153 |
+
# assert str(exc_info.value) == "Timeout"
|
| 154 |
+
# assert p1.is_pending
|
| 155 |
+
# p1._wait()
|
| 156 |
+
# assert p1.is_fulfilled
|
| 157 |
+
|
| 158 |
+
|
| 159 |
+
# # GET
|
| 160 |
+
# def test_get_when():
|
| 161 |
+
# p1 = df(5, 0.01)
|
| 162 |
+
# assert p1.is_pending
|
| 163 |
+
# v = p1.get()
|
| 164 |
+
# assert p1.is_fulfilled
|
| 165 |
+
# assert 5 == v
|
| 166 |
+
|
| 167 |
+
|
| 168 |
+
def test_get_if():
|
| 169 |
+
p1 = Promise()
|
| 170 |
+
p1.do_resolve(5)
|
| 171 |
+
v = p1.get()
|
| 172 |
+
assert p1.is_fulfilled
|
| 173 |
+
assert 5 == v
|
| 174 |
+
|
| 175 |
+
|
| 176 |
+
# def test_get_timeout():
|
| 177 |
+
# p1 = df(5, 0.1)
|
| 178 |
+
# assert p1.is_pending
|
| 179 |
+
# with raises(Exception) as exc_info:
|
| 180 |
+
# p1._wait(timeout=0.05)
|
| 181 |
+
# assert str(exc_info.value) == "Timeout"
|
| 182 |
+
# assert p1.is_pending
|
| 183 |
+
# v = p1.get()
|
| 184 |
+
# assert p1.is_fulfilled
|
| 185 |
+
# assert 5 == v
|
| 186 |
+
|
| 187 |
+
|
| 188 |
+
# Promise.all
|
| 189 |
+
def test_promise_all_when():
|
| 190 |
+
p1 = Promise()
|
| 191 |
+
p2 = Promise()
|
| 192 |
+
pl = Promise.all([p1, p2])
|
| 193 |
+
assert p1.is_pending
|
| 194 |
+
assert p2.is_pending
|
| 195 |
+
assert pl.is_pending
|
| 196 |
+
p1.do_resolve(5)
|
| 197 |
+
p1._wait()
|
| 198 |
+
assert p1.is_fulfilled
|
| 199 |
+
assert p2.is_pending
|
| 200 |
+
assert pl.is_pending
|
| 201 |
+
p2.do_resolve(10)
|
| 202 |
+
p2._wait()
|
| 203 |
+
pl._wait()
|
| 204 |
+
assert p1.is_fulfilled
|
| 205 |
+
assert p2.is_fulfilled
|
| 206 |
+
assert pl.is_fulfilled
|
| 207 |
+
assert 5 == p1.get()
|
| 208 |
+
assert 10 == p2.get()
|
| 209 |
+
assert 5 == pl.get()[0]
|
| 210 |
+
assert 10 == pl.get()[1]
|
| 211 |
+
|
| 212 |
+
|
| 213 |
+
def test_promise_all_when_mixed_promises():
|
| 214 |
+
p1 = Promise()
|
| 215 |
+
p2 = Promise()
|
| 216 |
+
pl = Promise.all([p1, 32, p2, False, True])
|
| 217 |
+
assert p1.is_pending
|
| 218 |
+
assert p2.is_pending
|
| 219 |
+
assert pl.is_pending
|
| 220 |
+
p1.do_resolve(5)
|
| 221 |
+
p1._wait()
|
| 222 |
+
assert p1.is_fulfilled
|
| 223 |
+
assert p2.is_pending
|
| 224 |
+
assert pl.is_pending
|
| 225 |
+
p2.do_resolve(10)
|
| 226 |
+
p2._wait()
|
| 227 |
+
pl._wait()
|
| 228 |
+
assert p1.is_fulfilled
|
| 229 |
+
assert p2.is_fulfilled
|
| 230 |
+
assert pl.is_fulfilled
|
| 231 |
+
assert 5 == p1.get()
|
| 232 |
+
assert 10 == p2.get()
|
| 233 |
+
assert pl.get() == [5, 32, 10, False, True]
|
| 234 |
+
|
| 235 |
+
|
| 236 |
+
def test_promise_all_when_if_no_promises():
|
| 237 |
+
pl = Promise.all([10, 32, False, True])
|
| 238 |
+
assert pl.get() == [10, 32, False, True]
|
| 239 |
+
|
| 240 |
+
|
| 241 |
+
def test_promise_all_if():
|
| 242 |
+
p1 = Promise()
|
| 243 |
+
p2 = Promise()
|
| 244 |
+
pd1 = Promise.all([p1, p2])
|
| 245 |
+
pd2 = Promise.all([p1])
|
| 246 |
+
pd3 = Promise.all([])
|
| 247 |
+
pd3._wait()
|
| 248 |
+
assert p1.is_pending
|
| 249 |
+
assert p2.is_pending
|
| 250 |
+
assert pd1.is_pending
|
| 251 |
+
assert pd2.is_pending
|
| 252 |
+
assert pd3.is_fulfilled
|
| 253 |
+
p1.do_resolve(5)
|
| 254 |
+
p1._wait()
|
| 255 |
+
pd2._wait()
|
| 256 |
+
assert p1.is_fulfilled
|
| 257 |
+
assert p2.is_pending
|
| 258 |
+
assert pd1.is_pending
|
| 259 |
+
assert pd2.is_fulfilled
|
| 260 |
+
p2.do_resolve(10)
|
| 261 |
+
p2._wait()
|
| 262 |
+
pd1._wait()
|
| 263 |
+
pd2._wait()
|
| 264 |
+
assert p1.is_fulfilled
|
| 265 |
+
assert p2.is_fulfilled
|
| 266 |
+
assert pd1.is_fulfilled
|
| 267 |
+
assert pd2.is_fulfilled
|
| 268 |
+
assert 5 == p1.get()
|
| 269 |
+
assert 10 == p2.get()
|
| 270 |
+
assert 5 == pd1.get()[0]
|
| 271 |
+
assert 5 == pd2.get()[0]
|
| 272 |
+
assert 10 == pd1.get()[1]
|
| 273 |
+
assert [] == pd3.get()
|
| 274 |
+
|
| 275 |
+
|
| 276 |
+
# promise_for_dict
|
| 277 |
+
@fixture(params=[Promise.for_dict, free_promise_for_dict])
|
| 278 |
+
def promise_for_dict(request):
|
| 279 |
+
return request.param
|
| 280 |
+
|
| 281 |
+
|
| 282 |
+
def test_dict_promise_when(promise_for_dict):
|
| 283 |
+
p1 = Promise()
|
| 284 |
+
p2 = Promise()
|
| 285 |
+
d = {"a": p1, "b": p2}
|
| 286 |
+
pd1 = promise_for_dict(d)
|
| 287 |
+
pd2 = promise_for_dict({"a": p1})
|
| 288 |
+
pd3 = promise_for_dict({})
|
| 289 |
+
assert p1.is_pending
|
| 290 |
+
assert p2.is_pending
|
| 291 |
+
assert pd1.is_pending
|
| 292 |
+
assert pd2.is_pending
|
| 293 |
+
pd3._wait()
|
| 294 |
+
assert pd3.is_fulfilled
|
| 295 |
+
p1.do_resolve(5)
|
| 296 |
+
p1._wait()
|
| 297 |
+
pd2._wait()
|
| 298 |
+
assert p1.is_fulfilled
|
| 299 |
+
assert p2.is_pending
|
| 300 |
+
assert pd1.is_pending
|
| 301 |
+
assert pd2.is_fulfilled
|
| 302 |
+
p2.do_resolve(10)
|
| 303 |
+
p2._wait()
|
| 304 |
+
pd1._wait()
|
| 305 |
+
assert p1.is_fulfilled
|
| 306 |
+
assert p2.is_fulfilled
|
| 307 |
+
assert pd1.is_fulfilled
|
| 308 |
+
assert pd2.is_fulfilled
|
| 309 |
+
assert 5 == p1.get()
|
| 310 |
+
assert 10 == p2.get()
|
| 311 |
+
assert 5 == pd1.get()["a"]
|
| 312 |
+
assert 5 == pd2.get()["a"]
|
| 313 |
+
assert 10 == pd1.get()["b"]
|
| 314 |
+
assert {} == pd3.get()
|
| 315 |
+
|
| 316 |
+
|
| 317 |
+
def test_dict_promise_if(promise_for_dict):
|
| 318 |
+
p1 = Promise()
|
| 319 |
+
p2 = Promise()
|
| 320 |
+
d = {"a": p1, "b": p2}
|
| 321 |
+
pd = promise_for_dict(d)
|
| 322 |
+
assert p1.is_pending
|
| 323 |
+
assert p2.is_pending
|
| 324 |
+
assert pd.is_pending
|
| 325 |
+
p1.do_resolve(5)
|
| 326 |
+
p1._wait()
|
| 327 |
+
assert p1.is_fulfilled
|
| 328 |
+
assert p2.is_pending
|
| 329 |
+
assert pd.is_pending
|
| 330 |
+
p2.do_resolve(10)
|
| 331 |
+
p2._wait()
|
| 332 |
+
assert p1.is_fulfilled
|
| 333 |
+
assert p2.is_fulfilled
|
| 334 |
+
# pd._wait()
|
| 335 |
+
# assert pd.is_fulfilled
|
| 336 |
+
# assert 5 == p1.get()
|
| 337 |
+
# assert 10 == p2.get()
|
| 338 |
+
# assert 5 == pd.get()["a"]
|
| 339 |
+
# assert 10 == pd.get()["b"]
|
| 340 |
+
|
| 341 |
+
|
| 342 |
+
def test_done():
|
| 343 |
+
counter = [0]
|
| 344 |
+
r = Promise()
|
| 345 |
+
|
| 346 |
+
def inc(_):
|
| 347 |
+
counter[0] += 1
|
| 348 |
+
|
| 349 |
+
def dec(_):
|
| 350 |
+
counter[0] -= 1
|
| 351 |
+
|
| 352 |
+
def end(_):
|
| 353 |
+
r.do_resolve(None)
|
| 354 |
+
|
| 355 |
+
p = Promise()
|
| 356 |
+
p.done(inc, dec)
|
| 357 |
+
p.done(inc, dec)
|
| 358 |
+
p.done(end)
|
| 359 |
+
p.do_resolve(4)
|
| 360 |
+
|
| 361 |
+
Promise.wait(r)
|
| 362 |
+
assert counter[0] == 2
|
| 363 |
+
|
| 364 |
+
r = Promise()
|
| 365 |
+
|
| 366 |
+
counter = [0]
|
| 367 |
+
p = Promise()
|
| 368 |
+
p.done(inc, dec)
|
| 369 |
+
p.done(inc, dec)
|
| 370 |
+
p.done(None, end)
|
| 371 |
+
p.do_reject(Exception())
|
| 372 |
+
|
| 373 |
+
Promise.wait(r)
|
| 374 |
+
assert counter[0] == -2
|
| 375 |
+
|
| 376 |
+
|
| 377 |
+
def test_done_all():
|
| 378 |
+
counter = [0]
|
| 379 |
+
|
| 380 |
+
def inc(_):
|
| 381 |
+
counter[0] += 1
|
| 382 |
+
|
| 383 |
+
def dec(_):
|
| 384 |
+
counter[0] -= 1
|
| 385 |
+
|
| 386 |
+
p = Promise()
|
| 387 |
+
r = Promise()
|
| 388 |
+
p.done_all()
|
| 389 |
+
p.done_all([(inc, dec)])
|
| 390 |
+
p.done_all(
|
| 391 |
+
[
|
| 392 |
+
(inc, dec),
|
| 393 |
+
(inc, dec),
|
| 394 |
+
{"success": inc, "failure": dec},
|
| 395 |
+
lambda _: r.do_resolve(None),
|
| 396 |
+
]
|
| 397 |
+
)
|
| 398 |
+
p.do_resolve(4)
|
| 399 |
+
Promise.wait(r)
|
| 400 |
+
assert counter[0] == 4
|
| 401 |
+
|
| 402 |
+
p = Promise()
|
| 403 |
+
r = Promise()
|
| 404 |
+
p.done_all()
|
| 405 |
+
p.done_all([inc])
|
| 406 |
+
p.done_all([(inc, dec)])
|
| 407 |
+
p.done_all(
|
| 408 |
+
[
|
| 409 |
+
(inc, dec),
|
| 410 |
+
{"success": inc, "failure": dec},
|
| 411 |
+
(None, lambda _: r.do_resolve(None)),
|
| 412 |
+
]
|
| 413 |
+
)
|
| 414 |
+
p.do_reject(Exception("Uh oh!"))
|
| 415 |
+
Promise.wait(r)
|
| 416 |
+
assert counter[0] == 1
|
| 417 |
+
|
| 418 |
+
|
| 419 |
+
def test_then_all():
|
| 420 |
+
p = Promise()
|
| 421 |
+
|
| 422 |
+
handlers = [
|
| 423 |
+
((lambda x: x * x), (lambda r: 1)),
|
| 424 |
+
{"success": (lambda x: x + x), "failure": (lambda r: 2)},
|
| 425 |
+
]
|
| 426 |
+
|
| 427 |
+
results = (
|
| 428 |
+
p.then_all()
|
| 429 |
+
+ p.then_all([lambda x: x])
|
| 430 |
+
+ p.then_all([(lambda x: x * x, lambda r: 1)])
|
| 431 |
+
+ p.then_all(handlers)
|
| 432 |
+
)
|
| 433 |
+
|
| 434 |
+
p.do_resolve(4)
|
| 435 |
+
|
| 436 |
+
assert [r.get() for r in results] == [4, 16, 16, 8]
|
| 437 |
+
|
| 438 |
+
p = Promise()
|
| 439 |
+
|
| 440 |
+
handlers = [
|
| 441 |
+
((lambda x: x * x), (lambda r: 1)),
|
| 442 |
+
{"success": (lambda x: x + x), "failure": (lambda r: 2)},
|
| 443 |
+
]
|
| 444 |
+
|
| 445 |
+
results = (
|
| 446 |
+
p.then_all()
|
| 447 |
+
+ p.then_all([(lambda x: x * x, lambda r: 1)])
|
| 448 |
+
+ p.then_all(handlers)
|
| 449 |
+
)
|
| 450 |
+
|
| 451 |
+
p.do_reject(Exception())
|
| 452 |
+
|
| 453 |
+
assert [r.get() for r in results] == [1, 1, 2]
|
| 454 |
+
|
| 455 |
+
|
| 456 |
+
def test_do_resolve():
|
| 457 |
+
p1 = Promise(lambda resolve, reject: resolve(0))
|
| 458 |
+
assert p1.get() == 0
|
| 459 |
+
assert p1.is_fulfilled
|
| 460 |
+
|
| 461 |
+
|
| 462 |
+
def test_do_resolve_fail_on_call():
|
| 463 |
+
def raises(resolve, reject):
|
| 464 |
+
raise Exception("Fails")
|
| 465 |
+
|
| 466 |
+
p1 = Promise(raises)
|
| 467 |
+
assert not p1.is_fulfilled
|
| 468 |
+
assert str(p1.reason) == "Fails"
|
| 469 |
+
|
| 470 |
+
|
| 471 |
+
def test_catch():
|
| 472 |
+
p1 = Promise(lambda resolve, reject: resolve(0))
|
| 473 |
+
p2 = p1.then(lambda value: 1 / value).catch(lambda e: e).then(lambda e: type(e))
|
| 474 |
+
assert p2.get() == ZeroDivisionError
|
| 475 |
+
assert p2.is_fulfilled
|
| 476 |
+
|
| 477 |
+
|
| 478 |
+
def test_is_thenable_promise():
|
| 479 |
+
promise = Promise()
|
| 480 |
+
assert is_thenable(promise)
|
| 481 |
+
|
| 482 |
+
|
| 483 |
+
def test_is_thenable_then_object():
|
| 484 |
+
promise = FakeThenPromise()
|
| 485 |
+
assert not is_thenable(promise)
|
| 486 |
+
|
| 487 |
+
|
| 488 |
+
def test_is_thenable_future():
|
| 489 |
+
promise = Future()
|
| 490 |
+
assert is_thenable(promise)
|
| 491 |
+
|
| 492 |
+
|
| 493 |
+
def test_is_thenable_simple_object():
|
| 494 |
+
assert not is_thenable(object())
|
| 495 |
+
|
| 496 |
+
|
| 497 |
+
@fixture(params=[Promise.resolve])
|
| 498 |
+
def resolve(request):
|
| 499 |
+
return request.param
|
| 500 |
+
|
| 501 |
+
|
| 502 |
+
def test_resolve_promise(resolve):
|
| 503 |
+
promise = Promise()
|
| 504 |
+
assert resolve(promise) == promise
|
| 505 |
+
|
| 506 |
+
|
| 507 |
+
def test_resolve_then_object(resolve):
|
| 508 |
+
promise = FakeThenPromise(raises=False)
|
| 509 |
+
p = resolve(promise)
|
| 510 |
+
assert isinstance(p, Promise)
|
| 511 |
+
|
| 512 |
+
|
| 513 |
+
def test_resolve_future(resolve):
|
| 514 |
+
future = Future()
|
| 515 |
+
promise = resolve(future)
|
| 516 |
+
assert promise.is_pending
|
| 517 |
+
future.set_result(1)
|
| 518 |
+
assert promise.get() == 1
|
| 519 |
+
assert promise.is_fulfilled
|
| 520 |
+
|
| 521 |
+
|
| 522 |
+
def test_resolve_future_rejected(resolve):
|
| 523 |
+
future = Future()
|
| 524 |
+
promise = resolve(future)
|
| 525 |
+
assert promise.is_pending
|
| 526 |
+
future.set_exception(Exception("Future rejected"))
|
| 527 |
+
assert promise.is_rejected
|
| 528 |
+
assert_exception(promise.reason, Exception, "Future rejected")
|
| 529 |
+
|
| 530 |
+
|
| 531 |
+
def test_resolve_object(resolve):
|
| 532 |
+
val = object()
|
| 533 |
+
promised = resolve(val)
|
| 534 |
+
assert isinstance(promised, Promise)
|
| 535 |
+
assert promised.get() == val
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
def test_resolve_promise_subclass():
|
| 539 |
+
class MyPromise(Promise):
|
| 540 |
+
pass
|
| 541 |
+
|
| 542 |
+
p = Promise()
|
| 543 |
+
p.do_resolve(10)
|
| 544 |
+
m_p = MyPromise.resolve(p)
|
| 545 |
+
|
| 546 |
+
assert isinstance(m_p, MyPromise)
|
| 547 |
+
assert m_p.get() == p.get()
|
| 548 |
+
|
| 549 |
+
|
| 550 |
+
def test_promise_repr_pending():
|
| 551 |
+
promise = Promise()
|
| 552 |
+
assert repr(promise) == "<Promise at {} pending>".format(hex(id(promise)))
|
| 553 |
+
|
| 554 |
+
|
| 555 |
+
def test_promise_repr_pending():
|
| 556 |
+
val = {1: 2}
|
| 557 |
+
promise = Promise.fulfilled(val)
|
| 558 |
+
promise._wait()
|
| 559 |
+
assert repr(promise) == "<Promise at {} fulfilled with {}>".format(
|
| 560 |
+
hex(id(promise)), repr(val)
|
| 561 |
+
)
|
| 562 |
+
|
| 563 |
+
|
| 564 |
+
def test_promise_repr_fulfilled():
|
| 565 |
+
val = {1: 2}
|
| 566 |
+
promise = Promise.fulfilled(val)
|
| 567 |
+
promise._wait()
|
| 568 |
+
assert repr(promise) == "<Promise at {} fulfilled with {}>".format(
|
| 569 |
+
hex(id(promise)), repr(val)
|
| 570 |
+
)
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
def test_promise_repr_rejected():
|
| 574 |
+
err = Exception("Error!")
|
| 575 |
+
promise = Promise.rejected(err)
|
| 576 |
+
promise._wait()
|
| 577 |
+
assert repr(promise) == "<Promise at {} rejected with {}>".format(
|
| 578 |
+
hex(id(promise)), repr(err)
|
| 579 |
+
)
|
| 580 |
+
|
| 581 |
+
|
| 582 |
+
def test_promise_loop():
|
| 583 |
+
def by_two(result):
|
| 584 |
+
return result * 2
|
| 585 |
+
|
| 586 |
+
def executor(resolve, reject):
|
| 587 |
+
resolve(Promise.resolve(1).then(lambda v: Promise.resolve(v).then(by_two)))
|
| 588 |
+
|
| 589 |
+
p = Promise(executor)
|
| 590 |
+
assert p.get(.1) == 2
|
| 591 |
+
|
| 592 |
+
|
| 593 |
+
def test_resolve_future_like(resolve):
|
| 594 |
+
class CustomThenable(object):
|
| 595 |
+
def add_done_callback(self, f):
|
| 596 |
+
f(True)
|
| 597 |
+
|
| 598 |
+
def done(self):
|
| 599 |
+
return True
|
| 600 |
+
|
| 601 |
+
def exception(self):
|
| 602 |
+
pass
|
| 603 |
+
|
| 604 |
+
def result(self):
|
| 605 |
+
return True
|
| 606 |
+
|
| 607 |
+
instance = CustomThenable()
|
| 608 |
+
|
| 609 |
+
promise = resolve(instance)
|
| 610 |
+
assert promise.get() == True
|
| 611 |
+
|
| 612 |
+
|
| 613 |
+
def sum_function(a, b):
|
| 614 |
+
return a + b
|
| 615 |
+
|
| 616 |
+
|
| 617 |
+
def test_promisify_function_resolved(resolve):
|
| 618 |
+
promisified_func = promisify(sum_function)
|
| 619 |
+
|
| 620 |
+
result = promisified_func(1, 2)
|
| 621 |
+
assert isinstance(result, Promise)
|
| 622 |
+
assert result.get() == 3
|
| 623 |
+
|
| 624 |
+
|
| 625 |
+
def test_promisify_function_rejected(resolve):
|
| 626 |
+
promisified_func = promisify(sum_function)
|
| 627 |
+
|
| 628 |
+
result = promisified_func(None, None)
|
| 629 |
+
assert isinstance(result, Promise)
|
| 630 |
+
with raises(Exception) as exc_info_promise:
|
| 631 |
+
result.get()
|
| 632 |
+
|
| 633 |
+
with raises(Exception) as exc_info:
|
| 634 |
+
sum_function(None, None)
|
| 635 |
+
|
| 636 |
+
assert str(exc_info_promise.value) == str(exc_info.value)
|
| 637 |
+
|
| 638 |
+
|
| 639 |
+
def test_promises_with_only_then():
|
| 640 |
+
context = {"success": False}
|
| 641 |
+
error = RuntimeError("Ooops!")
|
| 642 |
+
promise1 = Promise(
|
| 643 |
+
lambda resolve, reject: context.update({"promise1_reject": reject})
|
| 644 |
+
)
|
| 645 |
+
promise2 = promise1.then(lambda x: None)
|
| 646 |
+
promise3 = promise1.then(lambda x: None)
|
| 647 |
+
context["promise1_reject"](error)
|
| 648 |
+
|
| 649 |
+
promise2._wait()
|
| 650 |
+
promise3._wait()
|
| 651 |
+
assert promise2.reason == error
|
| 652 |
+
assert promise3.reason == error
|
| 653 |
+
|
| 654 |
+
|
| 655 |
+
def test_promises_promisify_still_works_but_deprecated_for_non_callables():
|
| 656 |
+
x = promisify(1)
|
| 657 |
+
assert isinstance(x, Promise)
|
| 658 |
+
assert x.get() == 1
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
# def test_promise_loop():
|
| 662 |
+
# values = Promise.resolve([1, None, 2])
|
| 663 |
+
# def on_error(error):
|
| 664 |
+
# error
|
| 665 |
+
|
| 666 |
+
# def executor(resolve, reject):
|
| 667 |
+
# resolve(Promise.resolve(values).then(lambda values: Promise.all([Promise.resolve(values[0])]).catch(on_error)))
|
| 668 |
+
|
| 669 |
+
# p = Promise(executor)
|
| 670 |
+
# assert p.get(.1) == 2
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_issues.py
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# This tests reported issues in the Promise package
|
| 2 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 3 |
+
from promise import Promise
|
| 4 |
+
import time
|
| 5 |
+
import weakref
|
| 6 |
+
import gc
|
| 7 |
+
|
| 8 |
+
executor = ThreadPoolExecutor(max_workers=40000)
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_issue_11():
|
| 12 |
+
# https://github.com/syrusakbary/promise/issues/11
|
| 13 |
+
def test(x):
|
| 14 |
+
def my(resolve, reject):
|
| 15 |
+
if x > 0:
|
| 16 |
+
resolve(x)
|
| 17 |
+
else:
|
| 18 |
+
reject(Exception(x))
|
| 19 |
+
|
| 20 |
+
return Promise(my)
|
| 21 |
+
|
| 22 |
+
promise_resolved = test(42).then(lambda x: x)
|
| 23 |
+
assert promise_resolved.get() == 42
|
| 24 |
+
|
| 25 |
+
promise_rejected = test(-42).then(lambda x: x, lambda e: str(e))
|
| 26 |
+
assert promise_rejected.get() == "-42"
|
| 27 |
+
|
| 28 |
+
|
| 29 |
+
def identity(x, wait):
|
| 30 |
+
if wait:
|
| 31 |
+
time.sleep(wait)
|
| 32 |
+
return x
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def promise_with_wait(x, wait):
|
| 36 |
+
return Promise.resolve(identity(x, wait))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_issue_9():
|
| 40 |
+
no_wait = Promise.all(
|
| 41 |
+
[promise_with_wait(x1, None).then(lambda y: x1 * y) for x1 in (0, 1, 2, 3)]
|
| 42 |
+
).get()
|
| 43 |
+
wait_a_bit = Promise.all(
|
| 44 |
+
[promise_with_wait(x2, 0.05).then(lambda y: x2 * y) for x2 in (0, 1, 2, 3)]
|
| 45 |
+
).get()
|
| 46 |
+
wait_longer = Promise.all(
|
| 47 |
+
[promise_with_wait(x3, 0.1).then(lambda y: x3 * y) for x3 in (0, 1, 2, 3)]
|
| 48 |
+
).get()
|
| 49 |
+
|
| 50 |
+
assert no_wait == wait_a_bit
|
| 51 |
+
assert no_wait == wait_longer
|
| 52 |
+
|
| 53 |
+
|
| 54 |
+
@Promise.safe
|
| 55 |
+
def test_issue_9_safe():
|
| 56 |
+
no_wait = Promise.all(
|
| 57 |
+
[promise_with_wait(x1, None).then(lambda y: x1 * y) for x1 in (0, 1, 2, 3)]
|
| 58 |
+
).get()
|
| 59 |
+
wait_a_bit = Promise.all(
|
| 60 |
+
[promise_with_wait(x2, 0.05).then(lambda y: x2 * y) for x2 in (0, 1, 2, 3)]
|
| 61 |
+
).get()
|
| 62 |
+
wait_longer = Promise.all(
|
| 63 |
+
[promise_with_wait(x3, 0.1).then(lambda y: x3 * y) for x3 in (0, 1, 2, 3)]
|
| 64 |
+
).get()
|
| 65 |
+
|
| 66 |
+
assert no_wait == [0, 3, 6, 9]
|
| 67 |
+
assert no_wait == wait_a_bit
|
| 68 |
+
assert no_wait == wait_longer
|
| 69 |
+
|
| 70 |
+
|
| 71 |
+
def test_issue_26():
|
| 72 |
+
context = {"success": False}
|
| 73 |
+
promise1 = Promise(
|
| 74 |
+
lambda resolve, reject: context.update({"promise1_reject": reject})
|
| 75 |
+
)
|
| 76 |
+
promise1.then(lambda x: None)
|
| 77 |
+
promise1.then(lambda x: None)
|
| 78 |
+
context["promise1_reject"](RuntimeError("Ooops!"))
|
| 79 |
+
|
| 80 |
+
promise2 = Promise(
|
| 81 |
+
lambda resolve, reject: context.update({"promise2_resolve": resolve})
|
| 82 |
+
)
|
| 83 |
+
promise3 = promise2.then(lambda x: context.update({"success": True}))
|
| 84 |
+
context["promise2_resolve"](None)
|
| 85 |
+
|
| 86 |
+
# We wait so it works in asynchronous envs
|
| 87 |
+
promise3._wait(timeout=.1)
|
| 88 |
+
assert context["success"]
|
| 89 |
+
|
| 90 |
+
|
| 91 |
+
# def promise_in_executor(x, wait):
|
| 92 |
+
# return Promise.promisify(executor.submit(identity, x, wait))
|
| 93 |
+
|
| 94 |
+
|
| 95 |
+
# @Promise.safe
|
| 96 |
+
# def test_issue_9_extra():
|
| 97 |
+
# no_wait = Promise.all([promise_in_executor(x1, None).then(lambda y: x1*y) for x1 in (0,1,2,3)]).get()
|
| 98 |
+
# wait_a_bit = Promise.all([promise_in_executor(x2, 0.1).then(lambda y: x2*y) for x2 in (0,1,2,3)]).get()
|
| 99 |
+
# wait_longer = Promise.all([promise_in_executor(x3, 0.5).then(lambda y: x3*y) for x3 in (0,1,2,3)]).get()
|
| 100 |
+
|
| 101 |
+
# assert no_wait == [0, 3, 6, 9]
|
| 102 |
+
# assert no_wait == wait_a_bit
|
| 103 |
+
# assert no_wait == wait_longer
|
| 104 |
+
|
| 105 |
+
|
| 106 |
+
def test_issue_33():
|
| 107 |
+
def do(x):
|
| 108 |
+
v = Promise.resolve("ok").then(lambda x: x).get()
|
| 109 |
+
return v
|
| 110 |
+
|
| 111 |
+
p = Promise.resolve(None).then(do)
|
| 112 |
+
assert p.get() == "ok"
|
| 113 |
+
|
| 114 |
+
|
| 115 |
+
def test_issue_75():
|
| 116 |
+
def function_with_local_type():
|
| 117 |
+
class A:
|
| 118 |
+
pass
|
| 119 |
+
|
| 120 |
+
a = A()
|
| 121 |
+
assert a == Promise.resolve(a).get()
|
| 122 |
+
|
| 123 |
+
return weakref.ref(A)
|
| 124 |
+
|
| 125 |
+
weak_reference = function_with_local_type()
|
| 126 |
+
|
| 127 |
+
# The local type 'A' from the function is still kept alive by reference cycles.
|
| 128 |
+
gc.collect()
|
| 129 |
+
|
| 130 |
+
# Now the local type should have been garbage collected,
|
| 131 |
+
# such that the weak reference should be invalid.
|
| 132 |
+
assert not weak_reference()
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_promise_list.py
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pytest import raises
|
| 2 |
+
|
| 3 |
+
from promise import Promise
|
| 4 |
+
from promise.promise_list import PromiseList
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def all(promises):
|
| 8 |
+
return PromiseList(promises, Promise).promise
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
def test_empty_promises():
|
| 12 |
+
all_promises = all([])
|
| 13 |
+
assert all_promises.get() == []
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def test_bad_promises():
|
| 17 |
+
all_promises = all(None)
|
| 18 |
+
|
| 19 |
+
with raises(Exception) as exc_info:
|
| 20 |
+
all_promises.get()
|
| 21 |
+
|
| 22 |
+
assert str(exc_info.value) == "PromiseList requires an iterable. Received None."
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def test_promise_basic():
|
| 26 |
+
all_promises = all([1, 2])
|
| 27 |
+
assert all_promises.get() == [1, 2]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
def test_promise_mixed():
|
| 31 |
+
all_promises = all([1, 2, Promise.resolve(3)])
|
| 32 |
+
assert all_promises.get() == [1, 2, 3]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def test_promise_rejected():
|
| 36 |
+
e = Exception("Error")
|
| 37 |
+
all_promises = all([1, 2, Promise.reject(e)])
|
| 38 |
+
|
| 39 |
+
with raises(Exception) as exc_info:
|
| 40 |
+
all_promises.get()
|
| 41 |
+
|
| 42 |
+
assert str(exc_info.value) == "Error"
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def test_promise_reject_skip_all_other_values():
|
| 46 |
+
e1 = Exception("Error1")
|
| 47 |
+
e2 = Exception("Error2")
|
| 48 |
+
p = Promise()
|
| 49 |
+
all_promises = all([1, Promise.reject(e1), Promise.reject(e2)])
|
| 50 |
+
|
| 51 |
+
with raises(Exception) as exc_info:
|
| 52 |
+
all_promises.get()
|
| 53 |
+
|
| 54 |
+
assert str(exc_info.value) == "Error1"
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def test_promise_lazy_promise():
|
| 58 |
+
p = Promise()
|
| 59 |
+
all_promises = all([1, 2, p])
|
| 60 |
+
assert not all_promises.is_fulfilled
|
| 61 |
+
p.do_resolve(3)
|
| 62 |
+
assert all_promises.get() == [1, 2, 3]
|
| 63 |
+
|
| 64 |
+
|
| 65 |
+
def test_promise_contained_promise():
|
| 66 |
+
p = Promise()
|
| 67 |
+
all_promises = all([1, 2, Promise.resolve(None).then(lambda v: p)])
|
| 68 |
+
assert not all_promises.is_fulfilled
|
| 69 |
+
p.do_resolve(3)
|
| 70 |
+
assert all_promises.get() == [1, 2, 3]
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_spec.py
ADDED
|
@@ -0,0 +1,584 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 5 |
+
from .utils import assert_exception
|
| 6 |
+
|
| 7 |
+
from threading import Event
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Counter:
|
| 11 |
+
"""
|
| 12 |
+
A helper class with some side effects
|
| 13 |
+
we can test.
|
| 14 |
+
"""
|
| 15 |
+
|
| 16 |
+
def __init__(self):
|
| 17 |
+
self.count = 0
|
| 18 |
+
|
| 19 |
+
def tick(self):
|
| 20 |
+
self.count += 1
|
| 21 |
+
|
| 22 |
+
def value(self):
|
| 23 |
+
return self.count
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
def test_3_2_1():
|
| 27 |
+
"""
|
| 28 |
+
Test that the arguments to 'then' are optional.
|
| 29 |
+
"""
|
| 30 |
+
|
| 31 |
+
p1 = Promise()
|
| 32 |
+
p2 = p1.then()
|
| 33 |
+
p3 = Promise()
|
| 34 |
+
p4 = p3.then()
|
| 35 |
+
p1.do_resolve(5)
|
| 36 |
+
p3.do_reject(Exception("How dare you!"))
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def test_3_2_1_1():
|
| 40 |
+
"""
|
| 41 |
+
That that the first argument to 'then' is ignored if it
|
| 42 |
+
is not a function.
|
| 43 |
+
"""
|
| 44 |
+
results = {}
|
| 45 |
+
nonFunctions = [None, False, 5, {}, []]
|
| 46 |
+
|
| 47 |
+
def testNonFunction(nonFunction):
|
| 48 |
+
def foo(k, r):
|
| 49 |
+
results[k] = r
|
| 50 |
+
|
| 51 |
+
p1 = Promise.reject(Exception("Error: " + str(nonFunction)))
|
| 52 |
+
p2 = p1.then(nonFunction, lambda r: foo(str(nonFunction), r))
|
| 53 |
+
p2._wait()
|
| 54 |
+
|
| 55 |
+
for v in nonFunctions:
|
| 56 |
+
testNonFunction(v)
|
| 57 |
+
|
| 58 |
+
for v in nonFunctions:
|
| 59 |
+
assert_exception(results[str(v)], Exception, "Error: " + str(v))
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
def test_3_2_1_2():
|
| 63 |
+
"""
|
| 64 |
+
That that the second argument to 'then' is ignored if it
|
| 65 |
+
is not a function.
|
| 66 |
+
"""
|
| 67 |
+
results = {}
|
| 68 |
+
nonFunctions = [None, False, 5, {}, []]
|
| 69 |
+
|
| 70 |
+
def testNonFunction(nonFunction):
|
| 71 |
+
def foo(k, r):
|
| 72 |
+
results[k] = r
|
| 73 |
+
|
| 74 |
+
p1 = Promise.resolve("Error: " + str(nonFunction))
|
| 75 |
+
p2 = p1.then(lambda r: foo(str(nonFunction), r), nonFunction)
|
| 76 |
+
p2._wait()
|
| 77 |
+
|
| 78 |
+
for v in nonFunctions:
|
| 79 |
+
testNonFunction(v)
|
| 80 |
+
|
| 81 |
+
for v in nonFunctions:
|
| 82 |
+
assert "Error: " + str(v) == results[str(v)]
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
def test_3_2_2_1():
|
| 86 |
+
"""
|
| 87 |
+
The first argument to 'then' must be called when a promise is
|
| 88 |
+
fulfilled.
|
| 89 |
+
"""
|
| 90 |
+
|
| 91 |
+
c = Counter()
|
| 92 |
+
|
| 93 |
+
def check(v, c):
|
| 94 |
+
assert v == 5
|
| 95 |
+
c.tick()
|
| 96 |
+
|
| 97 |
+
p1 = Promise.resolve(5)
|
| 98 |
+
p2 = p1.then(lambda v: check(v, c))
|
| 99 |
+
p2._wait()
|
| 100 |
+
assert 1 == c.value()
|
| 101 |
+
|
| 102 |
+
|
| 103 |
+
def test_3_2_2_2():
|
| 104 |
+
"""
|
| 105 |
+
Make sure callbacks are never called more than once.
|
| 106 |
+
"""
|
| 107 |
+
|
| 108 |
+
c = Counter()
|
| 109 |
+
p1 = Promise.resolve(5)
|
| 110 |
+
p2 = p1.then(lambda v: c.tick())
|
| 111 |
+
p2._wait()
|
| 112 |
+
try:
|
| 113 |
+
# I throw an exception
|
| 114 |
+
p1.do_resolve(5)
|
| 115 |
+
assert False # Should not get here!
|
| 116 |
+
except AssertionError:
|
| 117 |
+
# This is expected
|
| 118 |
+
pass
|
| 119 |
+
assert 1 == c.value()
|
| 120 |
+
|
| 121 |
+
|
| 122 |
+
def test_3_2_2_3():
|
| 123 |
+
"""
|
| 124 |
+
Make sure fulfilled callback never called if promise is rejected
|
| 125 |
+
"""
|
| 126 |
+
|
| 127 |
+
cf = Counter()
|
| 128 |
+
cr = Counter()
|
| 129 |
+
p1 = Promise.reject(Exception("Error"))
|
| 130 |
+
p2 = p1.then(lambda v: cf.tick(), lambda r: cr.tick())
|
| 131 |
+
p2._wait()
|
| 132 |
+
assert 0 == cf.value()
|
| 133 |
+
assert 1 == cr.value()
|
| 134 |
+
|
| 135 |
+
|
| 136 |
+
def test_3_2_3_1():
|
| 137 |
+
"""
|
| 138 |
+
The second argument to 'then' must be called when a promise is
|
| 139 |
+
rejected.
|
| 140 |
+
"""
|
| 141 |
+
|
| 142 |
+
c = Counter()
|
| 143 |
+
|
| 144 |
+
def check(r, c):
|
| 145 |
+
assert_exception(r, Exception, "Error")
|
| 146 |
+
c.tick()
|
| 147 |
+
|
| 148 |
+
p1 = Promise.reject(Exception("Error"))
|
| 149 |
+
p2 = p1.then(None, lambda r: check(r, c))
|
| 150 |
+
p2._wait()
|
| 151 |
+
assert 1 == c.value()
|
| 152 |
+
|
| 153 |
+
|
| 154 |
+
def test_3_2_3_2():
|
| 155 |
+
"""
|
| 156 |
+
Make sure callbacks are never called more than once.
|
| 157 |
+
"""
|
| 158 |
+
|
| 159 |
+
c = Counter()
|
| 160 |
+
p1 = Promise.reject(Exception("Error"))
|
| 161 |
+
p2 = p1.then(None, lambda v: c.tick())
|
| 162 |
+
p2._wait()
|
| 163 |
+
try:
|
| 164 |
+
# I throw an exception
|
| 165 |
+
p1.do_reject(Exception("Error"))
|
| 166 |
+
assert False # Should not get here!
|
| 167 |
+
except AssertionError:
|
| 168 |
+
# This is expected
|
| 169 |
+
pass
|
| 170 |
+
assert 1 == c.value()
|
| 171 |
+
|
| 172 |
+
|
| 173 |
+
def test_3_2_3_3():
|
| 174 |
+
"""
|
| 175 |
+
Make sure rejected callback never called if promise is fulfilled
|
| 176 |
+
"""
|
| 177 |
+
|
| 178 |
+
cf = Counter()
|
| 179 |
+
cr = Counter()
|
| 180 |
+
p1 = Promise.resolve(5)
|
| 181 |
+
p2 = p1.then(lambda v: cf.tick(), lambda r: cr.tick())
|
| 182 |
+
p2._wait()
|
| 183 |
+
assert 0 == cr.value()
|
| 184 |
+
assert 1 == cf.value()
|
| 185 |
+
|
| 186 |
+
|
| 187 |
+
def test_3_2_5_1_when():
|
| 188 |
+
"""
|
| 189 |
+
Then can be called multiple times on the same promise
|
| 190 |
+
and callbacks must be called in the order of the
|
| 191 |
+
then calls.
|
| 192 |
+
"""
|
| 193 |
+
|
| 194 |
+
def add(l, v):
|
| 195 |
+
l.append(v)
|
| 196 |
+
|
| 197 |
+
p1 = Promise.resolve(2)
|
| 198 |
+
order = []
|
| 199 |
+
p2 = p1.then(lambda v: add(order, "p2"))
|
| 200 |
+
p3 = p1.then(lambda v: add(order, "p3"))
|
| 201 |
+
p2._wait()
|
| 202 |
+
p3._wait()
|
| 203 |
+
assert 2 == len(order)
|
| 204 |
+
assert "p2" == order[0]
|
| 205 |
+
assert "p3" == order[1]
|
| 206 |
+
|
| 207 |
+
|
| 208 |
+
def test_3_2_5_1_if():
|
| 209 |
+
"""
|
| 210 |
+
Then can be called multiple times on the same promise
|
| 211 |
+
and callbacks must be called in the order of the
|
| 212 |
+
then calls.
|
| 213 |
+
"""
|
| 214 |
+
|
| 215 |
+
def add(l, v):
|
| 216 |
+
l.append(v)
|
| 217 |
+
|
| 218 |
+
p1 = Promise.resolve(2)
|
| 219 |
+
order = []
|
| 220 |
+
p2 = p1.then(lambda v: add(order, "p2"))
|
| 221 |
+
p3 = p1.then(lambda v: add(order, "p3"))
|
| 222 |
+
p2._wait()
|
| 223 |
+
p3._wait()
|
| 224 |
+
assert 2 == len(order)
|
| 225 |
+
assert "p2" == order[0]
|
| 226 |
+
assert "p3" == order[1]
|
| 227 |
+
|
| 228 |
+
|
| 229 |
+
def test_3_2_5_2_when():
|
| 230 |
+
"""
|
| 231 |
+
Then can be called multiple times on the same promise
|
| 232 |
+
and callbacks must be called in the order of the
|
| 233 |
+
then calls.
|
| 234 |
+
"""
|
| 235 |
+
|
| 236 |
+
def add(l, v):
|
| 237 |
+
l.append(v)
|
| 238 |
+
|
| 239 |
+
p1 = Promise.reject(Exception("Error"))
|
| 240 |
+
order = []
|
| 241 |
+
p2 = p1.then(None, lambda v: add(order, "p2"))
|
| 242 |
+
p3 = p1.then(None, lambda v: add(order, "p3"))
|
| 243 |
+
p2._wait()
|
| 244 |
+
p3._wait()
|
| 245 |
+
assert 2 == len(order)
|
| 246 |
+
assert "p2" == order[0]
|
| 247 |
+
assert "p3" == order[1]
|
| 248 |
+
|
| 249 |
+
|
| 250 |
+
def test_3_2_5_2_if():
|
| 251 |
+
"""
|
| 252 |
+
Then can be called multiple times on the same promise
|
| 253 |
+
and callbacks must be called in the order of the
|
| 254 |
+
then calls.
|
| 255 |
+
"""
|
| 256 |
+
|
| 257 |
+
def add(l, v):
|
| 258 |
+
l.append(v)
|
| 259 |
+
|
| 260 |
+
p1 = Promise.reject(Exception("Error"))
|
| 261 |
+
order = []
|
| 262 |
+
p2 = p1.then(None, lambda v: add(order, "p2"))
|
| 263 |
+
p3 = p1.then(None, lambda v: add(order, "p3"))
|
| 264 |
+
p2._wait()
|
| 265 |
+
p3._wait()
|
| 266 |
+
assert 2 == len(order)
|
| 267 |
+
assert "p2" == order[0]
|
| 268 |
+
assert "p3" == order[1]
|
| 269 |
+
|
| 270 |
+
|
| 271 |
+
def test_3_2_6_1():
|
| 272 |
+
"""
|
| 273 |
+
Promises returned by then must be fulfilled when the promise
|
| 274 |
+
they are chained from is fulfilled IF the fulfillment value
|
| 275 |
+
is not a promise.
|
| 276 |
+
"""
|
| 277 |
+
|
| 278 |
+
p1 = Promise.resolve(5)
|
| 279 |
+
pf = p1.then(lambda v: v * v)
|
| 280 |
+
assert pf.get() == 25
|
| 281 |
+
|
| 282 |
+
p2 = Promise.reject(Exception("Error"))
|
| 283 |
+
pr = p2.then(None, lambda r: 5)
|
| 284 |
+
assert 5 == pr.get()
|
| 285 |
+
|
| 286 |
+
|
| 287 |
+
def test_3_2_6_2_when():
|
| 288 |
+
"""
|
| 289 |
+
Promises returned by then must be rejected when any of their
|
| 290 |
+
callbacks throw an exception.
|
| 291 |
+
"""
|
| 292 |
+
|
| 293 |
+
def fail(v):
|
| 294 |
+
raise AssertionError("Exception Message")
|
| 295 |
+
|
| 296 |
+
p1 = Promise.resolve(5)
|
| 297 |
+
pf = p1.then(fail)
|
| 298 |
+
pf._wait()
|
| 299 |
+
assert pf.is_rejected
|
| 300 |
+
assert_exception(pf.reason, AssertionError, "Exception Message")
|
| 301 |
+
|
| 302 |
+
p2 = Promise.reject(Exception("Error"))
|
| 303 |
+
pr = p2.then(None, fail)
|
| 304 |
+
pr._wait()
|
| 305 |
+
assert pr.is_rejected
|
| 306 |
+
assert_exception(pr.reason, AssertionError, "Exception Message")
|
| 307 |
+
|
| 308 |
+
|
| 309 |
+
def test_3_2_6_2_if():
|
| 310 |
+
"""
|
| 311 |
+
Promises returned by then must be rejected when any of their
|
| 312 |
+
callbacks throw an exception.
|
| 313 |
+
"""
|
| 314 |
+
|
| 315 |
+
def fail(v):
|
| 316 |
+
raise AssertionError("Exception Message")
|
| 317 |
+
|
| 318 |
+
p1 = Promise.resolve(5)
|
| 319 |
+
pf = p1.then(fail)
|
| 320 |
+
pf._wait()
|
| 321 |
+
assert pf.is_rejected
|
| 322 |
+
assert_exception(pf.reason, AssertionError, "Exception Message")
|
| 323 |
+
|
| 324 |
+
p2 = Promise.reject(Exception("Error"))
|
| 325 |
+
pr = p2.then(None, fail)
|
| 326 |
+
pr._wait()
|
| 327 |
+
assert pr.is_rejected
|
| 328 |
+
assert_exception(pr.reason, AssertionError, "Exception Message")
|
| 329 |
+
|
| 330 |
+
|
| 331 |
+
def test_3_2_6_3_when_fulfilled():
|
| 332 |
+
"""
|
| 333 |
+
Testing return of pending promises to make
|
| 334 |
+
sure they are properly chained.
|
| 335 |
+
This covers the case where the root promise
|
| 336 |
+
is fulfilled after the chaining is defined.
|
| 337 |
+
"""
|
| 338 |
+
|
| 339 |
+
p1 = Promise()
|
| 340 |
+
pending = Promise()
|
| 341 |
+
|
| 342 |
+
def p1_resolved(v):
|
| 343 |
+
return pending
|
| 344 |
+
|
| 345 |
+
pf = p1.then(p1_resolved)
|
| 346 |
+
|
| 347 |
+
assert pending.is_pending
|
| 348 |
+
assert pf.is_pending
|
| 349 |
+
p1.do_resolve(10)
|
| 350 |
+
pending.do_resolve(5)
|
| 351 |
+
pending._wait()
|
| 352 |
+
assert pending.is_fulfilled
|
| 353 |
+
assert 5 == pending.get()
|
| 354 |
+
pf._wait()
|
| 355 |
+
assert pf.is_fulfilled
|
| 356 |
+
assert 5 == pf.get()
|
| 357 |
+
|
| 358 |
+
p2 = Promise()
|
| 359 |
+
bad = Promise()
|
| 360 |
+
pr = p2.then(lambda r: bad)
|
| 361 |
+
assert bad.is_pending
|
| 362 |
+
assert pr.is_pending
|
| 363 |
+
p2.do_resolve(10)
|
| 364 |
+
bad._reject_callback(Exception("Error"))
|
| 365 |
+
bad._wait()
|
| 366 |
+
assert bad.is_rejected
|
| 367 |
+
assert_exception(bad.reason, Exception, "Error")
|
| 368 |
+
pr._wait()
|
| 369 |
+
assert pr.is_rejected
|
| 370 |
+
assert_exception(pr.reason, Exception, "Error")
|
| 371 |
+
|
| 372 |
+
|
| 373 |
+
def test_3_2_6_3_if_fulfilled():
|
| 374 |
+
"""
|
| 375 |
+
Testing return of pending promises to make
|
| 376 |
+
sure they are properly chained.
|
| 377 |
+
This covers the case where the root promise
|
| 378 |
+
is fulfilled before the chaining is defined.
|
| 379 |
+
"""
|
| 380 |
+
|
| 381 |
+
p1 = Promise()
|
| 382 |
+
p1.do_resolve(10)
|
| 383 |
+
pending = Promise()
|
| 384 |
+
pending.do_resolve(5)
|
| 385 |
+
pf = p1.then(lambda r: pending)
|
| 386 |
+
pending._wait()
|
| 387 |
+
assert pending.is_fulfilled
|
| 388 |
+
assert 5 == pending.get()
|
| 389 |
+
pf._wait()
|
| 390 |
+
assert pf.is_fulfilled
|
| 391 |
+
assert 5 == pf.get()
|
| 392 |
+
|
| 393 |
+
p2 = Promise()
|
| 394 |
+
p2.do_resolve(10)
|
| 395 |
+
bad = Promise()
|
| 396 |
+
bad.do_reject(Exception("Error"))
|
| 397 |
+
pr = p2.then(lambda r: bad)
|
| 398 |
+
bad._wait()
|
| 399 |
+
assert_exception(bad.reason, Exception, "Error")
|
| 400 |
+
pr._wait()
|
| 401 |
+
assert pr.is_rejected
|
| 402 |
+
assert_exception(pr.reason, Exception, "Error")
|
| 403 |
+
|
| 404 |
+
|
| 405 |
+
def test_3_2_6_3_when_rejected():
|
| 406 |
+
"""
|
| 407 |
+
Testing return of pending promises to make
|
| 408 |
+
sure they are properly chained.
|
| 409 |
+
This covers the case where the root promise
|
| 410 |
+
is rejected after the chaining is defined.
|
| 411 |
+
"""
|
| 412 |
+
|
| 413 |
+
p1 = Promise()
|
| 414 |
+
pending = Promise()
|
| 415 |
+
pr = p1.then(None, lambda r: pending)
|
| 416 |
+
assert pending.is_pending
|
| 417 |
+
assert pr.is_pending
|
| 418 |
+
p1.do_reject(Exception("Error"))
|
| 419 |
+
pending.do_resolve(10)
|
| 420 |
+
pending._wait()
|
| 421 |
+
assert pending.is_fulfilled
|
| 422 |
+
assert 10 == pending.get()
|
| 423 |
+
assert 10 == pr.get()
|
| 424 |
+
|
| 425 |
+
p2 = Promise()
|
| 426 |
+
bad = Promise()
|
| 427 |
+
pr = p2.then(None, lambda r: bad)
|
| 428 |
+
assert bad.is_pending
|
| 429 |
+
assert pr.is_pending
|
| 430 |
+
p2.do_reject(Exception("Error"))
|
| 431 |
+
bad.do_reject(Exception("Assertion"))
|
| 432 |
+
bad._wait()
|
| 433 |
+
assert bad.is_rejected
|
| 434 |
+
assert_exception(bad.reason, Exception, "Assertion")
|
| 435 |
+
pr._wait()
|
| 436 |
+
assert pr.is_rejected
|
| 437 |
+
assert_exception(pr.reason, Exception, "Assertion")
|
| 438 |
+
|
| 439 |
+
|
| 440 |
+
def test_3_2_6_3_if_rejected():
|
| 441 |
+
"""
|
| 442 |
+
Testing return of pending promises to make
|
| 443 |
+
sure they are properly chained.
|
| 444 |
+
This covers the case where the root promise
|
| 445 |
+
is rejected before the chaining is defined.
|
| 446 |
+
"""
|
| 447 |
+
|
| 448 |
+
p1 = Promise()
|
| 449 |
+
p1.do_reject(Exception("Error"))
|
| 450 |
+
pending = Promise()
|
| 451 |
+
pending.do_resolve(10)
|
| 452 |
+
pr = p1.then(None, lambda r: pending)
|
| 453 |
+
pending._wait()
|
| 454 |
+
assert pending.is_fulfilled
|
| 455 |
+
assert 10 == pending.get()
|
| 456 |
+
pr._wait()
|
| 457 |
+
assert pr.is_fulfilled
|
| 458 |
+
assert 10 == pr.get()
|
| 459 |
+
|
| 460 |
+
p2 = Promise()
|
| 461 |
+
p2.do_reject(Exception("Error"))
|
| 462 |
+
bad = Promise()
|
| 463 |
+
bad.do_reject(Exception("Assertion"))
|
| 464 |
+
pr = p2.then(None, lambda r: bad)
|
| 465 |
+
bad._wait()
|
| 466 |
+
assert bad.is_rejected
|
| 467 |
+
assert_exception(bad.reason, Exception, "Assertion")
|
| 468 |
+
pr._wait()
|
| 469 |
+
assert pr.is_rejected
|
| 470 |
+
assert_exception(pr.reason, Exception, "Assertion")
|
| 471 |
+
|
| 472 |
+
|
| 473 |
+
def test_3_2_6_4_pending():
|
| 474 |
+
"""
|
| 475 |
+
Handles the case where the arguments to then
|
| 476 |
+
are not functions or promises.
|
| 477 |
+
"""
|
| 478 |
+
p1 = Promise()
|
| 479 |
+
p2 = p1.then(5)
|
| 480 |
+
p1.do_resolve(10)
|
| 481 |
+
assert 10 == p1.get()
|
| 482 |
+
p2._wait()
|
| 483 |
+
assert p2.is_fulfilled
|
| 484 |
+
assert 10 == p2.get()
|
| 485 |
+
|
| 486 |
+
|
| 487 |
+
def test_3_2_6_4_fulfilled():
|
| 488 |
+
"""
|
| 489 |
+
Handles the case where the arguments to then
|
| 490 |
+
are values, not functions or promises.
|
| 491 |
+
"""
|
| 492 |
+
p1 = Promise()
|
| 493 |
+
p1.do_resolve(10)
|
| 494 |
+
p2 = p1.then(5)
|
| 495 |
+
assert 10 == p1.get()
|
| 496 |
+
p2._wait()
|
| 497 |
+
assert p2.is_fulfilled
|
| 498 |
+
assert 10 == p2.get()
|
| 499 |
+
|
| 500 |
+
|
| 501 |
+
def test_3_2_6_5_pending():
|
| 502 |
+
"""
|
| 503 |
+
Handles the case where the arguments to then
|
| 504 |
+
are values, not functions or promises.
|
| 505 |
+
"""
|
| 506 |
+
p1 = Promise()
|
| 507 |
+
p2 = p1.then(None, 5)
|
| 508 |
+
p1.do_reject(Exception("Error"))
|
| 509 |
+
assert_exception(p1.reason, Exception, "Error")
|
| 510 |
+
p2._wait()
|
| 511 |
+
assert p2.is_rejected
|
| 512 |
+
assert_exception(p2.reason, Exception, "Error")
|
| 513 |
+
|
| 514 |
+
|
| 515 |
+
def test_3_2_6_5_rejected():
|
| 516 |
+
"""
|
| 517 |
+
Handles the case where the arguments to then
|
| 518 |
+
are values, not functions or promises.
|
| 519 |
+
"""
|
| 520 |
+
p1 = Promise()
|
| 521 |
+
p1.do_reject(Exception("Error"))
|
| 522 |
+
p2 = p1.then(None, 5)
|
| 523 |
+
assert_exception(p1.reason, Exception, "Error")
|
| 524 |
+
p2._wait()
|
| 525 |
+
assert p2.is_rejected
|
| 526 |
+
assert_exception(p2.reason, Exception, "Error")
|
| 527 |
+
|
| 528 |
+
|
| 529 |
+
def test_chained_promises():
|
| 530 |
+
"""
|
| 531 |
+
Handles the case where the arguments to then
|
| 532 |
+
are values, not functions or promises.
|
| 533 |
+
"""
|
| 534 |
+
p1 = Promise(lambda resolve, reject: resolve(Promise.resolve(True)))
|
| 535 |
+
assert p1.get() == True
|
| 536 |
+
|
| 537 |
+
|
| 538 |
+
def test_promise_resolved_after():
|
| 539 |
+
"""
|
| 540 |
+
The first argument to 'then' must be called when a promise is
|
| 541 |
+
fulfilled.
|
| 542 |
+
"""
|
| 543 |
+
|
| 544 |
+
c = Counter()
|
| 545 |
+
|
| 546 |
+
def check(v, c):
|
| 547 |
+
assert v == 5
|
| 548 |
+
c.tick()
|
| 549 |
+
|
| 550 |
+
p1 = Promise()
|
| 551 |
+
p2 = p1.then(lambda v: check(v, c))
|
| 552 |
+
p1.do_resolve(5)
|
| 553 |
+
Promise.wait(p2)
|
| 554 |
+
|
| 555 |
+
assert 1 == c.value()
|
| 556 |
+
|
| 557 |
+
|
| 558 |
+
def test_promise_follows_indifentely():
|
| 559 |
+
a = Promise.resolve(None)
|
| 560 |
+
b = a.then(lambda x: Promise.resolve("X"))
|
| 561 |
+
e = Event()
|
| 562 |
+
|
| 563 |
+
def b_then(v):
|
| 564 |
+
|
| 565 |
+
c = Promise.resolve(None)
|
| 566 |
+
d = c.then(lambda v: Promise.resolve("B"))
|
| 567 |
+
return d
|
| 568 |
+
|
| 569 |
+
promise = b.then(b_then)
|
| 570 |
+
|
| 571 |
+
assert promise.get() == "B"
|
| 572 |
+
|
| 573 |
+
|
| 574 |
+
def test_promise_all_follows_indifentely():
|
| 575 |
+
promises = Promise.all(
|
| 576 |
+
[
|
| 577 |
+
Promise.resolve("A"),
|
| 578 |
+
Promise.resolve(None)
|
| 579 |
+
.then(Promise.resolve)
|
| 580 |
+
.then(lambda v: Promise.resolve(None).then(lambda v: Promise.resolve("B"))),
|
| 581 |
+
]
|
| 582 |
+
)
|
| 583 |
+
|
| 584 |
+
assert promises.get() == ["A", "B"]
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/test_thread_safety.py
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from promise import Promise
|
| 2 |
+
from promise.dataloader import DataLoader
|
| 3 |
+
import threading
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def test_promise_thread_safety():
|
| 8 |
+
"""
|
| 9 |
+
Promise tasks should never be executed in a different thread from the one they are scheduled from,
|
| 10 |
+
unless the ThreadPoolExecutor is used.
|
| 11 |
+
|
| 12 |
+
Here we assert that the pending promise tasks on thread 1 are not executed on thread 2 as thread 2
|
| 13 |
+
resolves its own promise tasks.
|
| 14 |
+
"""
|
| 15 |
+
event_1 = threading.Event()
|
| 16 |
+
event_2 = threading.Event()
|
| 17 |
+
|
| 18 |
+
assert_object = {'is_same_thread': True}
|
| 19 |
+
|
| 20 |
+
def task_1():
|
| 21 |
+
thread_name = threading.current_thread().getName()
|
| 22 |
+
|
| 23 |
+
def then_1(value):
|
| 24 |
+
# Enqueue tasks to run later.
|
| 25 |
+
# This relies on the fact that `then` does not execute the function synchronously when called from
|
| 26 |
+
# within another `then` callback function.
|
| 27 |
+
promise = Promise.resolve(None).then(then_2)
|
| 28 |
+
assert promise.is_pending
|
| 29 |
+
event_1.set() # Unblock main thread
|
| 30 |
+
event_2.wait() # Wait for thread 2
|
| 31 |
+
|
| 32 |
+
def then_2(value):
|
| 33 |
+
assert_object['is_same_thread'] = (thread_name == threading.current_thread().getName())
|
| 34 |
+
|
| 35 |
+
promise = Promise.resolve(None).then(then_1)
|
| 36 |
+
|
| 37 |
+
def task_2():
|
| 38 |
+
promise = Promise.resolve(None).then(lambda v: None)
|
| 39 |
+
promise.get() # Drain task queue
|
| 40 |
+
event_2.set() # Unblock thread 1
|
| 41 |
+
|
| 42 |
+
thread_1 = threading.Thread(target=task_1)
|
| 43 |
+
thread_1.start()
|
| 44 |
+
|
| 45 |
+
event_1.wait() # Wait for Thread 1 to enqueue promise tasks
|
| 46 |
+
|
| 47 |
+
thread_2 = threading.Thread(target=task_2)
|
| 48 |
+
thread_2.start()
|
| 49 |
+
|
| 50 |
+
for thread in (thread_1, thread_2):
|
| 51 |
+
thread.join()
|
| 52 |
+
|
| 53 |
+
assert assert_object['is_same_thread']
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
def test_dataloader_thread_safety():
|
| 57 |
+
"""
|
| 58 |
+
Dataloader should only batch `load` calls that happened on the same thread.
|
| 59 |
+
|
| 60 |
+
Here we assert that `load` calls on thread 2 are not batched on thread 1 as
|
| 61 |
+
thread 1 batches its own `load` calls.
|
| 62 |
+
"""
|
| 63 |
+
def load_many(keys):
|
| 64 |
+
thead_name = threading.current_thread().getName()
|
| 65 |
+
return Promise.resolve([thead_name for key in keys])
|
| 66 |
+
|
| 67 |
+
thread_name_loader = DataLoader(load_many)
|
| 68 |
+
|
| 69 |
+
event_1 = threading.Event()
|
| 70 |
+
event_2 = threading.Event()
|
| 71 |
+
event_3 = threading.Event()
|
| 72 |
+
|
| 73 |
+
assert_object = {
|
| 74 |
+
'is_same_thread_1': True,
|
| 75 |
+
'is_same_thread_2': True,
|
| 76 |
+
}
|
| 77 |
+
|
| 78 |
+
def task_1():
|
| 79 |
+
@Promise.safe
|
| 80 |
+
def do():
|
| 81 |
+
promise = thread_name_loader.load(1)
|
| 82 |
+
event_1.set()
|
| 83 |
+
event_2.wait() # Wait for thread 2 to call `load`
|
| 84 |
+
assert_object['is_same_thread_1'] = (
|
| 85 |
+
promise.get() == threading.current_thread().getName()
|
| 86 |
+
)
|
| 87 |
+
event_3.set() # Unblock thread 2
|
| 88 |
+
|
| 89 |
+
do().get()
|
| 90 |
+
|
| 91 |
+
def task_2():
|
| 92 |
+
@Promise.safe
|
| 93 |
+
def do():
|
| 94 |
+
promise = thread_name_loader.load(2)
|
| 95 |
+
event_2.set()
|
| 96 |
+
event_3.wait() # Wait for thread 1 to run `dispatch_queue_batch`
|
| 97 |
+
assert_object['is_same_thread_2'] = (
|
| 98 |
+
promise.get() == threading.current_thread().getName()
|
| 99 |
+
)
|
| 100 |
+
|
| 101 |
+
do().get()
|
| 102 |
+
|
| 103 |
+
thread_1 = threading.Thread(target=task_1)
|
| 104 |
+
thread_1.start()
|
| 105 |
+
|
| 106 |
+
event_1.wait() # Wait for thread 1 to call `load`
|
| 107 |
+
|
| 108 |
+
thread_2 = threading.Thread(target=task_2)
|
| 109 |
+
thread_2.start()
|
| 110 |
+
|
| 111 |
+
for thread in (thread_1, thread_2):
|
| 112 |
+
thread.join()
|
| 113 |
+
|
| 114 |
+
assert assert_object['is_same_thread_1']
|
| 115 |
+
assert assert_object['is_same_thread_2']
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/tests/utils.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
def assert_exception(exception, expected_exception_cls, expected_message):
|
| 2 |
+
assert isinstance(exception, expected_exception_cls)
|
| 3 |
+
assert str(exception) == expected_message
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__init__.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from .pyutils.version import get_version
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
try:
|
| 5 |
+
# This variable is injected in the __builtins__ by the build
|
| 6 |
+
# process. It used to enable importing subpackages when
|
| 7 |
+
# the required packages are not installed
|
| 8 |
+
__SETUP__ # type: ignore
|
| 9 |
+
except NameError:
|
| 10 |
+
__SETUP__ = False
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
VERSION = (2, 3, 0, "final", 0)
|
| 14 |
+
|
| 15 |
+
__version__ = get_version(VERSION)
|
| 16 |
+
|
| 17 |
+
if not __SETUP__:
|
| 18 |
+
from .promise import (
|
| 19 |
+
Promise,
|
| 20 |
+
promise_for_dict,
|
| 21 |
+
promisify,
|
| 22 |
+
is_thenable,
|
| 23 |
+
async_instance,
|
| 24 |
+
get_default_scheduler,
|
| 25 |
+
set_default_scheduler,
|
| 26 |
+
)
|
| 27 |
+
from .schedulers.immediate import ImmediateScheduler
|
| 28 |
+
|
| 29 |
+
__all__ = [
|
| 30 |
+
"Promise",
|
| 31 |
+
"promise_for_dict",
|
| 32 |
+
"promisify",
|
| 33 |
+
"is_thenable",
|
| 34 |
+
"async_instance",
|
| 35 |
+
"get_default_scheduler",
|
| 36 |
+
"set_default_scheduler",
|
| 37 |
+
"ImmediateScheduler",
|
| 38 |
+
]
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (706 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/async_.cpython-310.pyc
ADDED
|
Binary file (3.94 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/compat.cpython-310.pyc
ADDED
|
Binary file (1.38 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/dataloader.cpython-310.pyc
ADDED
|
Binary file (7.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/iterate_promise.cpython-310.pyc
ADDED
|
Binary file (435 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/promise.cpython-310.pyc
ADDED
|
Binary file (20.1 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/promise_list.cpython-310.pyc
ADDED
|
Binary file (3.42 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/__pycache__/utils.cpython-310.pyc
ADDED
|
Binary file (1.82 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/async_.py
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Based on https://github.com/petkaantonov/bluebird/blob/master/src/promise.js
|
| 2 |
+
from collections import deque
|
| 3 |
+
from threading import local
|
| 4 |
+
|
| 5 |
+
if False:
|
| 6 |
+
from .promise import Promise
|
| 7 |
+
from typing import Any, Callable, Optional, Union # flake8: noqa
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
class Async(local):
|
| 11 |
+
def __init__(self, trampoline_enabled=True):
|
| 12 |
+
self.is_tick_used = False
|
| 13 |
+
self.late_queue = deque() # type: ignore
|
| 14 |
+
self.normal_queue = deque() # type: ignore
|
| 15 |
+
self.have_drained_queues = False
|
| 16 |
+
self.trampoline_enabled = trampoline_enabled
|
| 17 |
+
|
| 18 |
+
def enable_trampoline(self):
|
| 19 |
+
self.trampoline_enabled = True
|
| 20 |
+
|
| 21 |
+
def disable_trampoline(self):
|
| 22 |
+
self.trampoline_enabled = False
|
| 23 |
+
|
| 24 |
+
def have_items_queued(self):
|
| 25 |
+
return self.is_tick_used or self.have_drained_queues
|
| 26 |
+
|
| 27 |
+
def _async_invoke_later(self, fn, scheduler):
|
| 28 |
+
self.late_queue.append(fn)
|
| 29 |
+
self.queue_tick(scheduler)
|
| 30 |
+
|
| 31 |
+
def _async_invoke(self, fn, scheduler):
|
| 32 |
+
# type: (Callable, Any) -> None
|
| 33 |
+
self.normal_queue.append(fn)
|
| 34 |
+
self.queue_tick(scheduler)
|
| 35 |
+
|
| 36 |
+
def _async_settle_promise(self, promise):
|
| 37 |
+
# type: (Promise) -> None
|
| 38 |
+
self.normal_queue.append(promise)
|
| 39 |
+
self.queue_tick(promise.scheduler)
|
| 40 |
+
|
| 41 |
+
def invoke_later(self, fn):
|
| 42 |
+
if self.trampoline_enabled:
|
| 43 |
+
self._async_invoke_later(fn, scheduler)
|
| 44 |
+
else:
|
| 45 |
+
scheduler.call_later(0.1, fn)
|
| 46 |
+
|
| 47 |
+
def invoke(self, fn, scheduler):
|
| 48 |
+
# type: (Callable, Any) -> None
|
| 49 |
+
if self.trampoline_enabled:
|
| 50 |
+
self._async_invoke(fn, scheduler)
|
| 51 |
+
else:
|
| 52 |
+
scheduler.call(fn)
|
| 53 |
+
|
| 54 |
+
def settle_promises(self, promise):
|
| 55 |
+
# type: (Promise) -> None
|
| 56 |
+
if self.trampoline_enabled:
|
| 57 |
+
self._async_settle_promise(promise)
|
| 58 |
+
else:
|
| 59 |
+
promise.scheduler.call(promise._settle_promises)
|
| 60 |
+
|
| 61 |
+
def throw_later(self, reason, scheduler):
|
| 62 |
+
# type: (Exception, Any) -> None
|
| 63 |
+
def fn():
|
| 64 |
+
# type: () -> None
|
| 65 |
+
raise reason
|
| 66 |
+
|
| 67 |
+
scheduler.call(fn)
|
| 68 |
+
|
| 69 |
+
fatal_error = throw_later
|
| 70 |
+
|
| 71 |
+
def drain_queue(self, queue):
|
| 72 |
+
# type: (deque) -> None
|
| 73 |
+
from .promise import Promise
|
| 74 |
+
|
| 75 |
+
while queue:
|
| 76 |
+
fn = queue.popleft()
|
| 77 |
+
if isinstance(fn, Promise):
|
| 78 |
+
fn._settle_promises()
|
| 79 |
+
continue
|
| 80 |
+
fn()
|
| 81 |
+
|
| 82 |
+
def drain_queue_until_resolved(self, promise):
|
| 83 |
+
# type: (Promise) -> None
|
| 84 |
+
from .promise import Promise
|
| 85 |
+
|
| 86 |
+
queue = self.normal_queue
|
| 87 |
+
while queue:
|
| 88 |
+
if not promise.is_pending:
|
| 89 |
+
return
|
| 90 |
+
fn = queue.popleft()
|
| 91 |
+
if isinstance(fn, Promise):
|
| 92 |
+
fn._settle_promises()
|
| 93 |
+
continue
|
| 94 |
+
fn()
|
| 95 |
+
|
| 96 |
+
self.reset()
|
| 97 |
+
self.have_drained_queues = True
|
| 98 |
+
self.drain_queue(self.late_queue)
|
| 99 |
+
|
| 100 |
+
def wait(self, promise, timeout=None):
|
| 101 |
+
# type: (Promise, Optional[float]) -> None
|
| 102 |
+
if not promise.is_pending:
|
| 103 |
+
# We return if the promise is already
|
| 104 |
+
# fulfilled or rejected
|
| 105 |
+
return
|
| 106 |
+
|
| 107 |
+
target = promise._target()
|
| 108 |
+
|
| 109 |
+
if self.trampoline_enabled:
|
| 110 |
+
if self.is_tick_used:
|
| 111 |
+
self.drain_queue_until_resolved(target)
|
| 112 |
+
|
| 113 |
+
if not promise.is_pending:
|
| 114 |
+
# We return if the promise is already
|
| 115 |
+
# fulfilled or rejected
|
| 116 |
+
return
|
| 117 |
+
target.scheduler.wait(target, timeout)
|
| 118 |
+
|
| 119 |
+
def drain_queues(self):
|
| 120 |
+
# type: () -> None
|
| 121 |
+
assert self.is_tick_used
|
| 122 |
+
self.drain_queue(self.normal_queue)
|
| 123 |
+
self.reset()
|
| 124 |
+
self.have_drained_queues = True
|
| 125 |
+
self.drain_queue(self.late_queue)
|
| 126 |
+
|
| 127 |
+
def queue_tick(self, scheduler):
|
| 128 |
+
# type: (Any) -> None
|
| 129 |
+
if not self.is_tick_used:
|
| 130 |
+
self.is_tick_used = True
|
| 131 |
+
scheduler.call(self.drain_queues)
|
| 132 |
+
|
| 133 |
+
def reset(self):
|
| 134 |
+
# type: () -> None
|
| 135 |
+
self.is_tick_used = False
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/compat.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
from inspect import iscoroutine
|
| 3 |
+
except ImportError:
|
| 4 |
+
|
| 5 |
+
def iscoroutine(obj): # type: ignore
|
| 6 |
+
return False
|
| 7 |
+
|
| 8 |
+
|
| 9 |
+
try:
|
| 10 |
+
from asyncio import Future, ensure_future # type: ignore
|
| 11 |
+
except ImportError:
|
| 12 |
+
|
| 13 |
+
class Future: # type: ignore
|
| 14 |
+
def __init__(self):
|
| 15 |
+
raise Exception("You need asyncio for using Futures")
|
| 16 |
+
|
| 17 |
+
def set_result(self):
|
| 18 |
+
raise Exception("You need asyncio for using Futures")
|
| 19 |
+
|
| 20 |
+
def set_exception(self):
|
| 21 |
+
raise Exception("You need asyncio for using Futures")
|
| 22 |
+
|
| 23 |
+
def ensure_future(): # type: ignore
|
| 24 |
+
raise Exception("ensure_future needs asyncio for executing")
|
| 25 |
+
|
| 26 |
+
|
| 27 |
+
try:
|
| 28 |
+
from .iterate_promise import iterate_promise
|
| 29 |
+
except (SyntaxError, ImportError):
|
| 30 |
+
|
| 31 |
+
def iterate_promise(promise): # type: ignore
|
| 32 |
+
raise Exception('You need "yield from" syntax for iterate in a Promise.')
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2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collections.abc import Iterable
|
| 4 |
+
except ImportError:
|
| 5 |
+
from collections import Iterable
|
| 6 |
+
from functools import partial
|
| 7 |
+
from threading import local
|
| 8 |
+
|
| 9 |
+
from .promise import Promise, async_instance, get_default_scheduler
|
| 10 |
+
|
| 11 |
+
if False:
|
| 12 |
+
from typing import (
|
| 13 |
+
Any,
|
| 14 |
+
List,
|
| 15 |
+
Sized,
|
| 16 |
+
Callable,
|
| 17 |
+
Optional,
|
| 18 |
+
Tuple,
|
| 19 |
+
Union,
|
| 20 |
+
Iterator,
|
| 21 |
+
Hashable,
|
| 22 |
+
) # flake8: noqa
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
def get_chunks(iterable_obj, chunk_size=1):
|
| 26 |
+
# type: (List[Loader], int) -> Iterator
|
| 27 |
+
chunk_size = max(1, chunk_size)
|
| 28 |
+
return (
|
| 29 |
+
iterable_obj[i : i + chunk_size]
|
| 30 |
+
for i in range(0, len(iterable_obj), chunk_size)
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
Loader = namedtuple("Loader", "key,resolve,reject")
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
class DataLoader(local):
|
| 38 |
+
|
| 39 |
+
batch = True
|
| 40 |
+
max_batch_size = None # type: int
|
| 41 |
+
cache = True
|
| 42 |
+
|
| 43 |
+
def __init__(
|
| 44 |
+
self,
|
| 45 |
+
batch_load_fn=None, # type: Callable
|
| 46 |
+
batch=None, # type: Optional[Any]
|
| 47 |
+
max_batch_size=None, # type: Optional[int]
|
| 48 |
+
cache=None, # type: Optional[Any]
|
| 49 |
+
get_cache_key=None, # type: Optional[Any]
|
| 50 |
+
cache_map=None, # type: Optional[Any]
|
| 51 |
+
scheduler=None, # type: Optional[Any]
|
| 52 |
+
):
|
| 53 |
+
# type: (...) -> None
|
| 54 |
+
|
| 55 |
+
if batch_load_fn is not None:
|
| 56 |
+
self.batch_load_fn = batch_load_fn
|
| 57 |
+
|
| 58 |
+
if not callable(self.batch_load_fn):
|
| 59 |
+
raise TypeError(
|
| 60 |
+
(
|
| 61 |
+
"DataLoader must be have a batch_load_fn which accepts "
|
| 62 |
+
"List<key> and returns Promise<List<value>>, but got: {}."
|
| 63 |
+
).format(batch_load_fn)
|
| 64 |
+
)
|
| 65 |
+
|
| 66 |
+
if batch is not None:
|
| 67 |
+
self.batch = batch
|
| 68 |
+
|
| 69 |
+
if max_batch_size is not None:
|
| 70 |
+
self.max_batch_size = max_batch_size
|
| 71 |
+
|
| 72 |
+
if cache is not None:
|
| 73 |
+
self.cache = cache
|
| 74 |
+
|
| 75 |
+
self.get_cache_key = get_cache_key or (lambda x: x)
|
| 76 |
+
self._promise_cache = cache_map or {}
|
| 77 |
+
self._queue = [] # type: List[Loader]
|
| 78 |
+
self._scheduler = scheduler
|
| 79 |
+
|
| 80 |
+
def load(self, key=None):
|
| 81 |
+
# type: (Hashable) -> Promise
|
| 82 |
+
"""
|
| 83 |
+
Loads a key, returning a `Promise` for the value represented by that key.
|
| 84 |
+
"""
|
| 85 |
+
if key is None:
|
| 86 |
+
raise TypeError(
|
| 87 |
+
(
|
| 88 |
+
"The loader.load() function must be called with a value,"
|
| 89 |
+
+ "but got: {}."
|
| 90 |
+
).format(key)
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
cache_key = self.get_cache_key(key)
|
| 94 |
+
|
| 95 |
+
# If caching and there is a cache-hit, return cached Promise.
|
| 96 |
+
if self.cache:
|
| 97 |
+
cached_promise = self._promise_cache.get(cache_key)
|
| 98 |
+
if cached_promise:
|
| 99 |
+
return cached_promise
|
| 100 |
+
|
| 101 |
+
# Otherwise, produce a new Promise for this value.
|
| 102 |
+
|
| 103 |
+
promise = Promise(partial(self.do_resolve_reject, key)) # type: ignore
|
| 104 |
+
|
| 105 |
+
# If caching, cache this promise.
|
| 106 |
+
if self.cache:
|
| 107 |
+
self._promise_cache[cache_key] = promise
|
| 108 |
+
|
| 109 |
+
return promise
|
| 110 |
+
|
| 111 |
+
def do_resolve_reject(self, key, resolve, reject):
|
| 112 |
+
# type: (Hashable, Callable, Callable) -> None
|
| 113 |
+
# Enqueue this Promise to be dispatched.
|
| 114 |
+
self._queue.append(Loader(key=key, resolve=resolve, reject=reject))
|
| 115 |
+
# Determine if a dispatch of this queue should be scheduled.
|
| 116 |
+
# A single dispatch should be scheduled per queue at the time when the
|
| 117 |
+
# queue changes from "empty" to "full".
|
| 118 |
+
if len(self._queue) == 1:
|
| 119 |
+
if self.batch:
|
| 120 |
+
# If batching, schedule a task to dispatch the queue.
|
| 121 |
+
enqueue_post_promise_job(partial(dispatch_queue, self), self._scheduler)
|
| 122 |
+
else:
|
| 123 |
+
# Otherwise dispatch the (queue of one) immediately.
|
| 124 |
+
dispatch_queue(self)
|
| 125 |
+
|
| 126 |
+
def load_many(self, keys):
|
| 127 |
+
# type: (Iterable[Hashable]) -> Promise
|
| 128 |
+
"""
|
| 129 |
+
Loads multiple keys, promising an array of values
|
| 130 |
+
|
| 131 |
+
>>> a, b = await my_loader.load_many([ 'a', 'b' ])
|
| 132 |
+
|
| 133 |
+
This is equivalent to the more verbose:
|
| 134 |
+
|
| 135 |
+
>>> a, b = await Promise.all([
|
| 136 |
+
>>> my_loader.load('a'),
|
| 137 |
+
>>> my_loader.load('b')
|
| 138 |
+
>>> ])
|
| 139 |
+
"""
|
| 140 |
+
if not isinstance(keys, Iterable):
|
| 141 |
+
raise TypeError(
|
| 142 |
+
(
|
| 143 |
+
"The loader.loadMany() function must be called with Array<key> "
|
| 144 |
+
+ "but got: {}."
|
| 145 |
+
).format(keys)
|
| 146 |
+
)
|
| 147 |
+
|
| 148 |
+
return Promise.all([self.load(key) for key in keys])
|
| 149 |
+
|
| 150 |
+
def clear(self, key):
|
| 151 |
+
# type: (Hashable) -> DataLoader
|
| 152 |
+
"""
|
| 153 |
+
Clears the value at `key` from the cache, if it exists. Returns itself for
|
| 154 |
+
method chaining.
|
| 155 |
+
"""
|
| 156 |
+
cache_key = self.get_cache_key(key)
|
| 157 |
+
self._promise_cache.pop(cache_key, None)
|
| 158 |
+
return self
|
| 159 |
+
|
| 160 |
+
def clear_all(self):
|
| 161 |
+
# type: () -> DataLoader
|
| 162 |
+
"""
|
| 163 |
+
Clears the entire cache. To be used when some event results in unknown
|
| 164 |
+
invalidations across this particular `DataLoader`. Returns itself for
|
| 165 |
+
method chaining.
|
| 166 |
+
"""
|
| 167 |
+
self._promise_cache.clear()
|
| 168 |
+
return self
|
| 169 |
+
|
| 170 |
+
def prime(self, key, value):
|
| 171 |
+
# type: (Hashable, Any) -> DataLoader
|
| 172 |
+
"""
|
| 173 |
+
Adds the provied key and value to the cache. If the key already exists, no
|
| 174 |
+
change is made. Returns itself for method chaining.
|
| 175 |
+
"""
|
| 176 |
+
cache_key = self.get_cache_key(key)
|
| 177 |
+
|
| 178 |
+
# Only add the key if it does not already exist.
|
| 179 |
+
if cache_key not in self._promise_cache:
|
| 180 |
+
# Cache a rejected promise if the value is an Error, in order to match
|
| 181 |
+
# the behavior of load(key).
|
| 182 |
+
if isinstance(value, Exception):
|
| 183 |
+
promise = Promise.reject(value)
|
| 184 |
+
else:
|
| 185 |
+
promise = Promise.resolve(value)
|
| 186 |
+
|
| 187 |
+
self._promise_cache[cache_key] = promise
|
| 188 |
+
|
| 189 |
+
return self
|
| 190 |
+
|
| 191 |
+
|
| 192 |
+
# Private: Enqueue a Job to be executed after all "PromiseJobs" Jobs.
|
| 193 |
+
#
|
| 194 |
+
# ES6 JavaScript uses the concepts Job and JobQueue to schedule work to occur
|
| 195 |
+
# after the current execution context has completed:
|
| 196 |
+
# http://www.ecma-international.org/ecma-262/6.0/#sec-jobs-and-job-queues
|
| 197 |
+
#
|
| 198 |
+
# Node.js uses the `process.nextTick` mechanism to implement the concept of a
|
| 199 |
+
# Job, maintaining a global FIFO JobQueue for all Jobs, which is flushed after
|
| 200 |
+
# the current call stack ends.
|
| 201 |
+
#
|
| 202 |
+
# When calling `then` on a Promise, it enqueues a Job on a specific
|
| 203 |
+
# "PromiseJobs" JobQueue which is flushed in Node as a single Job on the
|
| 204 |
+
# global JobQueue.
|
| 205 |
+
#
|
| 206 |
+
# DataLoader batches all loads which occur in a single frame of execution, but
|
| 207 |
+
# should include in the batch all loads which occur during the flushing of the
|
| 208 |
+
# "PromiseJobs" JobQueue after that same execution frame.
|
| 209 |
+
#
|
| 210 |
+
# In order to avoid the DataLoader dispatch Job occuring before "PromiseJobs",
|
| 211 |
+
# A Promise Job is created with the sole purpose of enqueuing a global Job,
|
| 212 |
+
# ensuring that it always occurs after "PromiseJobs" ends.
|
| 213 |
+
|
| 214 |
+
# Private: cached resolved Promise instance
|
| 215 |
+
cache = local()
|
| 216 |
+
|
| 217 |
+
def enqueue_post_promise_job(fn, scheduler):
|
| 218 |
+
# type: (Callable, Any) -> None
|
| 219 |
+
global cache
|
| 220 |
+
if not hasattr(cache, 'resolved_promise'):
|
| 221 |
+
cache.resolved_promise = Promise.resolve(None)
|
| 222 |
+
if not scheduler:
|
| 223 |
+
scheduler = get_default_scheduler()
|
| 224 |
+
|
| 225 |
+
def on_promise_resolve(v):
|
| 226 |
+
# type: (Any) -> None
|
| 227 |
+
async_instance.invoke(fn, scheduler)
|
| 228 |
+
|
| 229 |
+
cache.resolved_promise.then(on_promise_resolve)
|
| 230 |
+
|
| 231 |
+
|
| 232 |
+
def dispatch_queue(loader):
|
| 233 |
+
# type: (DataLoader) -> None
|
| 234 |
+
"""
|
| 235 |
+
Given the current state of a Loader instance, perform a batch load
|
| 236 |
+
from its current queue.
|
| 237 |
+
"""
|
| 238 |
+
# Take the current loader queue, replacing it with an empty queue.
|
| 239 |
+
queue = loader._queue
|
| 240 |
+
loader._queue = []
|
| 241 |
+
|
| 242 |
+
# If a maxBatchSize was provided and the queue is longer, then segment the
|
| 243 |
+
# queue into multiple batches, otherwise treat the queue as a single batch.
|
| 244 |
+
max_batch_size = loader.max_batch_size
|
| 245 |
+
|
| 246 |
+
if max_batch_size and max_batch_size < len(queue):
|
| 247 |
+
chunks = get_chunks(queue, max_batch_size)
|
| 248 |
+
for chunk in chunks:
|
| 249 |
+
dispatch_queue_batch(loader, chunk)
|
| 250 |
+
else:
|
| 251 |
+
dispatch_queue_batch(loader, queue)
|
| 252 |
+
|
| 253 |
+
|
| 254 |
+
def dispatch_queue_batch(loader, queue):
|
| 255 |
+
# type: (DataLoader, List[Loader]) -> None
|
| 256 |
+
# Collect all keys to be loaded in this dispatch
|
| 257 |
+
keys = [l.key for l in queue]
|
| 258 |
+
|
| 259 |
+
# Call the provided batch_load_fn for this loader with the loader queue's keys.
|
| 260 |
+
try:
|
| 261 |
+
batch_promise = loader.batch_load_fn(keys)
|
| 262 |
+
except Exception as e:
|
| 263 |
+
failed_dispatch(loader, queue, e)
|
| 264 |
+
return None
|
| 265 |
+
|
| 266 |
+
# Assert the expected response from batch_load_fn
|
| 267 |
+
if not batch_promise or not isinstance(batch_promise, Promise):
|
| 268 |
+
failed_dispatch(
|
| 269 |
+
loader,
|
| 270 |
+
queue,
|
| 271 |
+
TypeError(
|
| 272 |
+
(
|
| 273 |
+
"DataLoader must be constructed with a function which accepts "
|
| 274 |
+
"Array<key> and returns Promise<Array<value>>, but the function did "
|
| 275 |
+
"not return a Promise: {}."
|
| 276 |
+
).format(batch_promise)
|
| 277 |
+
),
|
| 278 |
+
)
|
| 279 |
+
return None
|
| 280 |
+
|
| 281 |
+
def batch_promise_resolved(values):
|
| 282 |
+
# type: (Sized) -> None
|
| 283 |
+
# Assert the expected resolution from batchLoadFn.
|
| 284 |
+
if not isinstance(values, Iterable):
|
| 285 |
+
raise TypeError(
|
| 286 |
+
(
|
| 287 |
+
"DataLoader must be constructed with a function which accepts "
|
| 288 |
+
"Array<key> and returns Promise<Array<value>>, but the function did "
|
| 289 |
+
"not return a Promise of an Array: {}."
|
| 290 |
+
).format(values)
|
| 291 |
+
)
|
| 292 |
+
|
| 293 |
+
if len(values) != len(keys):
|
| 294 |
+
raise TypeError(
|
| 295 |
+
(
|
| 296 |
+
"DataLoader must be constructed with a function which accepts "
|
| 297 |
+
"Array<key> and returns Promise<Array<value>>, but the function did "
|
| 298 |
+
"not return a Promise of an Array of the same length as the Array "
|
| 299 |
+
"of keys."
|
| 300 |
+
"\n\nKeys:\n{}"
|
| 301 |
+
"\n\nValues:\n{}"
|
| 302 |
+
).format(keys, values)
|
| 303 |
+
)
|
| 304 |
+
|
| 305 |
+
# Step through the values, resolving or rejecting each Promise in the
|
| 306 |
+
# loaded queue.
|
| 307 |
+
for l, value in zip(queue, values):
|
| 308 |
+
if isinstance(value, Exception):
|
| 309 |
+
l.reject(value)
|
| 310 |
+
else:
|
| 311 |
+
l.resolve(value)
|
| 312 |
+
|
| 313 |
+
batch_promise.then(batch_promise_resolved).catch(
|
| 314 |
+
partial(failed_dispatch, loader, queue)
|
| 315 |
+
)
|
| 316 |
+
|
| 317 |
+
|
| 318 |
+
def failed_dispatch(loader, queue, error):
|
| 319 |
+
# type: (DataLoader, Iterable[Loader], Exception) -> None
|
| 320 |
+
"""
|
| 321 |
+
Do not cache individual loads if the entire batch dispatch fails,
|
| 322 |
+
but still reject each request so they do not hang.
|
| 323 |
+
"""
|
| 324 |
+
for l in queue:
|
| 325 |
+
loader.clear(l.key)
|
| 326 |
+
l.reject(error)
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/iterate_promise.py
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# flake8: noqa
|
| 2 |
+
if False:
|
| 3 |
+
from .promise import Promise
|
| 4 |
+
from typing import Iterator
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def iterate_promise(promise):
|
| 8 |
+
# type: (Promise) -> Iterator
|
| 9 |
+
if not promise.is_fulfilled:
|
| 10 |
+
yield from promise.future # type: ignore
|
| 11 |
+
assert promise.is_fulfilled
|
| 12 |
+
return promise.get()
|
vllm/lib/python3.10/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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from collections import namedtuple
|
| 2 |
+
from functools import partial, wraps
|
| 3 |
+
from sys import version_info, exc_info
|
| 4 |
+
from threading import RLock
|
| 5 |
+
from types import TracebackType
|
| 6 |
+
from weakref import WeakKeyDictionary
|
| 7 |
+
|
| 8 |
+
from .async_ import Async
|
| 9 |
+
from .compat import (
|
| 10 |
+
Future,
|
| 11 |
+
ensure_future,
|
| 12 |
+
iscoroutine, # type: ignore
|
| 13 |
+
iterate_promise,
|
| 14 |
+
) # type: ignore
|
| 15 |
+
from .utils import deprecated, integer_types, string_types, text_type, binary_type, warn
|
| 16 |
+
from .promise_list import PromiseList
|
| 17 |
+
from .schedulers.immediate import ImmediateScheduler
|
| 18 |
+
from typing import TypeVar, Generic
|
| 19 |
+
|
| 20 |
+
# from .schedulers.gevent import GeventScheduler
|
| 21 |
+
# from .schedulers.asyncio import AsyncioScheduler
|
| 22 |
+
# from .schedulers.thread import ThreadScheduler
|
| 23 |
+
|
| 24 |
+
if False:
|
| 25 |
+
from typing import (
|
| 26 |
+
Type,
|
| 27 |
+
List,
|
| 28 |
+
Any,
|
| 29 |
+
Callable,
|
| 30 |
+
Dict,
|
| 31 |
+
Iterator,
|
| 32 |
+
Optional, # flake8: noqa
|
| 33 |
+
Tuple,
|
| 34 |
+
Union,
|
| 35 |
+
Generic,
|
| 36 |
+
Hashable,
|
| 37 |
+
MutableMapping,
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
default_scheduler = ImmediateScheduler()
|
| 42 |
+
|
| 43 |
+
async_instance = Async()
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
def get_default_scheduler():
|
| 47 |
+
# type: () -> ImmediateScheduler
|
| 48 |
+
return default_scheduler
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
def set_default_scheduler(scheduler):
|
| 52 |
+
global default_scheduler
|
| 53 |
+
default_scheduler = scheduler
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
IS_PYTHON2 = version_info[0] == 2
|
| 57 |
+
DEFAULT_TIMEOUT = None # type: Optional[float]
|
| 58 |
+
|
| 59 |
+
MAX_LENGTH = 0xFFFF | 0
|
| 60 |
+
CALLBACK_SIZE = 3
|
| 61 |
+
|
| 62 |
+
CALLBACK_FULFILL_OFFSET = 0
|
| 63 |
+
CALLBACK_REJECT_OFFSET = 1
|
| 64 |
+
CALLBACK_PROMISE_OFFSET = 2
|
| 65 |
+
|
| 66 |
+
BASE_TYPES = set(
|
| 67 |
+
integer_types
|
| 68 |
+
+ string_types
|
| 69 |
+
+ (bool, float, complex, tuple, list, dict, text_type, binary_type)
|
| 70 |
+
)
|
| 71 |
+
|
| 72 |
+
# These are the potential states of a promise
|
| 73 |
+
STATE_PENDING = -1
|
| 74 |
+
STATE_REJECTED = 0
|
| 75 |
+
STATE_FULFILLED = 1
|
| 76 |
+
|
| 77 |
+
|
| 78 |
+
def make_self_resolution_error():
|
| 79 |
+
# type: () -> TypeError
|
| 80 |
+
return TypeError("Promise is self")
|
| 81 |
+
|
| 82 |
+
|
| 83 |
+
def try_catch(handler, *args, **kwargs):
|
| 84 |
+
# type: (Callable, Any, Any) -> Union[Tuple[Any, None], Tuple[None, Tuple[Exception, Optional[TracebackType]]]]
|
| 85 |
+
try:
|
| 86 |
+
return (handler(*args, **kwargs), None)
|
| 87 |
+
except Exception as e:
|
| 88 |
+
tb = exc_info()[2]
|
| 89 |
+
return (None, (e, tb))
|
| 90 |
+
|
| 91 |
+
|
| 92 |
+
T = TypeVar("T")
|
| 93 |
+
S = TypeVar("S", contravariant=True)
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
class Promise(Generic[T]):
|
| 97 |
+
"""
|
| 98 |
+
This is the Promise class that complies
|
| 99 |
+
Promises/A+ specification.
|
| 100 |
+
"""
|
| 101 |
+
|
| 102 |
+
# __slots__ = ('_state', '_is_final', '_is_bound', '_is_following', '_is_async_guaranteed',
|
| 103 |
+
# '_length', '_handlers', '_fulfillment_handler0', '_rejection_handler0', '_promise0',
|
| 104 |
+
# '_is_waiting', '_future', '_trace', '_event_instance'
|
| 105 |
+
# )
|
| 106 |
+
|
| 107 |
+
_state = STATE_PENDING # type: int
|
| 108 |
+
_is_final = False
|
| 109 |
+
_is_bound = False
|
| 110 |
+
_is_following = False
|
| 111 |
+
_is_async_guaranteed = False
|
| 112 |
+
_length = 0
|
| 113 |
+
_handlers = None # type: Dict[int, Union[Callable, Promise, None]]
|
| 114 |
+
_fulfillment_handler0 = None # type: Any
|
| 115 |
+
_rejection_handler0 = None # type: Any
|
| 116 |
+
_promise0 = None # type: Optional[Promise]
|
| 117 |
+
_future = None # type: Future
|
| 118 |
+
_traceback = None # type: Optional[TracebackType]
|
| 119 |
+
# _trace = None
|
| 120 |
+
_is_waiting = False
|
| 121 |
+
_scheduler = None
|
| 122 |
+
|
| 123 |
+
def __init__(self, executor=None, scheduler=None):
|
| 124 |
+
# type: (Optional[Callable[[Callable[[T], None], Callable[[Exception], None]], None]], Any) -> None
|
| 125 |
+
"""
|
| 126 |
+
Initialize the Promise into a pending state.
|
| 127 |
+
"""
|
| 128 |
+
# self._state = STATE_PENDING # type: int
|
| 129 |
+
# self._is_final = False
|
| 130 |
+
# self._is_bound = False
|
| 131 |
+
# self._is_following = False
|
| 132 |
+
# self._is_async_guaranteed = False
|
| 133 |
+
# self._length = 0
|
| 134 |
+
# self._handlers = None # type: Dict[int, Union[Callable, None]]
|
| 135 |
+
# self._fulfillment_handler0 = None # type: Union[Callable, partial]
|
| 136 |
+
# self._rejection_handler0 = None # type: Union[Callable, partial]
|
| 137 |
+
# self._promise0 = None # type: Promise
|
| 138 |
+
# self._future = None # type: Future
|
| 139 |
+
# self._event_instance = None # type: Event
|
| 140 |
+
|
| 141 |
+
# self._is_waiting = False
|
| 142 |
+
self._scheduler = scheduler
|
| 143 |
+
|
| 144 |
+
if executor is not None:
|
| 145 |
+
self._resolve_from_executor(executor)
|
| 146 |
+
|
| 147 |
+
# For compatibility reasons
|
| 148 |
+
# self.reject = self._deprecated_reject
|
| 149 |
+
# self.resolve = self._deprecated_resolve
|
| 150 |
+
|
| 151 |
+
@property
|
| 152 |
+
def scheduler(self):
|
| 153 |
+
# type: () -> ImmediateScheduler
|
| 154 |
+
return self._scheduler or default_scheduler
|
| 155 |
+
|
| 156 |
+
@property
|
| 157 |
+
def future(self):
|
| 158 |
+
# type: (Promise) -> Future
|
| 159 |
+
if not self._future:
|
| 160 |
+
self._future = Future() # type: ignore
|
| 161 |
+
self._then( # type: ignore
|
| 162 |
+
self._future.set_result, self._future.set_exception
|
| 163 |
+
)
|
| 164 |
+
return self._future
|
| 165 |
+
|
| 166 |
+
def __iter__(self):
|
| 167 |
+
# type: () -> Iterator
|
| 168 |
+
return iterate_promise(self._target()) # type: ignore
|
| 169 |
+
|
| 170 |
+
__await__ = __iter__
|
| 171 |
+
|
| 172 |
+
@deprecated(
|
| 173 |
+
"Rejecting directly in a Promise instance is deprecated, as Promise.reject() is now a class method. "
|
| 174 |
+
"Please use promise.do_reject() instead.",
|
| 175 |
+
name="reject",
|
| 176 |
+
)
|
| 177 |
+
def _deprecated_reject(self, e):
|
| 178 |
+
self.do_reject(e)
|
| 179 |
+
|
| 180 |
+
@deprecated(
|
| 181 |
+
"Resolving directly in a Promise instance is deprecated, as Promise.resolve() is now a class method. "
|
| 182 |
+
"Please use promise.do_resolve() instead.",
|
| 183 |
+
name="resolve",
|
| 184 |
+
)
|
| 185 |
+
def _deprecated_resolve(self, value):
|
| 186 |
+
self.do_resolve(value)
|
| 187 |
+
|
| 188 |
+
def _resolve_callback(self, value):
|
| 189 |
+
# type: (T) -> None
|
| 190 |
+
if value is self:
|
| 191 |
+
return self._reject_callback(make_self_resolution_error(), False)
|
| 192 |
+
|
| 193 |
+
if not self.is_thenable(value):
|
| 194 |
+
return self._fulfill(value)
|
| 195 |
+
|
| 196 |
+
promise = self._try_convert_to_promise(value)._target()
|
| 197 |
+
if promise == self:
|
| 198 |
+
self._reject(make_self_resolution_error())
|
| 199 |
+
return
|
| 200 |
+
|
| 201 |
+
if promise._state == STATE_PENDING:
|
| 202 |
+
len = self._length
|
| 203 |
+
if len > 0:
|
| 204 |
+
promise._migrate_callback0(self)
|
| 205 |
+
for i in range(1, len):
|
| 206 |
+
promise._migrate_callback_at(self, i)
|
| 207 |
+
|
| 208 |
+
self._is_following = True
|
| 209 |
+
self._length = 0
|
| 210 |
+
self._set_followee(promise)
|
| 211 |
+
elif promise._state == STATE_FULFILLED:
|
| 212 |
+
self._fulfill(promise._value())
|
| 213 |
+
elif promise._state == STATE_REJECTED:
|
| 214 |
+
self._reject(promise._reason(), promise._target()._traceback)
|
| 215 |
+
|
| 216 |
+
def _settled_value(self, _raise=False):
|
| 217 |
+
# type: (bool) -> Any
|
| 218 |
+
assert not self._is_following
|
| 219 |
+
|
| 220 |
+
if self._state == STATE_FULFILLED:
|
| 221 |
+
return self._rejection_handler0
|
| 222 |
+
elif self._state == STATE_REJECTED:
|
| 223 |
+
if _raise:
|
| 224 |
+
raise_val = self._fulfillment_handler0
|
| 225 |
+
raise raise_val.with_traceback(self._traceback)
|
| 226 |
+
return self._fulfillment_handler0
|
| 227 |
+
|
| 228 |
+
def _fulfill(self, value):
|
| 229 |
+
# type: (T) -> None
|
| 230 |
+
if value is self:
|
| 231 |
+
err = make_self_resolution_error()
|
| 232 |
+
# self._attach_extratrace(err)
|
| 233 |
+
return self._reject(err)
|
| 234 |
+
self._state = STATE_FULFILLED
|
| 235 |
+
self._rejection_handler0 = value
|
| 236 |
+
|
| 237 |
+
if self._length > 0:
|
| 238 |
+
if self._is_async_guaranteed:
|
| 239 |
+
self._settle_promises()
|
| 240 |
+
else:
|
| 241 |
+
async_instance.settle_promises(self)
|
| 242 |
+
|
| 243 |
+
def _reject(self, reason, traceback=None):
|
| 244 |
+
# type: (Exception, Optional[TracebackType]) -> None
|
| 245 |
+
self._state = STATE_REJECTED
|
| 246 |
+
self._fulfillment_handler0 = reason
|
| 247 |
+
self._traceback = traceback
|
| 248 |
+
|
| 249 |
+
if self._is_final:
|
| 250 |
+
assert self._length == 0
|
| 251 |
+
async_instance.fatal_error(reason, self.scheduler)
|
| 252 |
+
return
|
| 253 |
+
|
| 254 |
+
if self._length > 0:
|
| 255 |
+
async_instance.settle_promises(self)
|
| 256 |
+
else:
|
| 257 |
+
self._ensure_possible_rejection_handled()
|
| 258 |
+
|
| 259 |
+
if self._is_async_guaranteed:
|
| 260 |
+
self._settle_promises()
|
| 261 |
+
else:
|
| 262 |
+
async_instance.settle_promises(self)
|
| 263 |
+
|
| 264 |
+
def _ensure_possible_rejection_handled(self):
|
| 265 |
+
# type: () -> None
|
| 266 |
+
# self._rejection_is_unhandled = True
|
| 267 |
+
# async_instance.invoke_later(self._notify_unhandled_rejection, self)
|
| 268 |
+
pass
|
| 269 |
+
|
| 270 |
+
def _reject_callback(self, reason, synchronous=False, traceback=None):
|
| 271 |
+
# type: (Exception, bool, Optional[TracebackType]) -> None
|
| 272 |
+
assert isinstance(
|
| 273 |
+
reason, Exception
|
| 274 |
+
), "A promise was rejected with a non-error: {}".format(reason)
|
| 275 |
+
# trace = ensure_error_object(reason)
|
| 276 |
+
# has_stack = trace is reason
|
| 277 |
+
# self._attach_extratrace(trace, synchronous and has_stack)
|
| 278 |
+
self._reject(reason, traceback)
|
| 279 |
+
|
| 280 |
+
def _clear_callback_data_index_at(self, index):
|
| 281 |
+
# type: (int) -> None
|
| 282 |
+
assert not self._is_following
|
| 283 |
+
assert index > 0
|
| 284 |
+
base = index * CALLBACK_SIZE - CALLBACK_SIZE
|
| 285 |
+
self._handlers[base + CALLBACK_PROMISE_OFFSET] = None
|
| 286 |
+
self._handlers[base + CALLBACK_FULFILL_OFFSET] = None
|
| 287 |
+
self._handlers[base + CALLBACK_REJECT_OFFSET] = None
|
| 288 |
+
|
| 289 |
+
def _fulfill_promises(self, length, value):
|
| 290 |
+
# type: (int, T) -> None
|
| 291 |
+
for i in range(1, length):
|
| 292 |
+
handler = self._fulfillment_handler_at(i)
|
| 293 |
+
promise = self._promise_at(i)
|
| 294 |
+
self._clear_callback_data_index_at(i)
|
| 295 |
+
self._settle_promise(promise, handler, value, None)
|
| 296 |
+
|
| 297 |
+
def _reject_promises(self, length, reason):
|
| 298 |
+
# type: (int, Exception) -> None
|
| 299 |
+
for i in range(1, length):
|
| 300 |
+
handler = self._rejection_handler_at(i)
|
| 301 |
+
promise = self._promise_at(i)
|
| 302 |
+
self._clear_callback_data_index_at(i)
|
| 303 |
+
self._settle_promise(promise, handler, reason, None)
|
| 304 |
+
|
| 305 |
+
def _settle_promise(
|
| 306 |
+
self,
|
| 307 |
+
promise, # type: Optional[Promise]
|
| 308 |
+
handler, # type: Optional[Callable]
|
| 309 |
+
value, # type: Union[T, Exception]
|
| 310 |
+
traceback, # type: Optional[TracebackType]
|
| 311 |
+
):
|
| 312 |
+
# type: (...) -> None
|
| 313 |
+
assert not self._is_following
|
| 314 |
+
is_promise = isinstance(promise, self.__class__)
|
| 315 |
+
async_guaranteed = self._is_async_guaranteed
|
| 316 |
+
if callable(handler):
|
| 317 |
+
if not is_promise:
|
| 318 |
+
handler(value) # , promise
|
| 319 |
+
else:
|
| 320 |
+
if async_guaranteed:
|
| 321 |
+
promise._is_async_guaranteed = True # type: ignore
|
| 322 |
+
self._settle_promise_from_handler( # type: ignore
|
| 323 |
+
handler, value, promise # type: ignore
|
| 324 |
+
) # type: ignore
|
| 325 |
+
elif is_promise:
|
| 326 |
+
if async_guaranteed:
|
| 327 |
+
promise._is_async_guaranteed = True # type: ignore
|
| 328 |
+
if self._state == STATE_FULFILLED:
|
| 329 |
+
promise._fulfill(value) # type: ignore
|
| 330 |
+
else:
|
| 331 |
+
promise._reject(value, self._traceback) # type: ignore
|
| 332 |
+
|
| 333 |
+
def _settle_promise0(
|
| 334 |
+
self,
|
| 335 |
+
handler, # type: Optional[Callable]
|
| 336 |
+
value, # type: Any
|
| 337 |
+
traceback, # type: Optional[TracebackType]
|
| 338 |
+
):
|
| 339 |
+
# type: (...) -> None
|
| 340 |
+
promise = self._promise0
|
| 341 |
+
self._promise0 = None
|
| 342 |
+
self._settle_promise(promise, handler, value, traceback) # type: ignore
|
| 343 |
+
|
| 344 |
+
def _settle_promise_from_handler(self, handler, value, promise):
|
| 345 |
+
# type: (Callable, Any, Promise) -> None
|
| 346 |
+
value, error_with_tb = try_catch(handler, value) # , promise
|
| 347 |
+
|
| 348 |
+
if error_with_tb:
|
| 349 |
+
error, tb = error_with_tb
|
| 350 |
+
promise._reject_callback(error, False, tb)
|
| 351 |
+
else:
|
| 352 |
+
promise._resolve_callback(value)
|
| 353 |
+
|
| 354 |
+
def _promise_at(self, index):
|
| 355 |
+
# type: (int) -> Optional[Promise]
|
| 356 |
+
assert index > 0
|
| 357 |
+
assert not self._is_following
|
| 358 |
+
return self._handlers.get( # type: ignore
|
| 359 |
+
index * CALLBACK_SIZE - CALLBACK_SIZE + CALLBACK_PROMISE_OFFSET
|
| 360 |
+
)
|
| 361 |
+
|
| 362 |
+
def _fulfillment_handler_at(self, index):
|
| 363 |
+
# type: (int) -> Optional[Callable]
|
| 364 |
+
assert not self._is_following
|
| 365 |
+
assert index > 0
|
| 366 |
+
return self._handlers.get( # type: ignore
|
| 367 |
+
index * CALLBACK_SIZE - CALLBACK_SIZE + CALLBACK_FULFILL_OFFSET
|
| 368 |
+
)
|
| 369 |
+
|
| 370 |
+
def _rejection_handler_at(self, index):
|
| 371 |
+
# type: (int) -> Optional[Callable]
|
| 372 |
+
assert not self._is_following
|
| 373 |
+
assert index > 0
|
| 374 |
+
return self._handlers.get( # type: ignore
|
| 375 |
+
index * CALLBACK_SIZE - CALLBACK_SIZE + CALLBACK_REJECT_OFFSET
|
| 376 |
+
)
|
| 377 |
+
|
| 378 |
+
def _migrate_callback0(self, follower):
|
| 379 |
+
# type: (Promise) -> None
|
| 380 |
+
self._add_callbacks(
|
| 381 |
+
follower._fulfillment_handler0,
|
| 382 |
+
follower._rejection_handler0,
|
| 383 |
+
follower._promise0,
|
| 384 |
+
)
|
| 385 |
+
|
| 386 |
+
def _migrate_callback_at(self, follower, index):
|
| 387 |
+
self._add_callbacks(
|
| 388 |
+
follower._fulfillment_handler_at(index),
|
| 389 |
+
follower._rejection_handler_at(index),
|
| 390 |
+
follower._promise_at(index),
|
| 391 |
+
)
|
| 392 |
+
|
| 393 |
+
def _add_callbacks(
|
| 394 |
+
self,
|
| 395 |
+
fulfill, # type: Optional[Callable]
|
| 396 |
+
reject, # type: Optional[Callable]
|
| 397 |
+
promise, # type: Optional[Promise]
|
| 398 |
+
):
|
| 399 |
+
# type: (...) -> int
|
| 400 |
+
assert not self._is_following
|
| 401 |
+
|
| 402 |
+
if self._handlers is None:
|
| 403 |
+
self._handlers = {}
|
| 404 |
+
|
| 405 |
+
index = self._length
|
| 406 |
+
if index > MAX_LENGTH - CALLBACK_SIZE:
|
| 407 |
+
index = 0
|
| 408 |
+
self._length = 0
|
| 409 |
+
|
| 410 |
+
if index == 0:
|
| 411 |
+
assert not self._promise0
|
| 412 |
+
assert not self._fulfillment_handler0
|
| 413 |
+
assert not self._rejection_handler0
|
| 414 |
+
|
| 415 |
+
self._promise0 = promise
|
| 416 |
+
if callable(fulfill):
|
| 417 |
+
self._fulfillment_handler0 = fulfill
|
| 418 |
+
if callable(reject):
|
| 419 |
+
self._rejection_handler0 = reject
|
| 420 |
+
|
| 421 |
+
else:
|
| 422 |
+
base = index * CALLBACK_SIZE - CALLBACK_SIZE
|
| 423 |
+
|
| 424 |
+
assert (base + CALLBACK_PROMISE_OFFSET) not in self._handlers
|
| 425 |
+
assert (base + CALLBACK_FULFILL_OFFSET) not in self._handlers
|
| 426 |
+
assert (base + CALLBACK_REJECT_OFFSET) not in self._handlers
|
| 427 |
+
|
| 428 |
+
self._handlers[base + CALLBACK_PROMISE_OFFSET] = promise
|
| 429 |
+
if callable(fulfill):
|
| 430 |
+
self._handlers[base + CALLBACK_FULFILL_OFFSET] = fulfill
|
| 431 |
+
if callable(reject):
|
| 432 |
+
self._handlers[base + CALLBACK_REJECT_OFFSET] = reject
|
| 433 |
+
|
| 434 |
+
self._length = index + 1
|
| 435 |
+
return index
|
| 436 |
+
|
| 437 |
+
def _target(self):
|
| 438 |
+
# type: () -> Promise
|
| 439 |
+
ret = self
|
| 440 |
+
while ret._is_following:
|
| 441 |
+
ret = ret._followee()
|
| 442 |
+
return ret
|
| 443 |
+
|
| 444 |
+
def _followee(self):
|
| 445 |
+
# type: () -> Promise
|
| 446 |
+
assert self._is_following
|
| 447 |
+
assert isinstance(self._rejection_handler0, Promise)
|
| 448 |
+
return self._rejection_handler0
|
| 449 |
+
|
| 450 |
+
def _set_followee(self, promise):
|
| 451 |
+
# type: (Promise) -> None
|
| 452 |
+
assert self._is_following
|
| 453 |
+
assert not isinstance(self._rejection_handler0, Promise)
|
| 454 |
+
self._rejection_handler0 = promise
|
| 455 |
+
|
| 456 |
+
def _settle_promises(self):
|
| 457 |
+
# type: () -> None
|
| 458 |
+
length = self._length
|
| 459 |
+
if length > 0:
|
| 460 |
+
if self._state == STATE_REJECTED:
|
| 461 |
+
reason = self._fulfillment_handler0
|
| 462 |
+
traceback = self._traceback
|
| 463 |
+
self._settle_promise0(self._rejection_handler0, reason, traceback)
|
| 464 |
+
self._reject_promises(length, reason)
|
| 465 |
+
else:
|
| 466 |
+
value = self._rejection_handler0
|
| 467 |
+
self._settle_promise0(self._fulfillment_handler0, value, None)
|
| 468 |
+
self._fulfill_promises(length, value)
|
| 469 |
+
|
| 470 |
+
self._length = 0
|
| 471 |
+
|
| 472 |
+
def _resolve_from_executor(self, executor):
|
| 473 |
+
# type: (Callable[[Callable[[T], None], Callable[[Exception], None]], None]) -> None
|
| 474 |
+
# self._capture_stacktrace()
|
| 475 |
+
synchronous = True
|
| 476 |
+
|
| 477 |
+
def resolve(value):
|
| 478 |
+
# type: (T) -> None
|
| 479 |
+
self._resolve_callback(value)
|
| 480 |
+
|
| 481 |
+
def reject(reason, traceback=None):
|
| 482 |
+
# type: (Exception, TracebackType) -> None
|
| 483 |
+
self._reject_callback(reason, synchronous, traceback)
|
| 484 |
+
|
| 485 |
+
error = None
|
| 486 |
+
traceback = None
|
| 487 |
+
try:
|
| 488 |
+
executor(resolve, reject)
|
| 489 |
+
except Exception as e:
|
| 490 |
+
traceback = exc_info()[2]
|
| 491 |
+
error = e
|
| 492 |
+
|
| 493 |
+
synchronous = False
|
| 494 |
+
|
| 495 |
+
if error is not None:
|
| 496 |
+
self._reject_callback(error, True, traceback)
|
| 497 |
+
|
| 498 |
+
@classmethod
|
| 499 |
+
def wait(cls, promise, timeout=None):
|
| 500 |
+
# type: (Promise, Optional[float]) -> None
|
| 501 |
+
async_instance.wait(promise, timeout)
|
| 502 |
+
|
| 503 |
+
def _wait(self, timeout=None):
|
| 504 |
+
# type: (Optional[float]) -> None
|
| 505 |
+
self.wait(self, timeout)
|
| 506 |
+
|
| 507 |
+
def get(self, timeout=None):
|
| 508 |
+
# type: (Optional[float]) -> T
|
| 509 |
+
target = self._target()
|
| 510 |
+
self._wait(timeout or DEFAULT_TIMEOUT)
|
| 511 |
+
return self._target_settled_value(_raise=True)
|
| 512 |
+
|
| 513 |
+
def _target_settled_value(self, _raise=False):
|
| 514 |
+
# type: (bool) -> Any
|
| 515 |
+
return self._target()._settled_value(_raise)
|
| 516 |
+
|
| 517 |
+
_value = _reason = _target_settled_value
|
| 518 |
+
value = reason = property(_target_settled_value)
|
| 519 |
+
|
| 520 |
+
def __repr__(self):
|
| 521 |
+
# type: () -> str
|
| 522 |
+
hex_id = hex(id(self))
|
| 523 |
+
if self._is_following:
|
| 524 |
+
return "<Promise at {} following {}>".format(hex_id, self._target())
|
| 525 |
+
state = self._state
|
| 526 |
+
if state == STATE_PENDING:
|
| 527 |
+
return "<Promise at {} pending>".format(hex_id)
|
| 528 |
+
elif state == STATE_FULFILLED:
|
| 529 |
+
return "<Promise at {} fulfilled with {}>".format(
|
| 530 |
+
hex_id, repr(self._rejection_handler0)
|
| 531 |
+
)
|
| 532 |
+
elif state == STATE_REJECTED:
|
| 533 |
+
return "<Promise at {} rejected with {}>".format(
|
| 534 |
+
hex_id, repr(self._fulfillment_handler0)
|
| 535 |
+
)
|
| 536 |
+
|
| 537 |
+
return "<Promise unknown>"
|
| 538 |
+
|
| 539 |
+
@property
|
| 540 |
+
def is_pending(self):
|
| 541 |
+
# type: (Promise) -> bool
|
| 542 |
+
"""Indicate whether the Promise is still pending. Could be wrong the moment the function returns."""
|
| 543 |
+
return self._target()._state == STATE_PENDING
|
| 544 |
+
|
| 545 |
+
@property
|
| 546 |
+
def is_fulfilled(self):
|
| 547 |
+
# type: (Promise) -> bool
|
| 548 |
+
"""Indicate whether the Promise has been fulfilled. Could be wrong the moment the function returns."""
|
| 549 |
+
return self._target()._state == STATE_FULFILLED
|
| 550 |
+
|
| 551 |
+
@property
|
| 552 |
+
def is_rejected(self):
|
| 553 |
+
# type: (Promise) -> bool
|
| 554 |
+
"""Indicate whether the Promise has been rejected. Could be wrong the moment the function returns."""
|
| 555 |
+
return self._target()._state == STATE_REJECTED
|
| 556 |
+
|
| 557 |
+
def catch(self, on_rejection):
|
| 558 |
+
# type: (Promise, Callable[[Exception], Any]) -> Promise
|
| 559 |
+
"""
|
| 560 |
+
This method returns a Promise and deals with rejected cases only.
|
| 561 |
+
It behaves the same as calling Promise.then(None, on_rejection).
|
| 562 |
+
"""
|
| 563 |
+
return self.then(None, on_rejection)
|
| 564 |
+
|
| 565 |
+
def _then(
|
| 566 |
+
self,
|
| 567 |
+
did_fulfill=None, # type: Optional[Callable[[T], S]]
|
| 568 |
+
did_reject=None, # type: Optional[Callable[[Exception], S]]
|
| 569 |
+
):
|
| 570 |
+
# type: (...) -> Promise[S]
|
| 571 |
+
promise = self.__class__() # type: Promise
|
| 572 |
+
target = self._target()
|
| 573 |
+
|
| 574 |
+
state = target._state
|
| 575 |
+
if state == STATE_PENDING:
|
| 576 |
+
target._add_callbacks(did_fulfill, did_reject, promise)
|
| 577 |
+
else:
|
| 578 |
+
traceback = None
|
| 579 |
+
if state == STATE_FULFILLED:
|
| 580 |
+
value = target._rejection_handler0
|
| 581 |
+
handler = did_fulfill
|
| 582 |
+
elif state == STATE_REJECTED:
|
| 583 |
+
value = target._fulfillment_handler0
|
| 584 |
+
traceback = target._traceback
|
| 585 |
+
handler = did_reject # type: ignore
|
| 586 |
+
# target._rejection_is_unhandled = False
|
| 587 |
+
async_instance.invoke(
|
| 588 |
+
partial(target._settle_promise, promise, handler, value, traceback),
|
| 589 |
+
promise.scheduler
|
| 590 |
+
# target._settle_promise instead?
|
| 591 |
+
# settler,
|
| 592 |
+
# target,
|
| 593 |
+
)
|
| 594 |
+
|
| 595 |
+
return promise
|
| 596 |
+
|
| 597 |
+
fulfill = _resolve_callback
|
| 598 |
+
do_resolve = _resolve_callback
|
| 599 |
+
do_reject = _reject_callback
|
| 600 |
+
|
| 601 |
+
def then(self, did_fulfill=None, did_reject=None):
|
| 602 |
+
# type: (Promise, Callable[[T], S], Optional[Callable[[Exception], S]]) -> Promise[S]
|
| 603 |
+
"""
|
| 604 |
+
This method takes two optional arguments. The first argument
|
| 605 |
+
is used if the "self promise" is fulfilled and the other is
|
| 606 |
+
used if the "self promise" is rejected. In either case, this
|
| 607 |
+
method returns another promise that effectively represents
|
| 608 |
+
the result of either the first of the second argument (in the
|
| 609 |
+
case that the "self promise" is fulfilled or rejected,
|
| 610 |
+
respectively).
|
| 611 |
+
Each argument can be either:
|
| 612 |
+
* None - Meaning no action is taken
|
| 613 |
+
* A function - which will be called with either the value
|
| 614 |
+
of the "self promise" or the reason for rejection of
|
| 615 |
+
the "self promise". The function may return:
|
| 616 |
+
* A value - which will be used to fulfill the promise
|
| 617 |
+
returned by this method.
|
| 618 |
+
* A promise - which, when fulfilled or rejected, will
|
| 619 |
+
cascade its value or reason to the promise returned
|
| 620 |
+
by this method.
|
| 621 |
+
* A value - which will be assigned as either the value
|
| 622 |
+
or the reason for the promise returned by this method
|
| 623 |
+
when the "self promise" is either fulfilled or rejected,
|
| 624 |
+
respectively.
|
| 625 |
+
:type success: (Any) -> object
|
| 626 |
+
:type failure: (Any) -> object
|
| 627 |
+
:rtype : Promise
|
| 628 |
+
"""
|
| 629 |
+
return self._then(did_fulfill, did_reject)
|
| 630 |
+
|
| 631 |
+
def done(self, did_fulfill=None, did_reject=None):
|
| 632 |
+
# type: (Optional[Callable], Optional[Callable]) -> None
|
| 633 |
+
promise = self._then(did_fulfill, did_reject)
|
| 634 |
+
promise._is_final = True
|
| 635 |
+
|
| 636 |
+
def done_all(self, handlers=None):
|
| 637 |
+
# type: (Promise, Optional[List[Union[Dict[str, Optional[Callable]], Tuple[Callable, Callable], Callable]]]) -> None
|
| 638 |
+
"""
|
| 639 |
+
:type handlers: list[(Any) -> object] | list[((Any) -> object, (Any) -> object)]
|
| 640 |
+
"""
|
| 641 |
+
if not handlers:
|
| 642 |
+
return
|
| 643 |
+
|
| 644 |
+
for handler in handlers:
|
| 645 |
+
if isinstance(handler, tuple):
|
| 646 |
+
s, f = handler
|
| 647 |
+
self.done(s, f)
|
| 648 |
+
elif isinstance(handler, dict):
|
| 649 |
+
s = handler.get("success") # type: ignore
|
| 650 |
+
f = handler.get("failure") # type: ignore
|
| 651 |
+
|
| 652 |
+
self.done(s, f)
|
| 653 |
+
else:
|
| 654 |
+
self.done(handler)
|
| 655 |
+
|
| 656 |
+
def then_all(self, handlers=None):
|
| 657 |
+
# type: (Promise, List[Callable]) -> List[Promise]
|
| 658 |
+
"""
|
| 659 |
+
Utility function which calls 'then' for each handler provided. Handler can either
|
| 660 |
+
be a function in which case it is used as success handler, or a tuple containing
|
| 661 |
+
the success and the failure handler, where each of them could be None.
|
| 662 |
+
:type handlers: list[(Any) -> object] | list[((Any) -> object, (Any) -> object)]
|
| 663 |
+
:param handlers
|
| 664 |
+
:rtype : list[Promise]
|
| 665 |
+
"""
|
| 666 |
+
if not handlers:
|
| 667 |
+
return []
|
| 668 |
+
|
| 669 |
+
promises = [] # type: List[Promise]
|
| 670 |
+
|
| 671 |
+
for handler in handlers:
|
| 672 |
+
if isinstance(handler, tuple):
|
| 673 |
+
s, f = handler
|
| 674 |
+
|
| 675 |
+
promises.append(self.then(s, f))
|
| 676 |
+
elif isinstance(handler, dict):
|
| 677 |
+
s = handler.get("success")
|
| 678 |
+
f = handler.get("failure")
|
| 679 |
+
|
| 680 |
+
promises.append(self.then(s, f))
|
| 681 |
+
else:
|
| 682 |
+
promises.append(self.then(handler))
|
| 683 |
+
|
| 684 |
+
return promises
|
| 685 |
+
|
| 686 |
+
@classmethod
|
| 687 |
+
def _try_convert_to_promise(cls, obj):
|
| 688 |
+
# type: (Any) -> Promise
|
| 689 |
+
_type = obj.__class__
|
| 690 |
+
if issubclass(_type, Promise):
|
| 691 |
+
if cls is not Promise:
|
| 692 |
+
return cls(obj.then, obj._scheduler)
|
| 693 |
+
return obj
|
| 694 |
+
|
| 695 |
+
if iscoroutine(obj): # type: ignore
|
| 696 |
+
obj = ensure_future(obj) # type: ignore
|
| 697 |
+
_type = obj.__class__
|
| 698 |
+
|
| 699 |
+
if is_future_like(_type):
|
| 700 |
+
|
| 701 |
+
def executor(resolve, reject):
|
| 702 |
+
# type: (Callable, Callable) -> None
|
| 703 |
+
if obj.done():
|
| 704 |
+
_process_future_result(resolve, reject)(obj)
|
| 705 |
+
else:
|
| 706 |
+
obj.add_done_callback(_process_future_result(resolve, reject))
|
| 707 |
+
# _process_future_result(resolve, reject)(obj)
|
| 708 |
+
|
| 709 |
+
promise = cls(executor) # type: Promise
|
| 710 |
+
promise._future = obj
|
| 711 |
+
return promise
|
| 712 |
+
|
| 713 |
+
return obj
|
| 714 |
+
|
| 715 |
+
@classmethod
|
| 716 |
+
def reject(cls, reason):
|
| 717 |
+
# type: (Exception) -> Promise
|
| 718 |
+
ret = cls() # type: Promise
|
| 719 |
+
# ret._capture_stacktrace();
|
| 720 |
+
# ret._rejectCallback(reason, true);
|
| 721 |
+
ret._reject_callback(reason, True)
|
| 722 |
+
return ret
|
| 723 |
+
|
| 724 |
+
rejected = reject
|
| 725 |
+
|
| 726 |
+
@classmethod
|
| 727 |
+
def resolve(cls, obj):
|
| 728 |
+
# type: (T) -> Promise[T]
|
| 729 |
+
if not cls.is_thenable(obj):
|
| 730 |
+
ret = cls() # type: Promise
|
| 731 |
+
# ret._capture_stacktrace()
|
| 732 |
+
ret._state = STATE_FULFILLED
|
| 733 |
+
ret._rejection_handler0 = obj
|
| 734 |
+
return ret
|
| 735 |
+
|
| 736 |
+
return cls._try_convert_to_promise(obj)
|
| 737 |
+
|
| 738 |
+
cast = resolve
|
| 739 |
+
fulfilled = cast
|
| 740 |
+
|
| 741 |
+
@classmethod
|
| 742 |
+
def promisify(cls, f):
|
| 743 |
+
# type: (Callable) -> Callable[..., Promise]
|
| 744 |
+
if not callable(f):
|
| 745 |
+
warn(
|
| 746 |
+
"Promise.promisify is now a function decorator, please use Promise.resolve instead."
|
| 747 |
+
)
|
| 748 |
+
return cls.resolve(f)
|
| 749 |
+
|
| 750 |
+
@wraps(f)
|
| 751 |
+
def wrapper(*args, **kwargs):
|
| 752 |
+
# type: (*Any, **Any) -> Promise
|
| 753 |
+
def executor(resolve, reject):
|
| 754 |
+
# type: (Callable, Callable) -> Optional[Any]
|
| 755 |
+
return resolve(f(*args, **kwargs))
|
| 756 |
+
|
| 757 |
+
return cls(executor)
|
| 758 |
+
|
| 759 |
+
return wrapper
|
| 760 |
+
|
| 761 |
+
_safe_resolved_promise = None # type: Promise
|
| 762 |
+
|
| 763 |
+
@classmethod
|
| 764 |
+
def safe(cls, fn):
|
| 765 |
+
# type: (Callable) -> Callable
|
| 766 |
+
from functools import wraps
|
| 767 |
+
|
| 768 |
+
if not cls._safe_resolved_promise:
|
| 769 |
+
cls._safe_resolved_promise = Promise.resolve(None)
|
| 770 |
+
|
| 771 |
+
@wraps(fn)
|
| 772 |
+
def wrapper(*args, **kwargs):
|
| 773 |
+
# type: (*Any, **Any) -> Promise
|
| 774 |
+
return cls._safe_resolved_promise.then(lambda v: fn(*args, **kwargs))
|
| 775 |
+
|
| 776 |
+
return wrapper
|
| 777 |
+
|
| 778 |
+
@classmethod
|
| 779 |
+
def all(cls, promises):
|
| 780 |
+
# type: (Any) -> Promise
|
| 781 |
+
return PromiseList(promises, promise_class=cls).promise
|
| 782 |
+
|
| 783 |
+
@classmethod
|
| 784 |
+
def for_dict(cls, m):
|
| 785 |
+
# type: (Dict[Hashable, Promise[S]]) -> Promise[Dict[Hashable, S]]
|
| 786 |
+
"""
|
| 787 |
+
A special function that takes a dictionary of promises
|
| 788 |
+
and turns them into a promise for a dictionary of values.
|
| 789 |
+
In other words, this turns an dictionary of promises for values
|
| 790 |
+
into a promise for a dictionary of values.
|
| 791 |
+
"""
|
| 792 |
+
dict_type = type(m) # type: Type[Dict]
|
| 793 |
+
|
| 794 |
+
if not m:
|
| 795 |
+
return cls.resolve(dict_type()) # type: ignore
|
| 796 |
+
|
| 797 |
+
def handle_success(resolved_values):
|
| 798 |
+
# type: (List[S]) -> Dict[Hashable, S]
|
| 799 |
+
return dict_type(zip(m.keys(), resolved_values))
|
| 800 |
+
|
| 801 |
+
return cls.all(m.values()).then(handle_success)
|
| 802 |
+
|
| 803 |
+
@classmethod
|
| 804 |
+
def is_thenable(cls, obj):
|
| 805 |
+
# type: (Any) -> bool
|
| 806 |
+
"""
|
| 807 |
+
A utility function to determine if the specified
|
| 808 |
+
object is a promise using "duck typing".
|
| 809 |
+
"""
|
| 810 |
+
_type = obj.__class__
|
| 811 |
+
if obj is None or _type in BASE_TYPES:
|
| 812 |
+
return False
|
| 813 |
+
|
| 814 |
+
return (
|
| 815 |
+
issubclass(_type, Promise)
|
| 816 |
+
or iscoroutine(obj) # type: ignore
|
| 817 |
+
or is_future_like(_type)
|
| 818 |
+
)
|
| 819 |
+
|
| 820 |
+
|
| 821 |
+
_type_done_callbacks = WeakKeyDictionary() # type: MutableMapping[type, bool]
|
| 822 |
+
|
| 823 |
+
|
| 824 |
+
def is_future_like(_type):
|
| 825 |
+
# type: (type) -> bool
|
| 826 |
+
if _type not in _type_done_callbacks:
|
| 827 |
+
_type_done_callbacks[_type] = callable(
|
| 828 |
+
getattr(_type, "add_done_callback", None)
|
| 829 |
+
)
|
| 830 |
+
return _type_done_callbacks[_type]
|
| 831 |
+
|
| 832 |
+
|
| 833 |
+
promisify = Promise.promisify
|
| 834 |
+
promise_for_dict = Promise.for_dict
|
| 835 |
+
is_thenable = Promise.is_thenable
|
| 836 |
+
|
| 837 |
+
|
| 838 |
+
def _process_future_result(resolve, reject):
|
| 839 |
+
# type: (Callable, Callable) -> Callable
|
| 840 |
+
def handle_future_result(future):
|
| 841 |
+
# type: (Any) -> None
|
| 842 |
+
try:
|
| 843 |
+
resolve(future.result())
|
| 844 |
+
except Exception as e:
|
| 845 |
+
tb = exc_info()[2]
|
| 846 |
+
reject(e, tb)
|
| 847 |
+
|
| 848 |
+
return handle_future_result
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/promise_list.py
ADDED
|
@@ -0,0 +1,151 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from functools import partial
|
| 2 |
+
try:
|
| 3 |
+
from collections.abc import Iterable
|
| 4 |
+
except ImportError:
|
| 5 |
+
from collections import Iterable
|
| 6 |
+
|
| 7 |
+
if False:
|
| 8 |
+
from .promise import Promise
|
| 9 |
+
from typing import (
|
| 10 |
+
Any,
|
| 11 |
+
Optional,
|
| 12 |
+
Tuple,
|
| 13 |
+
Union,
|
| 14 |
+
List,
|
| 15 |
+
Type,
|
| 16 |
+
Collection,
|
| 17 |
+
) # flake8: noqa
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class PromiseList(object):
|
| 21 |
+
|
| 22 |
+
__slots__ = ("_values", "_length", "_total_resolved", "promise", "_promise_class")
|
| 23 |
+
|
| 24 |
+
def __init__(self, values, promise_class):
|
| 25 |
+
# type: (Union[Collection, Promise[Collection]], Type[Promise]) -> None
|
| 26 |
+
self._promise_class = promise_class
|
| 27 |
+
self.promise = self._promise_class()
|
| 28 |
+
|
| 29 |
+
self._length = 0
|
| 30 |
+
self._total_resolved = 0
|
| 31 |
+
self._values = None # type: Optional[Collection]
|
| 32 |
+
Promise = self._promise_class
|
| 33 |
+
if Promise.is_thenable(values):
|
| 34 |
+
values_as_promise = Promise._try_convert_to_promise(
|
| 35 |
+
values
|
| 36 |
+
)._target() # type: ignore
|
| 37 |
+
self._init_promise(values_as_promise)
|
| 38 |
+
else:
|
| 39 |
+
self._init(values) # type: ignore
|
| 40 |
+
|
| 41 |
+
def __len__(self):
|
| 42 |
+
# type: () -> int
|
| 43 |
+
return self._length
|
| 44 |
+
|
| 45 |
+
def _init_promise(self, values):
|
| 46 |
+
# type: (Promise[Collection]) -> None
|
| 47 |
+
if values.is_fulfilled:
|
| 48 |
+
values = values._value()
|
| 49 |
+
elif values.is_rejected:
|
| 50 |
+
self._reject(values._reason())
|
| 51 |
+
return
|
| 52 |
+
|
| 53 |
+
self.promise._is_async_guaranteed = True
|
| 54 |
+
values._then(self._init, self._reject)
|
| 55 |
+
return
|
| 56 |
+
|
| 57 |
+
def _init(self, values):
|
| 58 |
+
# type: (Collection) -> None
|
| 59 |
+
self._values = values
|
| 60 |
+
if not isinstance(values, Iterable):
|
| 61 |
+
err = Exception(
|
| 62 |
+
"PromiseList requires an iterable. Received {}.".format(repr(values))
|
| 63 |
+
)
|
| 64 |
+
self.promise._reject_callback(err, False)
|
| 65 |
+
return
|
| 66 |
+
|
| 67 |
+
if not values:
|
| 68 |
+
self._resolve([])
|
| 69 |
+
return
|
| 70 |
+
|
| 71 |
+
self._iterate(values)
|
| 72 |
+
return
|
| 73 |
+
|
| 74 |
+
def _iterate(self, values):
|
| 75 |
+
# type: (Collection[Any]) -> None
|
| 76 |
+
Promise = self._promise_class
|
| 77 |
+
is_resolved = False
|
| 78 |
+
|
| 79 |
+
self._length = len(values)
|
| 80 |
+
self._values = [None] * self._length
|
| 81 |
+
|
| 82 |
+
result = self.promise
|
| 83 |
+
|
| 84 |
+
for i, val in enumerate(values):
|
| 85 |
+
if Promise.is_thenable(val):
|
| 86 |
+
maybe_promise = Promise._try_convert_to_promise(val)._target()
|
| 87 |
+
# if is_resolved:
|
| 88 |
+
# # maybe_promise.suppressUnhandledRejections
|
| 89 |
+
# pass
|
| 90 |
+
if maybe_promise.is_pending:
|
| 91 |
+
maybe_promise._add_callbacks(
|
| 92 |
+
partial(self._promise_fulfilled, i=i),
|
| 93 |
+
self._promise_rejected,
|
| 94 |
+
None,
|
| 95 |
+
)
|
| 96 |
+
self._values[i] = maybe_promise
|
| 97 |
+
elif maybe_promise.is_fulfilled:
|
| 98 |
+
is_resolved = self._promise_fulfilled(maybe_promise._value(), i)
|
| 99 |
+
elif maybe_promise.is_rejected:
|
| 100 |
+
is_resolved = self._promise_rejected(maybe_promise._reason())
|
| 101 |
+
|
| 102 |
+
else:
|
| 103 |
+
is_resolved = self._promise_fulfilled(val, i)
|
| 104 |
+
|
| 105 |
+
if is_resolved:
|
| 106 |
+
break
|
| 107 |
+
|
| 108 |
+
if not is_resolved:
|
| 109 |
+
result._is_async_guaranteed = True
|
| 110 |
+
|
| 111 |
+
def _promise_fulfilled(self, value, i):
|
| 112 |
+
# type: (Any, int) -> bool
|
| 113 |
+
if self.is_resolved:
|
| 114 |
+
return False
|
| 115 |
+
# assert not self.is_resolved
|
| 116 |
+
# assert isinstance(self._values, Iterable)
|
| 117 |
+
# assert isinstance(i, int)
|
| 118 |
+
self._values[i] = value # type: ignore
|
| 119 |
+
self._total_resolved += 1
|
| 120 |
+
if self._total_resolved >= self._length:
|
| 121 |
+
self._resolve(self._values) # type: ignore
|
| 122 |
+
return True
|
| 123 |
+
return False
|
| 124 |
+
|
| 125 |
+
def _promise_rejected(self, reason):
|
| 126 |
+
# type: (Exception) -> bool
|
| 127 |
+
if self.is_resolved:
|
| 128 |
+
return False
|
| 129 |
+
# assert not self.is_resolved
|
| 130 |
+
# assert isinstance(self._values, Iterable)
|
| 131 |
+
self._total_resolved += 1
|
| 132 |
+
self._reject(reason)
|
| 133 |
+
return True
|
| 134 |
+
|
| 135 |
+
@property
|
| 136 |
+
def is_resolved(self):
|
| 137 |
+
# type: () -> bool
|
| 138 |
+
return self._values is None
|
| 139 |
+
|
| 140 |
+
def _resolve(self, value):
|
| 141 |
+
# type: (Collection[Any]) -> None
|
| 142 |
+
assert not self.is_resolved
|
| 143 |
+
assert not isinstance(value, self._promise_class)
|
| 144 |
+
self._values = None
|
| 145 |
+
self.promise._fulfill(value)
|
| 146 |
+
|
| 147 |
+
def _reject(self, reason):
|
| 148 |
+
# type: (Exception) -> None
|
| 149 |
+
assert not self.is_resolved
|
| 150 |
+
self._values = None
|
| 151 |
+
self.promise._reject_callback(reason, False)
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (198 Bytes). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/__pycache__/version.cpython-310.pyc
ADDED
|
Binary file (2.54 kB). View file
|
|
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/pyutils/version.py
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from __future__ import unicode_literals
|
| 2 |
+
|
| 3 |
+
import datetime
|
| 4 |
+
import os
|
| 5 |
+
import subprocess
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def get_version(version=None):
|
| 9 |
+
"Returns a PEP 440-compliant version number from VERSION."
|
| 10 |
+
version = get_complete_version(version)
|
| 11 |
+
|
| 12 |
+
# Now build the two parts of the version number:
|
| 13 |
+
# main = X.Y[.Z]
|
| 14 |
+
# sub = .devN - for pre-alpha releases
|
| 15 |
+
# | {a|b|rc}N - for alpha, beta, and rc releases
|
| 16 |
+
|
| 17 |
+
main = get_main_version(version)
|
| 18 |
+
|
| 19 |
+
sub = ""
|
| 20 |
+
if version[3] == "alpha" and version[4] == 0:
|
| 21 |
+
git_changeset = get_git_changeset()
|
| 22 |
+
if git_changeset:
|
| 23 |
+
sub = ".dev%s" % git_changeset
|
| 24 |
+
else:
|
| 25 |
+
sub = ".dev"
|
| 26 |
+
elif version[3] != "final":
|
| 27 |
+
mapping = {"alpha": "a", "beta": "b", "rc": "rc"}
|
| 28 |
+
sub = mapping[version[3]] + str(version[4])
|
| 29 |
+
|
| 30 |
+
return str(main + sub)
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def get_main_version(version=None):
|
| 34 |
+
"Returns main version (X.Y[.Z]) from VERSION."
|
| 35 |
+
version = get_complete_version(version)
|
| 36 |
+
parts = 2 if version[2] == 0 else 3
|
| 37 |
+
return ".".join(str(x) for x in version[:parts])
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def get_complete_version(version=None):
|
| 41 |
+
"""Returns a tuple of the promise version. If version argument is non-empty,
|
| 42 |
+
then checks for correctness of the tuple provided.
|
| 43 |
+
"""
|
| 44 |
+
if version is None:
|
| 45 |
+
from promise import VERSION
|
| 46 |
+
|
| 47 |
+
return VERSION
|
| 48 |
+
else:
|
| 49 |
+
assert len(version) == 5
|
| 50 |
+
assert version[3] in ("alpha", "beta", "rc", "final")
|
| 51 |
+
|
| 52 |
+
return version
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def get_docs_version(version=None):
|
| 56 |
+
version = get_complete_version(version)
|
| 57 |
+
if version[3] != "final":
|
| 58 |
+
return "dev"
|
| 59 |
+
else:
|
| 60 |
+
return "%d.%d" % version[:2]
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def get_git_changeset():
|
| 64 |
+
"""Returns a numeric identifier of the latest git changeset.
|
| 65 |
+
The result is the UTC timestamp of the changeset in YYYYMMDDHHMMSS format.
|
| 66 |
+
This value isn't guaranteed to be unique, but collisions are very unlikely,
|
| 67 |
+
so it's sufficient for generating the development version numbers.
|
| 68 |
+
"""
|
| 69 |
+
repo_dir = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
| 70 |
+
try:
|
| 71 |
+
git_log = subprocess.Popen(
|
| 72 |
+
"git log --pretty=format:%ct --quiet -1 HEAD",
|
| 73 |
+
stdout=subprocess.PIPE,
|
| 74 |
+
stderr=subprocess.PIPE,
|
| 75 |
+
shell=True,
|
| 76 |
+
cwd=repo_dir,
|
| 77 |
+
universal_newlines=True,
|
| 78 |
+
)
|
| 79 |
+
timestamp = git_log.communicate()[0]
|
| 80 |
+
timestamp = datetime.datetime.utcfromtimestamp(int(timestamp))
|
| 81 |
+
except Exception:
|
| 82 |
+
return None
|
| 83 |
+
return timestamp.strftime("%Y%m%d%H%M%S")
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__init__.py
ADDED
|
File without changes
|
vllm/lib/python3.10/site-packages/wandb/vendor/promise-2.3.0/wandb_promise/schedulers/__pycache__/__init__.cpython-310.pyc
ADDED
|
Binary file (201 Bytes). View file
|
|
|