如何在使用“ray.put”创建对象后显式释放对象?
How to explicitly release object after creating it with `ray.put`?
我正在尝试使用 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
完成后,我查看 ray 仪表板,发现所有 obj_id
仍在 ray 共享内存中,引用类型为 LOCAL_REFERENCE
。
官方文档没有详细说明是否有任何方法可以显式控制对象的生命周期。据我了解,它基本上建议等到所有内存都用完,然后依靠射线清理。
问题:如何从射线共享内存中显式清除对象?
注意:我用的是Jupyter,会不会因为这个原因这个对象还活着?
函数ray.internal.internal_api.free()
执行这个函数。我在下面复制粘贴的 Ray docs for this function but it has a good docstring you can find here 上找不到任何文档。
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.
我正在尝试使用 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
完成后,我查看 ray 仪表板,发现所有 obj_id
仍在 ray 共享内存中,引用类型为 LOCAL_REFERENCE
。
官方文档没有详细说明是否有任何方法可以显式控制对象的生命周期。据我了解,它基本上建议等到所有内存都用完,然后依靠射线清理。
问题:如何从射线共享内存中显式清除对象?
注意:我用的是Jupyter,会不会因为这个原因这个对象还活着?
函数ray.internal.internal_api.free()
执行这个函数。我在下面复制粘贴的 Ray docs for this function but it has a good docstring you can find here 上找不到任何文档。
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.