Specifying Accelerators#

Tags: MachineLearning, Advanced, Hardware

Flyte allows you to specify gpu resources for a given task. However, in some cases, you may want to use a different accelerator type, such as TPU, specific variations of GPUs, or fractional GPUs. You can configure the Flyte backend to use your preferred accelerators, and those who write workflow code can import the flytekit.extras.accelerators module to specify an accelerator in the task decorator.

If you want to use a specific GPU device, you can pass the device name directly to the task decorator, e.g.:

@task(
    limits=Resources(gpu="1"),
    accelerator=GPUAccelerator("nvidia-tesla-v100"),
)
def my_task() -> None:
    ...

Base Classes#

These classes can be used to create custom accelerator type constants. For example, you can create a TPU accelerator.

BaseAccelerator()

Base class for all accelerator types.

GPUAccelerator(device)

Class that represents a GPU accelerator.

MultiInstanceGPUAccelerator()

Base class for all multi-instance GPU accelerator types.

But, often, you may want to use a well known accelerator type, and to simplify this, flytekit provides a set of predefined accelerator constants, as described in the next section.

Predefined Accelerator Constants#

The flytekit.extras.accelerators module provides some constants for known accelerators, listed below, but this is not a complete list. If you know the name of the accelerator, you can pass the string name to the task decorator directly.

If using the constants, you can import them directly from the module, e.g.:

from flytekit.extras.accelerators import T4

@task(
    limits=Resources(gpu="1"),
    accelerator=T4,
)
def my_task() -> None:
    ...

if you want to use a fractional GPU, you can use the partitioned method on the accelerator constant, e.g.:

from flytekit.extras.accelerators import A100

@task(
    limits=Resources(gpu="1"),
    accelerator=A100.partition_2g_10gb,
)
def my_task() -> None:
    ...

A10G

use this constant to specify that the task should run on an NVIDIA A10 Tensor Core GPU

L4

use this constant to specify that the task should run on an NVIDIA L4 Tensor Core GPU

K80

use this constant to specify that the task should run on an NVIDIA Tesla K80 GPU

M60

use this constant to specify that the task should run on an NVIDIA Tesla M60 GPU

P4

use this constant to specify that the task should run on an NVIDIA Tesla P4 GPU

P100

use this constant to specify that the task should run on an NVIDIA Tesla P100 GPU

T4

use this constant to specify that the task should run on an NVIDIA T4 Tensor Core GPU

V100

use this constant to specify that the task should run on an NVIDIA Tesla V100 GPU

A100

Use this constant to specify that the task should run on an entire NVIDIA A100 GPU.

A100_80GB

use this constant to specify that the task should run on an entire NVIDIA A100 80GB GPU.

flytekit.extras.accelerators.A100 = <flytekit.extras.accelerators._A100 object>#

Use this constant to specify that the task should run on an entire NVIDIA A100 GPU. Fractional partitions are also available.

Use pre-defined partitions (as instance attributes). For example, to specify a 10GB partition, use A100.partition_2g_10gb. All partitions are nested in the class as follows:

class flytekit.extras.accelerators._A100[source]#

Class that represents an NVIDIA A100 GPU. It is possible to specify a partition of an A100 GPU by using the provided partitions on the class. For example, to specify a 10GB partition, use A100.partition_2g_10gb. Refer to Partitioned GPUs

partition_1g_5gb = <flytekit.extras.accelerators._A100_Base object>#

5GB partition of an A100 GPU.

partition_2g_10gb = <flytekit.extras.accelerators._A100_Base object>#

10GB partition of an A100 GPU - 2x5GB slices with 2/7th of the SM.

partition_3g_20gb = <flytekit.extras.accelerators._A100_Base object>#

20GB partition of an A100 GPU - 4x5GB slices, with 3/7th fraction of SM (Streaming multiprocessor).

partition_4g_20gb = <flytekit.extras.accelerators._A100_Base object>#

20GB partition of an A100 GPU - 4x5GB slices, with 4/7th fraction of SM.

partition_7g_40gb = <flytekit.extras.accelerators._A100_Base object>#

40GB partition of an A100 GPU - 8x5GB slices, with 7/7th fraction of SM.

flytekit.extras.accelerators.A100_80GB = <flytekit.extras.accelerators._A100_80GB object>#

use this constant to specify that the task should run on an entire NVIDIA A100 80GB GPU. Fractional partitions are also available.

Use pre-defined partitions (as instance attributes). For example, to specify a 10GB partition, use A100.partition_2g_10gb. All available partitions are listed below:

class flytekit.extras.accelerators._A100_80GB[source]#

Partitions of an NVIDIA A100 80GB GPU.

partition_1g_10gb = <flytekit.extras.accelerators._A100_80GB_Base object>#

10GB partition of an A100 80GB GPU - 2x5GB slices with 1/7th of the SM.

partition_2g_20gb = <flytekit.extras.accelerators._A100_80GB_Base object>#

2GB partition of an A100 80GB GPU - 4x5GB slices with 2/7th of the SM.

partition_3g_40gb = <flytekit.extras.accelerators._A100_80GB_Base object>#

3GB partition of an A100 80GB GPU - 8x5GB slices with 3/7th of the SM.

partition_4g_40gb = <flytekit.extras.accelerators._A100_80GB_Base object>#

4GB partition of an A100 80GB GPU - 8x5GB slices with 4/7th of the SM.

partition_7g_80gb = <flytekit.extras.accelerators._A100_80GB_Base object>#

7GB partition of an A100 80GB GPU - 16x5GB slices with 7/7th of the SM.

flytekit.extras.accelerators.A10G = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA A10 Tensor Core GPU

class flytekit.extras.accelerators.BaseAccelerator[source]#

Bases: abc.ABC, Generic[flytekit.extras.accelerators.T]

Base class for all accelerator types. This class is not meant to be instantiated directly.

abstract to_flyte_idl()[source]#
Return type

flytekit.extras.accelerators.T

class flytekit.extras.accelerators.GPUAccelerator(device)[source]#

Bases: flytekit.extras.accelerators.BaseAccelerator

Class that represents a GPU accelerator. The class can be instantiated with any valid GPU device name, but it is recommended to use one of the pre-defined constants below, as name has to match the name of the device configured on the cluster.

Parameters

device (str) –

Return type

None

to_flyte_idl()[source]#
Return type

flyteidl.core.tasks_pb2.GPUAccelerator

flytekit.extras.accelerators.K80 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA Tesla K80 GPU

flytekit.extras.accelerators.L4 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA L4 Tensor Core GPU

flytekit.extras.accelerators.M60 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA Tesla M60 GPU

class flytekit.extras.accelerators.MultiInstanceGPUAccelerator[source]#

Bases: flytekit.extras.accelerators.BaseAccelerator

Base class for all multi-instance GPU accelerator types. It is recommended to use one of the pre-defined constants below, as name has to match the name of the device configured on the cluster. For example, to specify a 10GB partition of an A100 GPU, use A100.partition_2g_10gb.

device: ClassVar[str]#
classmethod partitioned(partition_size)[source]#
Parameters

partition_size (str) –

Return type

flytekit.extras.accelerators.MIG

to_flyte_idl()[source]#
Return type

flyteidl.core.tasks_pb2.GPUAccelerator

property unpartitioned: flytekit.extras.accelerators.MIG#
flytekit.extras.accelerators.P100 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA Tesla P100 GPU

flytekit.extras.accelerators.P4 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA Tesla P4 GPU

flytekit.extras.accelerators.T4 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA T4 Tensor Core GPU

flytekit.extras.accelerators.V100 = <flytekit.extras.accelerators.GPUAccelerator object>#

use this constant to specify that the task should run on an NVIDIA Tesla V100 GPU