ray.experimental.wait_tensor_freed#

ray.experimental.wait_tensor_freed(tensor: torch.Tensor, timeout: float | None = None)[source]#

Wait for the tensor to be freed.

This function is useful for cases where an actor keeps a reference to a tensor after returning the tensor from a task annotated with @ray.method(tensor_transport=...). In this case, Ray will store a reference to the tensor, so any in-place modifications made by the actor that returned the tensor could be seen by other actors. See Ray Direct Transport (RDT) for more details.

Call this function for RDT objects to ensure that all corresponding ray.ObjectRefs have gone out of scope and therefore the tensor is safe to write to again.

Parameters:
  • tensor – The tensor to wait to be freed. This should be a tensor that was previously returned by a task annotated with @ray.method(tensor_transport=...) or stored via ray.put(_tensor_transport="...").

  • timeout – The timeout in seconds to wait for all references to the tensor to go out of scope. Set to None to wait indefinitely. Note that if None is used, this function could hang if the ray.ObjectRefs that refer to this tensor never go out of scope.