Resources
Task resources specify the computational limits and requests (CPU, memory, GPU, storage) that will be allocated to each task’s container during execution.
To specify resource requirements for your task, instantiate a Resources object with the desired parameters and assign it to either
the resources parameter of the TaskEnvironment or the resources parameter of the override function (for invocation overrides).
Every task defined using that TaskEnvironment will run with the specified resources.
If a specific task has its own resources defined in the decorator, it will override the environment’s resources for that task only.
If neither TaskEnvironment nor the task decorator specifies resources, the default resource allocation will be used.
Resources data class
For the full class definition, parameter types, and accepted formats, see the
Resources API reference.
The main parameters are:
cpu: CPU allocation — number, string ("500m"), or(request, limit)tuple.memory: Memory with Kubernetes units —"4Gi", or(request, limit)tuple. Leave headroom below a node’s total RAM: its allocatable memory is smaller (the kubelet reserves overhead for the OS and system daemons), so a request near a node’s nominal capacity can leave the pod stuckPending.gpu: GPU allocation —"A100:2", integer count, orGPU()/TPU()/Device()for advanced config.disk: Ephemeral storage —"10Gi".shm: Shared memory —"1Gi"or"auto".
Ephemeral storage
The disk parameter requests ephemeral storage — node-local scratch disk for the task’s container. Set it as a string with Kubernetes units, for example "50Gi":
env = flyte.TaskEnvironment(
name="etl_env",
resources=flyte.Resources(cpu=2, memory="4Gi", disk="50Gi"),
)Under the hood, disk maps to the Kubernetes
ephemeral-storage resource on the task’s pod.
What it covers. Ephemeral storage is the local disk a task writes to while it runs: the container’s writable filesystem and any temporary files your code creates on the local filesystem during execution (downloaded datasets, intermediate outputs, model checkpoints staged before offload). It is distinct from the offloaded storage backing flyte.io.File and flyte.io.Dir, which lives in the blob store rather than on the node.
Lifecycle. Ephemeral storage is tied to the task’s pod: it is provisioned when the task starts and reclaimed when the pod terminates. Nothing written to it survives beyond the task run, so use it for scratch work — persist anything you need to keep to a flyte.io.File or flyte.io.Dir in object storage.
Single value, not a request/limit range. Unlike cpu and memory, disk takes a single string, not a (request, limit) tuple.
Default behavior. If you don’t set disk, no ephemeral-storage request or limit is applied. The pod can still write to node-local disk, but it may be evicted if the node comes under storage pressure. Tasks doing heavy local data processing should set disk explicitly.
Examples
Usage in TaskEnvironment
Here’s a complete example of defining a TaskEnvironment with resource specifications for a machine learning training workload:
import flyte
# Define a TaskEnvironment for ML training tasks
env = flyte.TaskEnvironment(
name="ml-training",
resources=flyte.Resources(
cpu=("2", "4"), # Request 2 cores, allow up to 4 cores for scaling
memory=("2Gi", "12Gi"), # Request 2 GiB, allow up to 12 GiB for large datasets
disk="50Gi", # 50 GiB ephemeral storage for checkpoints
shm="8Gi" # 8 GiB shared memory for efficient data loading
)
)
# Use the environment for tasks
@env.task
async def train_model(dataset_path: str) -> str:
# This task will run with flexible resource allocation
return "model trained"
Usage in a task-specific override
# Demonstrate resource override at task invocation level
@env.task
async def heavy_training_task() -> str:
return "heavy model trained with overridden resources"
@env.task
async def main():
# Task using environment-level resources
result = await train_model("data.csv")
print(result)
# Task with overridden resources at invocation time
result = await heavy_training_task.override(
resources=flyte.Resources(
cpu="4",
memory="24Gi",
disk="100Gi",
shm="16Gi"
)
)()
print(result)
For complete format specifications for each resource type (CPU, memory, GPU/TPU/Device, disk, shared memory), including accepted string formats, request/limit ranges, GPU partitioning, and supported accelerator types, see the
Resources API reference.