mirror of
https://github.com/wassname/ray.git
synced 2026-07-19 11:27:32 +08:00
[Core] Do not convert gpu id to int (#9744)
Co-authored-by: Richard Liaw <rliaw@berkeley.edu>
This commit is contained in:
@@ -633,6 +633,25 @@ def save_gpu_ids_shutdown_only():
|
||||
del os.environ["CUDA_VISIBLE_DEVICES"]
|
||||
|
||||
|
||||
@pytest.mark.parametrize("as_str", [False, True])
|
||||
def test_gpu_ids_as_str(save_gpu_ids_shutdown_only, as_str):
|
||||
allowed_gpu_ids = [4, 5, 6]
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(
|
||||
str(i) for i in allowed_gpu_ids)
|
||||
ray.init()
|
||||
|
||||
@ray.remote
|
||||
def get_gpu_ids(as_str):
|
||||
gpu_ids = ray.get_gpu_ids(as_str)
|
||||
for gpu_id in gpu_ids:
|
||||
if as_str:
|
||||
assert isinstance(gpu_id, str)
|
||||
else:
|
||||
assert isinstance(gpu_id, int)
|
||||
|
||||
ray.get([get_gpu_ids.remote(as_str) for _ in range(10)])
|
||||
|
||||
|
||||
def test_specific_gpus(save_gpu_ids_shutdown_only):
|
||||
allowed_gpu_ids = [4, 5, 6]
|
||||
os.environ["CUDA_VISIBLE_DEVICES"] = ",".join(
|
||||
@@ -643,14 +662,14 @@ def test_specific_gpus(save_gpu_ids_shutdown_only):
|
||||
def f():
|
||||
gpu_ids = ray.get_gpu_ids()
|
||||
assert len(gpu_ids) == 1
|
||||
assert gpu_ids[0] in allowed_gpu_ids
|
||||
assert int(gpu_ids[0]) in allowed_gpu_ids
|
||||
|
||||
@ray.remote(num_gpus=2)
|
||||
def g():
|
||||
gpu_ids = ray.get_gpu_ids()
|
||||
assert len(gpu_ids) == 2
|
||||
assert gpu_ids[0] in allowed_gpu_ids
|
||||
assert gpu_ids[1] in allowed_gpu_ids
|
||||
assert int(gpu_ids[0]) in allowed_gpu_ids
|
||||
assert int(gpu_ids[1]) in allowed_gpu_ids
|
||||
|
||||
ray.get([f.remote() for _ in range(100)])
|
||||
ray.get([g.remote() for _ in range(100)])
|
||||
@@ -671,7 +690,7 @@ def test_local_mode_gpus(save_gpu_ids_shutdown_only):
|
||||
gpu_ids = ray.get_gpu_ids()
|
||||
assert len(gpu_ids) == 3
|
||||
for gpu in gpu_ids:
|
||||
assert gpu in allowed_gpu_ids
|
||||
assert int(gpu) in allowed_gpu_ids
|
||||
|
||||
ray.get([f.remote() for _ in range(100)])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user