Skip to content

Type Aliases

Types and type aliases used by Minnt.

AnyArray module-attribute

AnyArray: TypeAlias = Tensor | ndarray | list | tuple

A type alias for any array-like structure.

PyTorch tensors, NumPy arrays, lists, and tuples are supported.

HasCompute

Bases: Protocol

A protocol for objects that have a compute method.

Source code in minnt/type_aliases.py
20
21
22
23
24
25
class HasCompute(Protocol):
    """A protocol for objects that have a compute method."""

    def compute(self) -> float | torch.Tensor | np.ndarray:
        """Compute the value of the object."""
        ...

compute

compute() -> float | Tensor | ndarray

Compute the value of the object.

Source code in minnt/type_aliases.py
23
24
25
def compute(self) -> float | torch.Tensor | np.ndarray:
    """Compute the value of the object."""
    ...

Logs module-attribute

Logs: TypeAlias = dict[str, float | Tensor | ndarray | HasCompute]

A dictionary of logs, with keys being the log names and values being the log values.

When the logs are returned by the TrainableModule, they are always just float values.

Tensor module-attribute

A type alias for a single tensor or a packed sequence of tensors.

TensorOrTensors module-attribute

TensorOrTensors: TypeAlias = Tensor | tuple[Tensor, ...] | list[Tensor] | Any

A type alias for a single tensor/packed sequence of a sequence of them.

While a tensor or a tuple of them is the most common, any type is allowed here to accomodate dictionaries or custom data structures.