code: def test_actor_multiple_gpus(ray_start_cluster):
      cluster = ray_start_cluster
      num_nodes = 3
      num_gpus_per_raylet = 5
      for i in range(num_nodes):
          cluster.add_node(
              num_cpus=10 * num_gpus_per_raylet,
              num_gpus=num_gpus_per_raylet,
          )
      ray.init(address=cluster.address)
  
      @ray.remote(num_gpus=2)
      class Actor1:
          def __init__(self):
              self.gpu_ids = ray.get_gpu_ids()
  
          def get_location_and_ids(self):
              assert ray.get_gpu_ids() == self.gpu_ids
              return (
                  ray._private.worker.global_worker.node.unique_id,
                  tuple(self.gpu_ids),
              )
  
      # Create some actors.
      actors1 = [Actor1.remote() for _ in range(num_nodes * 2)]
      # Make sure that no two actors are assigned to the same GPU.
      locations_and_ids = ray.get(
          [actor.get_location_and_ids.remote() for actor in actors1]
      )
      node_names = {location for location, gpu_id in locations_and_ids}
      assert len(node_names) == num_nodes
  
      # Keep track of which GPU IDs are being used for each location.
      gpus_in_use = {node_name: [] for node_name in node_names}
      for location, gpu_ids in locations_and_ids:
          gpus_in_use[location].extend(gpu_ids)
      for node_name in node_names:
          assert len(set(gpus_in_use[node_name])) == 4
  
      # Creating a new actor should fail because all of the GPUs are being
      # used.
      a = Actor1.remote()
      ready_ids, _ = ray.wait(
          [a.get_location_and_ids.remote()], timeout=0.01
      )
      assert ready_ids == []
  
      # We should be able to create more actors that use only a single GPU.
      @ray.remote(num_gpus=1)
      class Actor2:
          def __init__(self):
              self.gpu_ids = ray.get_gpu_ids()
  
          def get_location_and_ids(self):
              return (
                  ray._private.worker.global_worker.node.unique_id,
                  tuple(self.gpu_ids),
              )
  
      # Create some actors.
      actors2 = [Actor2.remote() for _ in range(num_nodes)]
      # Make sure that no two actors are assigned to the same GPU.
      locations_and_ids = ray.get(
          [actor.get_location_and_ids.remote() for actor in actors2]
      )
      names = {location for location, gpu_id in locations_and_ids}
      assert node_names == names
      for location, gpu_ids in locations_and_ids:
          gpus_in_use[location].extend(gpu_ids)
      for node_name in node_names:
          assert len(gpus_in_use[node_name]) == 5
          assert set(gpus_in_use[node_name]) == set(range(5))
  
      # Creating a new actor should fail because all of the GPUs are being
      # used.
      a = Actor2.remote()
      ready_ids, _ = ray.wait(
          [a.get_location_and_ids.remote()], timeout=0.01
      )
      assert ready_ids == []
  
imports: import collections
  import os
  import sys
  import time
  import pytest
  import ray
  import ray.cluster_utils
label_desc: Use image node_id 5 for calling a global function with example usage: test_actor_multiple_gpus(ray_start_cluster) and returns: ray,  tuple, ray,  tuple