# flytekit

Tarmily Wen

12/02/2022, 6:15 PM
Is it possible to request resources for a task dynamically? We have a task that depending on the input could require a different amount of resources.

Dan Rammer (hamersaw)

12/02/2022, 6:23 PM
Yes, there is a
that allows you to set task resources. To do this dynamically you'll have to run the task within a dyanmic task, which can then analyze the inputs and assign correct resources. For example:
Copy code
def foo(a: int) -> int:
    return a

def bar(a: int) -> int:
    if a == 1:
        return foo(a=a).with_overrides(
          requests=Resources(cpu="6", mem="500Mi")
    return foo(a=a)

def bar(a: int) -> int:
    return bar(a=a)
Very toy example, probably syntactically incorrect, but I'm sure you get the idea.
This, or course, then requires two Pods to start. One for the dynamic task to dynamically compile the new workflow closure, and then a second to actually execute the task. So there is a minimal amount of overhead.