Skip to content

Types Models

aana.core.models.types

Dtype

Bases: str, Enum

Data types.

Possible values are "auto", "float32", "float16", "bfloat16" and "int8".

ATTRIBUTE DESCRIPTION
AUTO

auto

TYPE: str

FLOAT32

float32

TYPE: str

FLOAT16

float16

TYPE: str

BFLOAT16

bfloat16

TYPE: str

INT8

int8

TYPE: str

to_torch

to_torch()

Convert the instance's dtype to a torch dtype.

RETURNS DESCRIPTION
dtype | str

Union[torch.dtype, str]: the torch dtype or "auto"

RAISES DESCRIPTION
ValueError

if the dtype is unknown

Source code in aana/core/models/types.py
def to_torch(self) -> torch.dtype | str:
    """Convert the instance's dtype to a torch dtype.

    Returns:
        Union[torch.dtype, str]: the torch dtype or "auto"

    Raises:
        ValueError: if the dtype is unknown
    """
    match self.value:
        case self.AUTO:
            return "auto"
        case self.FLOAT32:
            return torch.float32
        case self.FLOAT16:
            return torch.float16
        case self.BFLOAT16:
            return torch.bfloat16
        case self.INT8:
            return torch.int8
        case _:
            raise ValueError(f"Unknown dtype: {self}")  # noqa: TRY003