mirror of
https://github.com/wassname/ray.git
synced 2026-06-29 05:17:38 +08:00
Updating zero capacity resource semantics (#4555)
This commit is contained in:
committed by
Robert Nishihara
parent
bb207a205b
commit
0f42f87ebc
@@ -1948,15 +1948,15 @@ def test_multiple_raylets(ray_start_cluster):
|
||||
store_names = []
|
||||
store_names += [
|
||||
client["ObjectStoreSocketName"] for client in client_table
|
||||
if client["Resources"]["GPU"] == 0
|
||||
if client["Resources"].get("GPU", 0) == 0
|
||||
]
|
||||
store_names += [
|
||||
client["ObjectStoreSocketName"] for client in client_table
|
||||
if client["Resources"]["GPU"] == 5
|
||||
if client["Resources"].get("GPU", 0) == 5
|
||||
]
|
||||
store_names += [
|
||||
client["ObjectStoreSocketName"] for client in client_table
|
||||
if client["Resources"]["GPU"] == 1
|
||||
if client["Resources"].get("GPU", 0) == 1
|
||||
]
|
||||
assert len(store_names) == 3
|
||||
|
||||
@@ -2126,6 +2126,32 @@ def test_many_custom_resources(shutdown_only):
|
||||
ray.get(results)
|
||||
|
||||
|
||||
def test_zero_capacity_deletion_semantics(shutdown_only):
|
||||
ray.init(num_cpus=2, num_gpus=1, resources={"test_resource": 1})
|
||||
|
||||
def test():
|
||||
resources = ray.global_state.available_resources()
|
||||
retry_count = 0
|
||||
|
||||
while resources and retry_count < 5:
|
||||
time.sleep(0.1)
|
||||
resources = ray.global_state.available_resources()
|
||||
retry_count += 1
|
||||
|
||||
if retry_count >= 5:
|
||||
raise RuntimeError("Resources were available even after retries.")
|
||||
|
||||
return resources
|
||||
|
||||
function = ray.remote(
|
||||
num_cpus=2, num_gpus=1, resources={"test_resource": 1})(test)
|
||||
cluster_resources = ray.get(function.remote())
|
||||
|
||||
# All cluster resources should be utilized and
|
||||
# cluster_resources must be empty
|
||||
assert cluster_resources == {}
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def save_gpu_ids_shutdown_only():
|
||||
# Record the curent value of this environment variable so that we can
|
||||
|
||||
@@ -51,8 +51,8 @@ def test_uses_resources(ray_start_regular):
|
||||
|
||||
while not resource_used:
|
||||
available_resources = ray.global_state.available_resources()
|
||||
resource_used = available_resources[
|
||||
"CPU"] == cluster_resources["CPU"] - 1
|
||||
resource_used = available_resources.get(
|
||||
"CPU", 0) == cluster_resources.get("CPU", 0) - 1
|
||||
|
||||
assert resource_used
|
||||
|
||||
|
||||
Reference in New Issue
Block a user