utils.py 562 Bytes
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# Copyright (c) 2022-2025, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
#
# See LICENSE for license information.

"""Utility functions for experimental middleware between Transformer Engine and Kitchen."""

import enum

import torch


HIGH_PRECISION_FLOAT_DTYPES = (
    torch.float,
    torch.float16,
    torch.bfloat16,
    torch.float32,
)


class Fp4Formats(enum.Enum):
    """FP4 data format"""

    E2M1 = "e2m1"


def roundup_div(x: int, y: int) -> int:
    """Round up division"""
    assert x >= 0
    assert y > 0
    return (x + y - 1) // y