【ray】【核心API 】【Core API 】

本文详细介绍了Ray的核心API,包括Tasks、Actors和Objects,以及Runtime Context的相关操作如ray.init、ray.shutdown等。通过这些API,用户可以连接到本地或远程的Ray集群,管理任务、对象和运行时环境,实现分布式计算和资源调度。
摘要由CSDN通过智能技术生成

目录

Core API 

核心API 

Tasks 任务

Actors 

Objects 对象

Runtime Context 数据库环境

ray.init 

ray.shutdown

ray.is_initialized

ray.remote

ray.get

ray.wait

ray.put

Core API 

核心API 

ray.init

Connect to an existing Ray cluster or start one and connect to it.
连接到现有的Ray群集或启动一个并连接到它。

ray.shutdown

Disconnect the worker, and terminate processes started by ray.init().
断开worker的连接,并终止ray.init()启动的进程。

ray.is_initialized

Check if ray.init has been called yet.
检查是否已调用ray.init。

ray.job_config.JobConfig

A class used to store the configurations of a job.
用于存储作业配置的类。

Tasks 任务

ray.remote

Defines a remote function or an actor class.
定义一个远程函数或一个actor类。

ray.remote_function.RemoteFunction.options

Configures and overrides the task invocation parameters.
配置并覆盖任务调用参数。

ray.cancel

Cancels a task. 

取消任务。

Actors 

ray.remote

Defines a remote function or an actor class.
定义一个远程函数或一个执行元类。

ray.actor.ActorClass.options

Configures and overrides the actor instantiation parameters.
配置并覆盖执行元实例化参数。

ray.method

Annotate an actor method.
注释一个actor方法。

ray.get_actor

Get a handle to a named actor.
获取指定参与者的句柄。

ray.kill

Kill an actor forcefully.
强行杀死一个演员。

Objects 对象

ray.get

Get a remote object or a list of remote objects from the object store.
从对象存储区获取远程对象或远程对象列表。

ray.wait

Return a list of IDs that are ready and a list of IDs that are not.
返回已就绪的ID列表和未就绪的ID列表。

ray.put

Store an object in the object store.
在对象存储区中存储对象。

Runtime Context 数据库环境

ray.runtime_context.get_runtime_context

Get the runtime context of the current driver/worker.
获取当前driver/worker的运行时上下文。

ray.runtime_context.RuntimeContext

A class used for getting runtime context.
用于获取运行时上下文的类。

ray.get_gpu_ids

Get the IDs of the GPUs that are available to the worker.
获取工作进程可用的GPU的ID。

ray.init 

ray.init(address: str | None = None*num_cpus: int | None = Nonenum_gpus: int | None = Noneresources: Dict[strfloat] | None = Nonelabels: Dict[strstr] | None = Noneobject_store_memory: int | None = Nonelocal_mode: bool = Falseignore_reinit_error: bool = Falseinclude_dashboard: bool | None = Nonedashboard_host: str = '127.0.0.1'dashboard_port: int | None = Nonejob_config: ray.job_config.JobConfig = Noneconfigure_logging: bool = Truelogging_level: int = 'info'logging_format: str | None = Nonelog_to_driver: bool = Truenamespace: str | None = Noneruntime_env: Dict[strAny] | RuntimeEnv | None = Nonestorage: str | None = None**kwargs) → BaseContext
ray.init(地址:str| None=None,*,num_cpus:int| None=None,num_gpus:int| None=None,resources:Dict[str,float]|无=无,标签:Dict[str,str]| None=None,object_store_memory:int| None=无,local_mode:bool=假,ignore_reinit_error:bool=假,include_dashboard:bool| None=无,dashboard_host:str ='127.0.0.1 ',dashboard_port:int| None=无,job_config:ray.job_config.JobConfig=无,configure_logging:bool=True,logging_level:int='info',logging_format:str| None=None,log_to_driver:bool=True,命名空间:str| None=None,runtime_env:Dict[str,Any]| RuntimeEnv| None=无,存储:str| None=None,**kwargs)→ BaseContext[source] [出处]

Connect to an existing Ray cluster or start one and connect to it.
连接到现有的Ray群集或启动一个并连接到它。

This method handles two cases; either a Ray cluster already exists and we just attach this driver to it or we start all of the processes associated with a Ray cluster and attach to the newly started cluster. Note: This method overwrite sigterm handler of the driver process.
这种方法处理两种情况;要么一个Ray集群已经存在,我们只是将这个驱动程序附加到它,要么我们启动与Ray集群相关的所有进程,并附加到新启动的集群。注意:此方法覆盖驱动程序进程的sigterm处理程序。

In most cases, it is enough to just call this method with no arguments. This will autodetect an existing Ray cluster or start a new Ray instance if no existing cluster is found:
在大多数情况下,只需调用此方法而不带参数即可。这将自动检测现有的Ray集群或启动一个新的Ray实例,如果没有找到现有的集群:

ray.init()

To explicitly connect to an existing local cluster, use this as follows. A ConnectionError will be thrown if no existing local cluster is found.
要显式连接到现有的本地群集,请按如下方式使用此命令。如果没有找到现有的本地集群,则会抛出ConnectionError。

ray.init(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

资源存储库

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值