本文整理汇总了Python中ray.shutdown方法的典型用法代码示例。如果您正苦于以下问题:Python ray.shutdown方法的具体用法?Python ray.shutdown怎么用?Python ray.shutdown使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ray
的用法示例。
在下文中一共展示了ray.shutdown方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ray_local_session_fixture
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [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()
示例2: ray_session_fixture
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [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()
示例3: op_func
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def op_func(envs, op: OP, _args=None):
if op == OP.RESET:
return ray.get([env.reset.remote() for env in envs])
if op == OP.STEP:
return ray.get([env.step.remote(action) for env, action in zip(envs, _args)])
if op == OP.SAMPLE:
return ray.get([env.sample.remote() for env in envs])
if op == OP.RENDER:
if _args: # record
[env.render.remote(filename=r'videos/{0}-{1}.mp4'.format(env.env.spec.id, i)) for i, env in enumerate(envs)]
else:
[env.render.remote() for env in envs]
return None
if op == OP.CLOSE:
ray.get([env.close.remote() for env in envs])
ray.shutdown()
return None
示例4: testCustomResources
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def testCustomResources(self):
ray.shutdown()
ray.init(resources={"hi": 3})
class train(Trainable):
def step(self):
return {"timesteps_this_iter": 1, "done": True}
trials = run_experiments({
"foo": {
"run": train,
"resources_per_trial": {
"cpu": 1,
"custom_resources": {
"hi": 2
}
}
}
})
for trial in trials:
self.assertEqual(trial.status, Trial.TERMINATED)
示例5: testLotsOfStops
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def testLotsOfStops(self):
class TestTrainable(Trainable):
def step(self):
result = {"name": self.trial_name, "trial_id": self.trial_id}
return result
def cleanup(self):
time.sleep(2)
open(os.path.join(self.logdir, "marker"), "a").close()
return 1
analysis = tune.run(
TestTrainable, num_samples=10, stop={TRAINING_ITERATION: 1})
ray.shutdown()
for trial in analysis.trials:
path = os.path.join(trial.logdir, "marker")
assert os.path.exists(path)
示例6: start_connected_emptyhead_cluster
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def start_connected_emptyhead_cluster():
"""Starts head with no resources."""
cluster = Cluster(
initialize_head=True,
connect=True,
head_node_args={
"num_cpus": 0,
"_internal_config": json.dumps({
"num_heartbeats_timeout": 10
})
})
# Pytest doesn't play nicely with imports
_register_all()
register_trainable("__fake_remote", MockRemoteTrainer)
register_trainable("__fake_durable", MockDurableTrainer)
yield cluster
# The code after the yield will run as teardown code.
ray.shutdown()
cluster.shutdown()
示例7: test_ars_compilation
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def test_ars_compilation(self):
"""Test whether an ARSTrainer can be built on all frameworks."""
ray.init(num_cpus=2, local_mode=True)
config = ars.DEFAULT_CONFIG.copy()
# Keep it simple.
config["model"]["fcnet_hiddens"] = [10]
config["model"]["fcnet_activation"] = None
num_iterations = 2
for _ in framework_iterator(config):
plain_config = config.copy()
trainer = ars.ARSTrainer(config=plain_config, env="CartPole-v0")
for i in range(num_iterations):
results = trainer.train()
print(results)
check_compute_single_action(trainer)
trainer.stop()
ray.shutdown()
示例8: run_ray_search
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def run_ray_search(spec):
'''
Method to run ray search from experiment. Uses RandomSearch now.
TODO support for other ray search algorithms: https://ray.readthedocs.io/en/latest/tune-searchalg.html
'''
logger.info(f'Running ray search for spec {spec["name"]}')
# generate trial index to pass into Lab Trial
global trial_index # make gen_trial_index passable into ray.run
trial_index = -1
def gen_trial_index():
global trial_index
trial_index += 1
return trial_index
ray.init()
ray_trials = tune.run(
ray_trainable,
name=spec['name'],
config={
"spec": spec,
"trial_index": tune.sample_from(lambda spec: gen_trial_index()),
**build_config_space(spec)
},
resources_per_trial=infer_trial_resources(spec),
num_samples=spec['meta']['max_trial'],
queue_trials=True,
)
trial_data_dict = {} # data for Lab Experiment to analyze
for ray_trial in ray_trials:
ray_trial_data = ray_trial.last_result['trial_data']
trial_data_dict.update(ray_trial_data)
ray.shutdown()
return trial_data_dict
示例9: shutdown_worker
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def shutdown_worker(self):
"""Shuts down the worker."""
for worker in self._all_workers.values():
worker.shutdown.remote()
ray.shutdown()
示例10: shutdown
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def shutdown(self):
"""Shuts down the worker."""
self.inner_worker.shutdown()
示例11: main
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def main():
args = parse_args()
ray.init(address=args.ray_address)
# world size in terms of number of processes
dist_world_size = args.nproc_per_node * args.nnodes
wait_for_gpus(dist_world_size)
# Set up Ray distributed actors.
actor = ray.remote(num_cpus=1, num_gpus=args.nproc_per_node)(NodeLaunchActor)
workers = [actor.remote() for i in range(args.nnodes)]
# Set worker 0 as the master
master_addr = ray.get(workers[0].get_node_ip.remote())
master_port = ray.get(workers[0].find_free_port.remote())
unfinished = [
worker.run.remote(
master_addr=master_addr,
master_port=master_port,
node_rank=i,
dist_world_size=dist_world_size,
args=args,
)
for i, worker in enumerate(workers)
]
try:
while len(unfinished) > 0:
finished, unfinished = ray.wait(unfinished)
finished = ray.get(finished)
except Exception as inst:
logging.exception("An error occurred:")
ray.shutdown()
示例12: close
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def close(self, stop_ray=False):
"""
Close the Ray workers for the model
Arguments:
stop_ray: Boolean value for whether to close Ray cluster
return: None
"""
self.data_server.close.remote()
if stop_ray:
ray.shutdown()
time.sleep(5e-2)
示例13: __init__
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def __init__(self):
"""Initialize a Worker object."""
self.node = None
self.mode = None
self.cached_functions_to_run = []
self.actor_init_error = None
self.actors = {}
# Information used to maintain actor checkpoints.
self.actor_checkpoint_info = {}
self.actor_task_counter = 0
# When the worker is constructed. Record the original value of the
# CUDA_VISIBLE_DEVICES environment variable.
self.original_gpu_ids = ray.utils.get_cuda_visible_devices()
self.memory_monitor = memory_monitor.MemoryMonitor()
# A dictionary that maps from driver id to SerializationContext
# TODO: clean up the SerializationContext once the job finished.
self.serialization_context_map = {}
self.function_actor_manager = FunctionActorManager(self)
# This event is checked regularly by all of the threads so that they
# know when to exit.
self.threads_stopped = threading.Event()
# Index of the current session. This number will
# increment every time when `ray.shutdown` is called.
self._session_index = 0
# Functions to run to process the values returned by ray.get. Each
# postprocessor must take two arguments ("object_ids", and "values").
self._post_get_hooks = []
示例14: main_loop
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def main_loop(self):
"""The main loop a worker runs to receive and execute tasks."""
def sigterm_handler(signum, frame):
shutdown(True)
sys.exit(1)
ray.utils.set_sigterm_handler(sigterm_handler)
self.core_worker.run_task_loop()
sys.exit(0)
示例15: init
# 需要导入模块: import ray [as 别名]
# 或者: from ray import shutdown [as 别名]
def init():
ray.init(num_cpus=4)
async_api.init()
asyncio.get_event_loop().set_debug(False)
yield
async_api.shutdown()
ray.shutdown()