import torch


def normalize_tensor_sumto1(t: torch.Tensor) -> torch.Tensor:
    """
    Normalizes a tensor such that the data in each sample in the batch will sum to 1.
    """
    norm = t.sum(dim=1, keepdim=True)
    norm[norm == 0] = 1
    return t / norm