当前位置: 首页>>代码示例>>Python>>正文


Python ray.init方法代码示例

本文整理汇总了Python中ray.init方法的典型用法代码示例。如果您正苦于以下问题:Python ray.init方法的具体用法?Python ray.init怎么用?Python ray.init使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ray的用法示例。


在下文中一共展示了ray.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ray_init

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def ray_init(self):
        """
        Connects to a Ray cluster or starts one if none exists.
        """
        self.logger.info("Initializing Ray cluster with executor spec:")
        for spec_key, value in self.executor_spec.items():
            self.logger.info("{}: {}".format(spec_key, value))

        # Avoiding accidentally starting local redis clusters.
        if 'redis_address' not in self.executor_spec:
            self.logger.warning("Warning: No redis address provided, starting local redis server.")
        ray.init(
            redis_address=self.executor_spec.get('redis_address', None),
            num_cpus=self.executor_spec.get('num_cpus', None),
            num_gpus=self.executor_spec.get('num_gpus', None)
        ) 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:18,代码来源:ray_executor.py

示例2: test_worker_update

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def test_worker_update(self):
        """
        Tests if a worker can update from an external batch correct including all
        corrections and postprocessing using the pong spec.

        N.b. this test does not use Ray.
        """
        ray.init()
        agent_config = config_from_path("configs/ray_apex_for_pong.json")
        ray_spec = agent_config["execution_spec"].pop("ray_spec")
        worker_cls = RayValueWorker.as_remote().remote
        ray_spec["worker_spec"]["worker_sample_size"] = 198
        ray_spec["worker_spec"]["worker_executes_exploration"] = True
        ray_spec["worker_spec"]["ray_exploration"] = 0.4

        worker = worker_cls(agent_config, ray_spec["worker_spec"], self.env_spec,)
        time.sleep(5)

        start = time.perf_counter()
        task = worker.execute_and_get_with_count.remote()
        result, count = ray.get(task)
        task_time = time.perf_counter() - start
        print("internal result metrics = {}, external task time = {},"
              "external throughput = {}".format(result.get_metrics(), task_time, 198 / task_time)) 
开发者ID:rlgraph,项目名称:rlgraph,代码行数:26,代码来源:test_apex_agent_long_task_learning.py

示例3: ray_local_session_fixture

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def ray_local_session_fixture():
    """Initializes Ray and shuts down Ray in local mode.

    Yields:
        None: Yield is for purposes of pytest module style.
            All statements before the yield are apart of module setup, and all
            statements after the yield are apart of module teardown.

    """
    if not ray.is_initialized():
        ray.init(local_mode=True,
                 ignore_reinit_error=True,
                 log_to_driver=False,
                 include_webui=False)
    yield
    if ray.is_initialized():
        ray.shutdown() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:19,代码来源:ray_fixtures.py

示例4: ray_session_fixture

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def ray_session_fixture():
    """Initializes Ray and shuts down Ray.

    Yields:
        None: Yield is for purposes of pytest module style.
            All statements before the yield are apart of module setup, and all
            statements after the yield are apart of module teardown.

    """
    if not ray.is_initialized():
        ray.init(memory=52428800,
                 object_store_memory=78643200,
                 ignore_reinit_error=True,
                 log_to_driver=False,
                 include_webui=False)
    yield
    if ray.is_initialized():
        ray.shutdown() 
开发者ID:rlworkgroup,项目名称:garage,代码行数:20,代码来源:ray_fixtures.py

示例5: main

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def main():
    ray.init()
    n_data = 20
    model = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=3)

    for i in range(5):
        test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3))
        start_time = time.time()
        preds_1 = model.predict(test_data)
        elapsed = time.time() - start_time
        print(np.asarray(preds_1).shape)
        print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed))



    model.close() 
开发者ID:dkeras-project,项目名称:dkeras,代码行数:18,代码来源:multi_predict_test.py

示例6: main

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def main():
    """
    Test out using multiple models at the same time, this case is running
    ResNet50 and MobileNet
    """
    ray.init()
    n_data = 20

    model1 = dKeras(ResNet50, weights='imagenet', wait_for_workers=True, n_workers=3)
    model2 = dKeras(MobileNet, weights='imagenet', wait_for_workers=True, n_workers=3)

    test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3))

    model1.predict(test_data)
    model2.predict(test_data)

    model1.close()
    model2.close() 
开发者ID:dkeras-project,项目名称:dkeras,代码行数:20,代码来源:multi_model_test.py

示例7: main

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def main():
    ray.init(object_store_memory=4000000000)
    n_data = 80
    test_data = np.random.uniform(-1, 1, (n_data, 224, 224, 3))
    model = dKeras(ResNet50, weights='imagenet', init_ray=False, wait_for_workers=True, n_workers=4)

    start_time = time.time()
    preds = model.predict(test_data)
    elapsed = time.time() - start_time

    model.close()

    time.sleep(2)
    #
    # model = ResNet50(weights='imagenet')
    # preds2 = model.predict(test_data)
    #
    # # for i in range(n_data):
    # #     for j,n in enumerate(preds[i]):
    # #         print(n, preds2[i][j])
    # #     print('-'*80)

    print("Time elapsed: {}\nFPS: {}".format(elapsed, n_data / elapsed)) 
开发者ID:dkeras-project,项目名称:dkeras,代码行数:25,代码来源:basic_test.py

示例8: main_async

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def main_async():
    import asyncio
    from ray.experimental import async_api

    ray.init(num_cpus=4)
    remote_worker = Worker.remote()
    loop = asyncio.get_event_loop()

    t_zero = time.time()

    tasks = [
        async_api.as_future(remote_worker.sleep.remote(i)) for i in range(1, 3)
    ]
    loop.run_until_complete(asyncio.gather(tasks))

    print("delta", time.time() - t_zero) 
开发者ID:heronsystems,项目名称:adeptRL,代码行数:18,代码来源:hello_ray.py

示例9: testPassingArgumentsByValue

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testPassingArgumentsByValue(self):
    ray.init(start_ray_local=True, num_workers=0)

    # The types that can be passed by value are defined by
    # is_argument_serializable in serialization.py.
    class Foo(object):
      pass
    CAN_PASS_BY_VALUE = [1, 1L, 1.0, True, False, None, [1L, 1.0, True, None],
                         ([1, 2, 3], {False: [1.0, u"hi", ()]}), 100 * ["a"]]
    CANNOT_PASS_BY_VALUE = [int, np.int64(0), np.float64(0), Foo(), [Foo()],
                            (Foo()), {0: Foo()}, [[[int]]], 101 * [1],
                            np.zeros(10)]

    for obj in CAN_PASS_BY_VALUE:
      self.assertTrue(ray.serialization.is_argument_serializable(obj))
      self.assertEqual(obj, ray.serialization.deserialize_argument(ray.serialization.serialize_argument_if_possible(obj)))

    for obj in CANNOT_PASS_BY_VALUE:
      self.assertFalse(ray.serialization.is_argument_serializable(obj))
      self.assertEqual(None, ray.serialization.serialize_argument_if_possible(obj))

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:24,代码来源:runtest.py

示例10: testRegisterClass

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testRegisterClass(self):
    ray.init(start_ray_local=True, num_workers=0)

    # Check that putting an object of a class that has not been registered
    # throws an exception.
    class TempClass(object):
      pass
    self.assertRaises(Exception, lambda : ray.put(Foo))
    # Check that registering a class that Ray cannot serialize efficiently
    # raises an exception.
    self.assertRaises(Exception, lambda : ray.register_class(type(True)))
    # Check that registering the same class with pickle works.
    ray.register_class(type(float), pickle=True)
    self.assertEqual(ray.get(ray.put(float)), float)

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:18,代码来源:runtest.py

示例11: testRunningFunctionOnAllWorkers

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testRunningFunctionOnAllWorkers(self):
    ray.init(start_ray_local=True, num_workers=1)

    def f(worker):
      sys.path.append("fake_directory")
    ray.worker.global_worker.run_function_on_all_workers(f)
    @ray.remote
    def get_path():
      return sys.path
    self.assertEqual("fake_directory", ray.get(get_path.remote())[-1])
    def f(worker):
      sys.path.pop(-1)
    ray.worker.global_worker.run_function_on_all_workers(f)
    self.assertTrue("fake_directory" not in ray.get(get_path.remote()))

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:18,代码来源:runtest.py

示例12: testComputationGraph

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testComputationGraph(self):
    ray.init(start_ray_local=True, num_workers=1)

    @ray.remote
    def f(x):
      return x
    @ray.remote
    def g(x, y):
      return x, y
    a = f.remote(1)
    b = f.remote(1)
    c = g.remote(a, b)
    c = g.remote(a, 1)
    # Make sure that we can produce a computation_graph visualization.
    ray.visualize_computation_graph(view=False)

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:19,代码来源:runtest.py

示例13: testPythonMode

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testPythonMode(self):
    reload(test_functions)
    ray.init(start_ray_local=True, driver_mode=ray.PYTHON_MODE)

    @ray.remote
    def f():
      return np.ones([3, 4, 5])
    xref = f.remote()
    assert_equal(xref, np.ones([3, 4, 5])) # remote functions should return by value
    assert_equal(xref, ray.get(xref)) # ray.get should be the identity
    y = np.random.normal(size=[11, 12])
    assert_equal(y, ray.put(y)) # ray.put should be the identity

    # make sure objects are immutable, this example is why we need to copy
    # arguments before passing them into remote functions in python mode
    aref = test_functions.python_mode_f.remote()
    assert_equal(aref, np.array([0, 0]))
    bref = test_functions.python_mode_g.remote(aref)
    assert_equal(aref, np.array([0, 0])) # python_mode_g should not mutate aref
    assert_equal(bref, np.array([1, 0]))

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:24,代码来源:runtest.py

示例14: testAttachingToCluster

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testAttachingToCluster(self):
    node_ip_address = "127.0.0.1"
    scheduler_port = np.random.randint(40000, 50000)
    scheduler_address = "{}:{}".format(node_ip_address, scheduler_port)
    ray.services.start_scheduler(scheduler_address, cleanup=True)
    time.sleep(0.1)
    ray.services.start_node(scheduler_address, node_ip_address, num_workers=1, cleanup=True)

    ray.init(node_ip_address=node_ip_address, scheduler_address=scheduler_address)

    @ray.remote
    def f(x):
      return x + 1
    self.assertEqual(ray.get(f.remote(0)), 1)

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:18,代码来源:runtest.py

示例15: testReturnAndPassUnknownType

# 需要导入模块: import ray [as 别名]
# 或者: from ray import init [as 别名]
def testReturnAndPassUnknownType(self):
    ray.init(start_ray_local=True, num_workers=1, driver_mode=ray.SILENT_MODE)

    class Foo(object):
      pass
    # Check that returning an unknown type from a remote function raises an
    # exception.
    @ray.remote
    def f():
      return Foo()
    self.assertRaises(Exception, lambda : ray.get(f.remote()))
    # Check that passing an unknown type into a remote function raises an
    # exception.
    @ray.remote
    def g(x):
      return 1
    self.assertRaises(Exception, lambda : g.remote(Foo()))

    ray.worker.cleanup() 
开发者ID:ray-project,项目名称:ray-legacy,代码行数:21,代码来源:failure_test.py


注:本文中的ray.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。