Skip to main content

Resources

This class represents various computing resources such as CPU, Memory, and GPU that can be allocated to a task. It allows for flexible specification of resource requests and limits, supporting different formats for CPU, memory, and accelerator types. This class is used to define the computational environment for tasks, enabling fine-grained control over resource consumption.

Attributes

AttributeTypeDescription
cpuUnion[CPUBaseType, Tuple[CPUBaseType, CPUBaseType], None] = NoneCPU allocation. Accepts an int or float for CPU cores, a string for Kubernetes-style CPU (e.g., "500m"), or a tuple for request/limit range (e.g., (1, 4)).
memoryUnion[str, Tuple[str, str], None] = NoneMemory allocation using Kubernetes unit conventions, such as "512Mi" or "1Gi", or a tuple for request/limit range (e.g., ("1Gi", "4Gi")).
gpuUnion[Accelerators, int, [Device](device.md?sid=flyte__resources_device), None] = NoneGPU, TPU, or other accelerator allocation, specified as an int for count, a string for type and quantity (e.g., "T4:1"), or a Device object for advanced configuration.
diskUnion[str, None] = NoneEphemeral disk storage as a string with Kubernetes units (e.g., "10Gi"), which is automatically cleaned up when the task completes.
shmUnion[str, Literal["auto"], None] = NoneShared memory (/dev/shm) allocation, specified as a string with units (e.g., "1Gi") or "auto" to set to the maximum available on the node.

Constructor

Signature

def Resources(
cpu: Union[CPUBaseType, Tuple[CPUBaseType, CPUBaseType], None] = None,
memory: Union[str, Tuple[str, str], None] = None,
gpu: Union[Accelerators, int, [Device](device.md?sid=flyte__resources_device), None] = None,
disk: Union[str, None] = None,
shm: Union[str, Literal["auto"], None] = None
) - > null

Parameters

NameTypeDescription
cpuUnion[CPUBaseType, Tuple[CPUBaseType, CPUBaseType], None] = NoneCPU allocation. Accepts int, float, str (Kubernetes-style), or tuple (request/limit).
memoryUnion[str, Tuple[str, str], None] = NoneMemory allocation using Kubernetes unit conventions (e.g., "512Mi", "1Gi"). Can be a string or a tuple for request/limit.
gpuUnion[Accelerators, int, [Device](device.md?sid=flyte__resources_device), None] = NoneGPU, TPU, or other accelerator allocation. Accepts int (count), str (type:quantity), or a Device object for advanced config.
diskUnion[str, None] = NoneEphemeral disk storage as a string with Kubernetes units (e.g., "10Gi").
shmUnion[str, Literal["auto"], None] = NoneShared memory (/dev/shm) allocation. Accepts a string with units (e.g., "1Gi") or "auto".

Methods


get_device()

@classmethod
def get_device() - > Optional[[Device](device.md?sid=flyte__resources_device)]

Get the accelerator string for the task.

Returns

TypeDescription
Optional[[Device](device.md?sid=flyte__resources_device)]If GPUs are requested, return a tuple of the device name, and potentially a partition string. Default cloud provider labels typically use the following values: 1g.5gb, 2g.10gb, etc.

get_shared_memory()

@classmethod
def get_shared_memory() - > Optional[str]

Get the shared memory string for the task.

Returns

TypeDescription
Optional[str]The shared memory string.