import torch


def torch_all_close(a, b, tolerance=1e-12):
    """
    Check if all elements in two tensors are equal within a tolerance.
    """
    return torch.all(torch.lt(torch.abs(a - b), tolerance))