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
| Attribute | Type | Description |
|---|---|---|
| cpu | Union[CPUBaseType, Tuple[CPUBaseType, CPUBaseType], None] = None | CPU 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)). |
| memory | Union[str, Tuple[str, str], None] = None | Memory allocation using Kubernetes unit conventions, such as "512Mi" or "1Gi", or a tuple for request/limit range (e.g., ("1Gi", "4Gi")). |
| gpu | Union[Accelerators, int, [Device](device.md?sid=flyte__resources_device), None] = None | GPU, 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. |
| disk | Union[str, None] = None | Ephemeral disk storage as a string with Kubernetes units (e.g., "10Gi"), which is automatically cleaned up when the task completes. |
| shm | Union[str, Literal["auto"], None] = None | Shared 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
| Name | Type | Description |
|---|---|---|
| cpu | Union[CPUBaseType, Tuple[CPUBaseType, CPUBaseType], None] = None | CPU allocation. Accepts int, float, str (Kubernetes-style), or tuple (request/limit). |
| memory | Union[str, Tuple[str, str], None] = None | Memory allocation using Kubernetes unit conventions (e.g., "512Mi", "1Gi"). Can be a string or a tuple for request/limit. |
| gpu | Union[Accelerators, int, [Device](device.md?sid=flyte__resources_device), None] = None | GPU, TPU, or other accelerator allocation. Accepts int (count), str (type:quantity), or a Device object for advanced config. |
| disk | Union[str, None] = None | Ephemeral disk storage as a string with Kubernetes units (e.g., "10Gi"). |
| shm | Union[str, Literal["auto"], None] = None | Shared 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
| Type | Description |
|---|---|
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
| Type | Description |
|---|---|
Optional[str] | The shared memory string. |