Creating a task

Task is the smallest unit of execution. It represent a single operation or function, such as a data transformation, model training step, or data retrieval, etc. Each task takes a task_config parameter which is used to define the config like resource the task execution will require, the python version, libraries, apt packages, cuda version, etc. for the task.

Types of Tasks:

  • Python Tasks: Regular Python functions are decorated with @task and are called in the workflow function.
  • Each task takes a task_config as a parameter, where you pass the configuration setting to run that task, click here to learn more about the task config.
from truefoundry.deploy import Image, NvidiaGPU, Resources
from truefoundry.workflow import task, PythonTaskConfig, TaskPythonBuild


task_config = PythonTaskConfig(
    image=TaskPythonBuild(
        python_version="3.9",
        pip_packages=["truefoundry[workflow]"],
    ),
    resources=Resources(cpu_request=0.45),
    service_account="<service-account>",
)

@task(task_config=task_config)
def your_task():
  ...
  • Container Tasks: A Container Task is a task that runs a Docker container as part of the workflow execution. This allows you to encapsulate any piece of logic or computation within a Docker container and execute it within the workflow.
  • Each task takes a task_config as a parameter, where you pass the configuration setting to run that task, click here to learn more about the task config.
from truefoundry.deploy import Image, NvidiaGPU, Resources
from truefoundry.workflow import ContainerTask, ContainerTaskConfig

#container task config example
echo = ContainerTask(
    name="echo",
    task_config=ContainerTaskConfig(
        image=Image(
            image_uri="bash:4.1",
            command=["echo", "hello"],
        ),
        service_account="<service-account>",
    ),
)