chore: import upstream snapshot with attribution

This commit is contained in:
wehub-resource-sync
2026-07-13 13:17:40 +08:00
commit f1825c8ceb
10096 changed files with 2364182 additions and 0 deletions
@@ -0,0 +1,124 @@
"""Runtime env test with many tasks and actors
This test runs on four nodes and schedules many tasks and actors with
different runtime environments.
Test owner: architkulkarni
Acceptance criteria: Should run through and print "PASSED"
"""
import ray
import random
import os
import time
from ray._private.test_utils import safe_write_to_results_json
def update_progress(result):
result["last_update"] = time.time()
safe_write_to_results_json(result)
if __name__ == "__main__":
ray.init(address="auto", runtime_env={"pip": ["requests==2.31.0"]})
versions = ["2.28.0", "2.29.0", "2.31.0"]
envs = [{"pip": [f"requests=={versions[i]}"]} for i in range(len(versions) - 1)]
# If a task's env is {}, we should have requests==2.31.0 from the job's env
envs.append({})
NUM_TASK_ITERATIONS = 10
NUM_ACTOR_ITERATIONS = 10
NUM_CALLS_PER_ITERATION = 100
NUM_ENVS_PER_ITERATION = 4
if os.environ.get("IS_SMOKE_TEST") == "1":
NUM_TASK_ITERATIONS = 10
NUM_ACTOR_ITERATIONS = 10
NUM_CALLS_PER_ITERATION = 1
NUM_ENVS_PER_ITERATION = 1
print("Testing Tasks...")
start_time = time.time()
previous_time = start_time
@ray.remote
def check_version_task(expected_version: str):
import requests
assert requests.__version__ == expected_version, (
requests.__version__,
expected_version,
)
for i in range(NUM_TASK_ITERATIONS):
results = []
for j in range(NUM_ENVS_PER_ITERATION):
(env, expected_version) = random.choice(list(zip(envs, versions)))
remote_task = check_version_task.options(runtime_env=env)
results.extend(
[
remote_task.remote(expected_version)
for _ in range(NUM_CALLS_PER_ITERATION)
]
)
ray.get(results)
print(f"Finished tasks iteration {i+1}/{NUM_TASK_ITERATIONS}")
new_time = time.time()
update_progress(
{
"phase": "Tasks",
"iteration": i + 1,
"iteration_time": new_time - previous_time,
"absolute_time": new_time,
"elapsed_time": new_time - start_time,
}
)
previous_time = new_time
print("Testing Actors...")
@ray.remote
class TestActor:
def check_version(self, expected_version: str):
import requests
assert requests.__version__ == expected_version, (
requests.__version__,
expected_version,
)
def nested_check_version(self, expected_version: str):
ray.get(check_version_task.remote(expected_version))
for i in range(NUM_ACTOR_ITERATIONS):
results = []
for j in range(NUM_ENVS_PER_ITERATION):
env, expected_version = random.choice(list(zip(envs, versions)))
actor = TestActor.options(runtime_env=env).remote()
results.extend(
[
actor.check_version.remote(expected_version)
for _ in range(NUM_CALLS_PER_ITERATION)
]
)
results.extend(
[
actor.nested_check_version.remote(expected_version)
for _ in range(NUM_CALLS_PER_ITERATION)
]
)
ray.get(results)
print(f"Finished actors iteration {i+1}/{NUM_ACTOR_ITERATIONS}")
new_time = time.time()
update_progress(
{
"phase": "Actors",
"iteration": i + 1,
"iteration_time": new_time - previous_time,
"absolute_time": new_time,
"elapsed_time": new_time - start_time,
}
)
previous_time = new_time
print("PASSED")
@@ -0,0 +1,92 @@
"""Runtime env test on Ray Client
This test installs runtime environments on a remote cluster using local
pip requirements.txt files. It is intended to be run using Anyscale connect.
This complements existing per-commit tests in CI, for which we don't have
access to a physical remote cluster.
Test owner: architkulkarni
Acceptance criteria: Should run through and print "PASSED"
"""
import argparse
import json
import os
import tempfile
import time
from pathlib import Path
import ray
def test_pip_requirements_files(tmpdir: str):
"""Test requirements.txt with tasks and actors.
Test specifying in @ray.remote decorator and in .options.
"""
pip_file_18 = Path(os.path.join(tmpdir, "runtime_env_pip_18.txt"))
pip_file_18.write_text("requests==2.18.0")
env_18 = {"pip": str(pip_file_18)}
pip_file_16 = Path(os.path.join(tmpdir, "runtime_env_pip_16.txt"))
pip_file_16.write_text("requests==2.16.0")
env_16 = {"pip": str(pip_file_16)}
@ray.remote(runtime_env=env_16)
def get_version():
import requests
return requests.__version__
# TODO(architkulkarni): Uncomment after #19002 is fixed
# assert ray.get(get_version.remote()) == "2.16.0"
assert ray.get(get_version.options(runtime_env=env_18).remote()) == "2.18.0"
@ray.remote(runtime_env=env_18)
class VersionActor:
def get_version(self):
import requests
return requests.__version__
# TODO(architkulkarni): Uncomment after #19002 is fixed
# actor_18 = VersionActor.remote()
# assert ray.get(actor_18.get_version.remote()) == "2.18.0"
actor_16 = VersionActor.options(runtime_env=env_16).remote()
assert ray.get(actor_16.get_version.remote()) == "2.16.0"
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--smoke-test", action="store_true", help="Finish quickly for testing."
)
args = parser.parse_args()
start = time.time()
addr = os.environ.get("RAY_ADDRESS")
job_name = os.environ.get("RAY_JOB_NAME", "rte_ray_client")
# Test reconnecting to the same cluster multiple times.
for use_working_dir in [True, True, False, False]:
with tempfile.TemporaryDirectory() as tmpdir:
runtime_env = {"working_dir": tmpdir} if use_working_dir else None
print("Testing with use_working_dir=" + str(use_working_dir))
if addr is not None and addr.startswith("anyscale://"):
ray.init(address=addr, job_name=job_name, runtime_env=runtime_env)
else:
ray.init(address="auto", runtime_env=runtime_env)
test_pip_requirements_files(tmpdir)
ray.shutdown()
taken = time.time() - start
result = {
"time_taken": taken,
}
test_output_json = os.environ.get("TEST_OUTPUT_JSON", "/tmp/rte_ray_client.json")
with open(test_output_json, "wt") as f:
json.dump(result, f)
print("PASSED")
@@ -0,0 +1,87 @@
"""Test downloading Ray wheels for currently running commit
This test runs on a single node and verifies that wheel URLs on all platforms
for the currently running Ray commit are valid. This test is necessary to
catch changes in the format or location of uploaded wheels. A test like this is
is not straightforward to add in pre-merge CI because at pre-merge time, there
is no commit to master yet and no uploaded wheels.
Runtime environments use these URLs to download the currently running Ray wheel
into isolated conda environments on each worker.
Test owner: architkulkarni
Acceptance criteria: Should run through and print "PASSED"
"""
import ray
import time
import requests
import pprint
import ray._private.ray_constants as ray_constants
from ray._private.utils import get_master_wheel_url, get_release_wheel_url
from ray._private.test_utils import safe_write_to_results_json
def update_progress(result):
result["last_update"] = time.time()
safe_write_to_results_json(result)
if __name__ == "__main__":
# Fail if running on a build from source that doesn't have a commit and
# hasn't been uploaded as a wheel to AWS.
assert "RAY_COMMIT_SHA" not in ray.__commit__, ray.__commit__
retry = set()
for sys_platform in ["darwin", "linux", "win32"]:
for py_version in ray_constants.RUNTIME_ENV_CONDA_PY_VERSIONS:
if "dev" in ray.__version__:
url = get_master_wheel_url(
ray_commit=ray.__commit__,
sys_platform=sys_platform,
ray_version=ray.__version__,
py_version=py_version,
)
else:
url = get_release_wheel_url(
ray_commit=ray.__commit__,
sys_platform=sys_platform,
ray_version=ray.__version__,
py_version=py_version,
)
if requests.head(url).status_code != 200:
print("URL not found (yet?):", url)
retry.add(url)
continue
print("Successfully tested URL: ", url)
update_progress({"url": url})
num_retries = 0
MAX_NUM_RETRIES = 12
while retry and num_retries < MAX_NUM_RETRIES:
print(
f"There are {len(retry)} URLs to retry. Sleeping 10 minutes "
f"to give some time for wheels to be built. "
f"Trial {num_retries + 1}/{MAX_NUM_RETRIES}."
)
print("List of URLs to retry:", retry)
time.sleep(600)
print("Retrying now...")
for url in list(retry):
if requests.head(url).status_code != 200:
print(f"URL still not found: {url}")
else:
print("Successfully tested URL: ", url)
update_progress({"url": url})
retry.remove(url)
num_retries = num_retries + 1
if retry:
print("FAILED")
print("List of URLs not available after all retries: ")
pprint.pprint(list(retry))
else:
print("PASSED")