mirror of
https://github.com/wassname/ray.git
synced 2026-07-18 12:40:56 +08:00
[Core] Accelerator type API (#10561)
This commit is contained in:
@@ -12,6 +12,7 @@ import pytest
|
||||
|
||||
import ray
|
||||
import ray.ray_constants as ray_constants
|
||||
import ray.util.accelerators
|
||||
import ray.cluster_utils
|
||||
import ray.test_utils
|
||||
from ray import resource_spec
|
||||
@@ -687,6 +688,54 @@ Blacklisted: No
|
||||
assert resource_spec._constraints_from_gpu_info(None) == {}
|
||||
|
||||
|
||||
def test_accelerator_type_api(shutdown_only):
|
||||
v100 = ray.util.accelerators.NVIDIA_TESLA_V100
|
||||
resource_name = f"{ray_constants.RESOURCE_CONSTRAINT_PREFIX}{v100}"
|
||||
ray.init(num_cpus=4, resources={resource_name: 1})
|
||||
|
||||
quantity = 1
|
||||
|
||||
@ray.remote(accelerator_type=v100)
|
||||
def decorated_func(quantity):
|
||||
return ray.available_resources()[resource_name] < quantity
|
||||
|
||||
assert ray.get(decorated_func.remote(quantity))
|
||||
|
||||
def via_options_func(quantity):
|
||||
return ray.available_resources()[resource_name] < quantity
|
||||
|
||||
assert ray.get(
|
||||
ray.remote(via_options_func).options(
|
||||
accelerator_type=v100).remote(quantity))
|
||||
|
||||
@ray.remote(accelerator_type=v100)
|
||||
class DecoratedActor:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def initialized(self):
|
||||
pass
|
||||
|
||||
class ActorWithOptions:
|
||||
def __init__(self):
|
||||
pass
|
||||
|
||||
def initialized(self):
|
||||
pass
|
||||
|
||||
decorated_actor = DecoratedActor.remote()
|
||||
# Avoid a race condition where the actor hasn't been initialized and
|
||||
# claimed the resources yet.
|
||||
ray.get(decorated_actor.initialized.remote())
|
||||
assert ray.available_resources()[resource_name] < quantity
|
||||
|
||||
quantity = ray.available_resources()[resource_name]
|
||||
with_options = ray.remote(ActorWithOptions).options(
|
||||
accelerator_type=v100).remote()
|
||||
ray.get(with_options.initialized.remote())
|
||||
assert ray.available_resources()[resource_name] < quantity
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
import pytest
|
||||
sys.exit(pytest.main(["-v", __file__]))
|
||||
|
||||
Reference in New Issue
Block a user