ray.data.ExecutionResources#
- class ray.data.ExecutionResources(cpu: float | None = None, gpu: float | None = None, object_store_memory: float | None = None, memory: float | None = None)[source]#
Bases:
objectSpecifies resources usage or resource limits for execution.
By default this class represents resource usage. Use
for_limitsor setdefault_to_infto True to create an object that represents resource limits.- classmethod from_resource_dict(resource_dict: Dict[str, float])[source]#
Create an ExecutionResources object from a resource dict.
- to_resource_dict() Dict[str, float][source]#
Convert this ExecutionResources object to a resource dict.
Values are quantized to Ray Core’s fractional-resource granularity (5 decimal digits for cpu/gpu, integer bytes for memory) so the output is suitable for passing back to Ray Core via
.options(...).
- classmethod for_limits(cpu: float | None = None, gpu: float | None = None, object_store_memory: float | None = None, memory: float | None = None) ExecutionResources[source]#
Create an ExecutionResources object that represents resource limits.
- Parameters:
cpu – Amount of logical CPU slots.
gpu – Amount of logical GPU slots.
object_store_memory – Amount of object store memory.
memory – Amount of logical memory in bytes.
- Returns:
An
ExecutionResourceswith the given limits (defaulting to infinity for any unspecified field).
- to_limits() ExecutionResources[source]#
Return a copy of this object interpreted as resource limits.
Fields left unspecified (None) become unlimited (inf) rather than 0, so a partially-specified value like
ExecutionResources(cpu=4)caps only CPU and leaves the other resources unbounded.
- classmethod zero() ExecutionResources[source]#
Returns an ExecutionResources object with zero resources.
Returns a cached, shared singleton (safe because instances are immutable in practice).
- classmethod inf() ExecutionResources[source]#
Returns an ExecutionResources object with infinite resources.
Returns a cached, shared singleton (safe because instances are immutable in practice).
- object_store_memory_str() str[source]#
Returns a human-readable string for the object store memory field.
- copy(cpu: float | None = None, gpu: float | None = None, memory: float | None = None, object_store_memory: float | None = None) ExecutionResources[source]#
Returns a copy of this ExecutionResources object allowing to override specific resources as necessary
- add(other: ExecutionResources) ExecutionResources[source]#
Adds execution resources.
- Parameters:
other – The other
ExecutionResourcesto add to this one.- Returns:
A new ExecutionResource object with summed resources.
- subtract(other: ExecutionResources) ExecutionResources[source]#
Subtracts execution resources.
- Parameters:
other – The other
ExecutionResourcesto subtract from this one.- Returns:
A new ExecutionResource object with subtracted resources.
- max(other: ExecutionResources) ExecutionResources[source]#
Returns the maximum for each resource type.
- min(other: ExecutionResources) ExecutionResources[source]#
Returns the minimum for each resource type.
- satisfies_limit(limit: ExecutionResources, *, ignore_object_store_memory: bool = False) bool[source]#
Return if this resource struct meets the specified limits.
Note that None for a field means no limit.
- Parameters:
limit – The resource limits to check against.
ignore_object_store_memory – If True, ignore the object store memory limit when checking if this resource struct meets the limits.
- Returns:
Trueif every resource is within the corresponding limit.
- scale(f: float) ExecutionResources[source]#
Return copy with all set values scaled by
f.
- floordiv(other: ExecutionResources) ExecutionResources[source]#
Returns the floor division of resources.