Ray client import gpu lib but not used

Can ray ingnore the import code? Because the import is used for ray server run. For example, I donot have gpu and cupy in my local pc.

import time
import ray
import cupy as cp

ray.init(address=‘ray://10.110.30.57:10001’)

@ray.remote(num_gpus=1,resources={‘gpu_mem’: 1})
def f():
x_gpu = cp.ones((1000, 1000))
return ray._private.services.get_node_ip_address()

You could move the import into the @ray.remote function, like:

@ray.remote(num_gpus=1,resources={‘gpu_mem’: 1})
def f():
  import cupy as cp

  x_gpu = cp.ones((1000, 1000))
  return ray._private.services.get_node_ip_address()
1 Like