Provisioning Defaults

When running a task, the user may specify options for provisioning the hardware on which the task will run.

However, for each task, the developer can specify default options, which will apply once the user does not specify any.

If none of them are set (neither by the task nor by the user), the HQS Tasks environment falls back to default values.

The following parameters, explained in the sections below, can be used to specify hardware requirements, which will determine on which hardware the task will run:

  • vcpu: The number of (virtual) CPU shares (a.k.a. threads)
  • memory: The amount of memory in MiB
  • gpu: The number of GPUs (experimental)

Additionally, the following parameter specifies limits beyond the hardware itself:

  • timeout: The maximum time allowed for the execution, see here for its definition

CPU and Memory

The parameter vcpu defines how many virtual CPU threads (which usually equals twice the number of virtual CPU cores) the task shall be assigned. Depending on the execution model this either limits the number of CPU threads visible to the task process (even in the kernel), will throttle the CPU usage or may even do nothing.

The parameter memory specifies how much memory in MiB is made available to the (process or container which runs the) task. Similar to the vcpu parameter, details on what that means exactly depend on the environment on which the task is being executed. But a developer can expect that the task is allowed to allocate the specified amount of memory, and when attempting to allocate more, it may get killed, resulting the execution to fail.

To specify the default values for these parameters, pass an instance of the HardwareOptions class to the hardware parameter of the task decorator, as visualized in the following example:

from hqs_task import task
from hqs_core_models.provisioning_options import HardwareOptions

@task(hardware=HardwareOptions(vcpu=4))
def example_with_vcpu_4() -> None:
    ...

@task(hardware=HardwareOptions(memory=4096))
def example_with_memory_4gib() -> None:
    ...

Of course, multiple options can be combined in the constructor of HardwareOptions:

@task(hardware=HardwareOptions(vcpu=4, memory=4096))
def example_with_vcpu_4_and_memory_4gib() -> None:
    ...

GPU (Experimental)

The parameter gpu defines how many GPUs are made available to the task. However there is currently no way to specify what kind of GPU (vendor, generation, number of cores, amount of GRAM, etc.) the task requests.

Note: GPU support is still experimental and only provided by some HQS Tasks environments.

from hqs_task import task
from hqs_core_models.provisioning_options import HardwareOptions

@task(hardware=HardwareOptions(gpu=1))
def example_with_gpu() -> None:
    ...

Timeout

The parameter timeout can be used to overwrite the environment's default task timeout.

This parameter is set as an argument directly for the task decorator in the form of a timedelta object from the datetime library. This constructor has several keyword arguments to specify the timeout in a human-readable way:

from hqs_task import task
from datetime import timedelta

@task(timeout=timedelta(hours=24))
def example_with_timeout_24h() -> None:
    ...

Note that it is currently not possible to simply provide the timeout in seconds or specify that the task shall not have any timeout at all.