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.
- 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).
- classmethod zero() ExecutionResources[source]#
Returns an ExecutionResources object with zero resources.
Returns a cached, shared singleton (
functools.cachekeyed oncls) –zero()is called all over the scheduler hot path (e.g..max(zero())) and instances are immutable in practice (every arithmetic op returns a new object and there are no setters), so sharing one instance is safe and avoids the per-call allocation.
- classmethod inf() ExecutionResources[source]#
Returns an ExecutionResources object with infinite resources.
Returns a cached, shared singleton (see
zero()for why this is safe).
- classmethod combine(resources: Iterable[ExecutionResources], fn: Callable[[float, float], float]) ExecutionResources | None[source]#
Fold an iterable of
ExecutionResourcesper dimension withfn.fn(acc, value)combines two per-dimension floats – e.g.operator.addfor a sum, ormax/minfor an element-wise max/min. Accumulates raw floats in a single pass and allocates a single result object, instead of one intermediate per element asreduce(lambda a, b: a.<op>(b), resources)would.Seeds with the first element (so no per-
fnidentity is needed) and returnsNonefor an empty iterable, which may be a one-shot generator (so it’s consumed exactly once).
- classmethod combine_sum(resources: Iterable[ExecutionResources]) ExecutionResources[source]#
Sum an iterable of
ExecutionResourcesin a single pass.Thin wrapper over
combine()with addition. Empty folds are common (e.g. completed-ops / downstream-ineligible usage rollups on most iterations), so an empty input reuses the sharedzero()singleton instead of allocating.
- 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.