diff --git a/.github/workflows/checks.yml b/.github/workflows/checks.yml
index d88d14738a..61c7f7fc0c 100644
--- a/.github/workflows/checks.yml
+++ b/.github/workflows/checks.yml
@@ -6,11 +6,9 @@ on:
- master
paths-ignore:
- 'cookbook/docs/**'
- - 'cookbook/deployment/**'
pull_request:
paths-ignore:
- 'cookbook/docs/**'
- - 'cookbook/deployment/**'
jobs:
# Lists all directories that have Dockerfile in them...
@@ -146,4 +144,4 @@ jobs:
--data-raw '{
"tag_name": "'${{ needs.bump-version.outputs.version }}'",
"prerelease": false
- }'
\ No newline at end of file
+ }'
diff --git a/cookbook/deployment/customizing_resources.py b/cookbook/deployment/customizing_resources.py
index 8ce4708416..1cc30dc0a7 100644
--- a/cookbook/deployment/customizing_resources.py
+++ b/cookbook/deployment/customizing_resources.py
@@ -1,10 +1,8 @@
"""
Customizing Task Resources
---------------------------
-
One of the reasons to use a hosted Flyte environment is the potential of leveraging CPU, memory and storage resources, far greater than what's available locally.
Flytekit makes it possible to specify these requirements declaratively and close to where the task itself is declared.
-
"""
# %%
@@ -25,20 +23,22 @@
# #. ``mem``
# #. ``gpu``
#
-# To ensure regular tasks that do not require GPUs are not scheduled on GPU nodes, a separate node group for GPU nodes can be configured with `taints `_.
-#
-# To ensure tasks that do require GPUs get the needed tolerations on their pods, set up flytepropeller using the following `configuration `_. Make sure that this toleration config matches the taint config that you have configured to protect your gpu providing nodes from having to deal with regular non-gpu workloads (pods).
+# To ensure that regular tasks that don't require GPUs are not scheduled on GPU nodes, a separate node group for GPU nodes can be configured with `taints `_.
#
-# The ``storage`` resources option is not yet supported, but coming soon.
+# To ensure that tasks that require GPUs get the needed tolerations on their pods, set up FlytePropeller using the following `configuration `_. Ensure that this toleration config matches the taint config you have configured to protect your GPU providing nodes from dealing with regular non-GPU workloads (pods).
#
-# The actual values follow the `kubernetes convention `_.
-
+# The actual values follow the `Kubernetes convention `_.
+# Let's look at an example to understand how to customize resources.
+# %%
+# Import the dependencies.
import typing
from flytekit import Resources, task, workflow
+# %%
+# Define a task and configure the resources to be allocated to it.
@task(requests=Resources(cpu="1", mem="100Mi"), limits=Resources(cpu="2", mem="150Mi"))
def count_unique_numbers(x: typing.List[int]) -> int:
s = set()
@@ -48,21 +48,80 @@ def count_unique_numbers(x: typing.List[int]) -> int:
# %%
-# Let's create a dummy task that determines the square of a number.
+# Define a task that computes the square of a number.
@task
def square(x: int) -> int:
return x * x
# %%
-# The tasks decorated with memory and storage hints can be used like regular tasks in a workflow.
+# You can use the tasks decorated with memory and storage hints like regular tasks in a workflow.
@workflow
def my_workflow(x: typing.List[int]) -> int:
return square(x=count_unique_numbers(x=x))
# %%
-# The workflow and task can be executed locally.
+# You can execute the workflow locally.
if __name__ == "__main__":
print(count_unique_numbers(x=[1, 1, 2]))
print(my_workflow(x=[1, 1, 2]))
+
+# %%
+# Using ``with_overrides``
+# ^^^^^^^^^^^^^^^^^^^^^^^^
+#
+# You can use the ``with_overrides`` method to override the resources allocated to the tasks dynamically.
+# Let's understand how the resources can be initialized with an example.
+#
+
+# %%
+# Import the dependencies.
+import typing # noqa: E402
+
+from flytekit import Resources, task, workflow # noqa: E402
+
+
+# %%
+# Define a task and configure the resources to be allocated to it.
+# You can use tasks decorated with memory and storage hints like regular tasks in a workflow.
+@task(requests=Resources(cpu="2", mem="200Mi"), limits=Resources(cpu="3", mem="350Mi"))
+def count_unique_numbers_1(x: typing.List[int]) -> int:
+ s = set()
+ for i in x:
+ s.add(i)
+ return len(s)
+
+
+# %%
+# Define a task that computes the square of a number.
+@task
+def square_1(x: int) -> int:
+ return x * x
+
+
+# %%
+# The ``with_overrides`` method overrides the old resource allocations.
+@workflow
+def my_pipeline(x: typing.List[int]) -> int:
+ return square_1(x=count_unique_numbers_1(x=x)).with_overrides(
+ limits=Resources(cpu="6", mem="500Mi")
+ )
+
+
+# %%
+# You can execute the workflow locally.
+if __name__ == "__main__":
+ print(count_unique_numbers_1(x=[1, 1, 2]))
+ print(my_pipeline(x=[1, 1, 2]))
+
+# %%
+# You can see the memory allocation below. The memory limit is ``500Mi`` rather than ``350Mi``, and the
+# CPU limit is 4, whereas it should have been 6 as specified using ``with_overrides``.
+# This is because the default platform CPU quota for every pod is 4.
+#
+# .. figure:: https://raw.githubusercontent.com/flyteorg/static-resources/main/flytesnacks/core/resource_allocation.png
+# :alt: Resource allocated using "with_overrides" method
+#
+# Resource allocated using "with_overrides" method
+