import torch


def mask_to_tight_box_pytorch(mask):
    """Return bbox given mask.

    Args:
        mask: a [H, W] torch tensor

    Returns:
        a 4-tuple of torch scalars.
    """
    a = torch.nonzero(mask)
    bbox = torch.min(a[:, 1]), torch.min(a[:, 0]), torch.max(a[:, 1]), torch.max(a[:, 0])
    return bbox