jolly-florist-66728
09/24/2024, 12:05 PM@task
class ConfigurableFunction:
def __init__(self, x:int):
self._x = x
def __call__(self, y:int) -> int:
return self._x * y
And then usage
f10 = ConfigurableFunction(10)
f25 = ConfigurableFunction(25)
@workflow
def wf():
a = 10
b = f10(a)
c = f25(b)
return c
# Answer
Flyte does not natively support defining tasks directly within classes as shown in your example. However, you can achieve similar functionality using a combination of task decorators and class methods. According to Flyte GitHub Issue #3492, there is ongoing discussion and partial implementation for supporting class-based tasks, but it is not fully supported yet.
Here's a workaround using class methods and task decorators:
from flytekit import task, workflow
class ConfigurableFunction:
def __init__(self, x: int):
self._x = x
@task
def __call__(self, y: int) -> int:
return self._x * y
f10 = ConfigurableFunction(10)
f25 = ConfigurableFunction(25)
@workflow
def wf(a: int) -> int:
b = f10.__call__(y=a)
c = f25.__call__(y=b)
return c
if __name__ == "__main__":
print(wf(a=10))
Would you like more details on this approach or any other specific aspect?
Sources:
- Flyte GitHub Issue #3492
Slack Link
https://.slack.com/archives/CP2HDHKE1/p1727179537.049549 👍 0 button 👎 0 button 💡 Hint: Mention @runllm in the thread for followups.