def convert_IntVar_to_int(var) -> int:
    """
    Try to convert an IntVar (or an IntVar wrapped in a IntVarTensor) to
    an int. Raises a value error if var is dynamic.
    """
    from aitemplate.compiler.base import IntVarTensor

    if isinstance(var, int):
        return var

    var = var._attrs["int_var"] if isinstance(var, IntVarTensor) else var
    if var.upper_bound() == var.lower_bound():
        return var.upper_bound()

    raise ValueError(f"Cannot convert IntVar to int: {var}")
Try to convert an IntVar (or an IntVar wrapped in a IntVarTensor) to
an int. Raises a value error if var is dynamic.
python/aitemplate/utils/shape_utils.py