Hi, could you give an advice, is it possible to ma...
# flyte-support
s
Hi, could you give an advice, is it possible to make a task based on class? Something like
Copy code
@task
class ConfigurableFunction:
    def __init__(self, x:int):
        self._x = x
    def __call__(self, y:int) -> int:
        return self._x * y
And then usage
Copy code
f10 = ConfigurableFunction(10)
f25 = ConfigurableFunction(25)

@workflow
def wf():
   a = 10
   b = f10(a)
   c = f25(b)
   return c
f
You will have to work a custom task resolver
s
Is it the same as writing Custom task plugin?
b
It’s slightly different. It tells flytekit how to find and load the task when it runs on the Flyte pod. See the default implementation here, and a few examples: • Airflow task resolverCloudPickle resolver
loader_args
: method that outputs a list of strings, which provides metadata on which module, contains the task and what the attribute name is in the top-level scope of the module
load_task
: takes the output from
loader_args
, imports the module, and plucks the
f10
and
f25
variables from the module, which is assumed to be initialized instances of
ConfigurableFunction
I’d recommend creating a decorator class like
task_cls
or something and iterating from there, similar to the PythonFunctionTask class.
s
I don’t understand how the task resolver appear on the Flyte pod. Do you know maybe where I can find information about that?
which is what ends up in the Flyte UI right sidebar:
s
Does this work because
flykit.core.python_auto_container.default_task_resolver
is importable in the pod? How can I achieve the same with custom task resolver?
b
Flyte propeller only knows what container to run and what arguments to pass into it. The resolver and task are loaded in at the
entrypoint.py
: https://github.com/flyteorg/flytekit/blob/15dee9579a000696539b63745d0d036647987c0e/flytekit/bin/entrypoint.py#L392-L396 So as long as the task and its resolver are defined and loadable in your container via
pyflyte run
or
pyflyte register
it should work. Best way to iterate on this is using the flyte sandbox. I’d start by just subclassing
PythonFunctionTask
and supplying your own task resolver (just a copy of the default task resolver) into it to get a sense of how it works. Then start modifying the resolver and the
PythonFunctionTask
subclass to work with classes instead of functions.
As a sidenote @freezing-airport-6809 @average-finland-92144 @white-chef-57887 it would awesome if we had some docs around this topic
s
Thank you! I'll try