如何在使用“ray.put”创建对象后显式释放对象?

Pav*_*kyi 5 python-3.x ray

我正在尝试使用 摆脱固定在共享内存中的对象ray.put。这是代码示例:

import ray
<create obj>

for ...:
  obj_id = ray.put(obj)

  <do stuff with obj_id on ray Actors using ray.get(obj_id)>
  del obj_id
Run Code Online (Sandbox Code Playgroud)

完成后,我查看 ray 仪表板,发现所有内容obj_id仍然位于具有引用类型的 ray 共享内存中LOCAL_REFERENCE

官方文档没有详细说明是否有任何方法可以显式控制对象的生存期。据我了解,它基本上建议等到所有内存都用完,然后依靠光线来清理东西。

问题:如何从光线共享内存中显式清除对象?

注意:我正在使用 Jupyter,这个对象是否会因此而仍然存在?

Osc*_*agg 2

该函数ray.internal.internal_api.free()执行此功能。我找不到有关此功能的Ray 文档的任何文档,但它有一个很好的文档字符串,您可以在此处找到,我已将其复制粘贴在下面。

Free a list of IDs from the in-process and plasma object stores.

This function is a low-level API which should be used in restricted
scenarios.

If local_only is false, the request will be send to all object stores.

This method will not return any value to indicate whether the deletion is
successful or not. This function is an instruction to the object store. If
some of the objects are in use, the object stores will delete them later
when the ref count is down to 0.

Examples:
    >>> x_id = f.remote()
    >>> ray.get(x_id)  # wait for x to be created first
    >>> free([x_id])  # unpin & delete x globally

Args:
    object_refs (List[ObjectRef]): List of object refs to delete.
    local_only (bool): Whether only deleting the list of objects in local
    object store or all object stores.
Run Code Online (Sandbox Code Playgroud)