KFrank:

gt = torch.zeros_like (predictions)



Thanks for the suggestion @KFrank. I already tried that as below:
def tversky_score(
        predictions,
        targets,
        alpha=0.5,
        beta=0.5,
        eps=1e-16,
        encode_target=True
):
    if encode_target:
        # noinspection PyArgumentList
        # gt = predictions.clone()  # .zero_()
        gt = torch.zeros_like(predictions)
        # noinspection PyArgumentList
        assert (targets.ndim == 4) and (
                targets.size(1) == 1
        ), "Only single channel images can be encoded!"
        gt = gt.scatter_(1, targets.to(dtype=torch.int64), 1)
        gt.requires_grad = True
    else:
        gt = targets.clone()
        gt.requires_grad = True
    # flatten label and prediction tensors
    predictions = predictions.view(-1)
    gt = gt.view(-1)

    # True Positives, False Positives & False Negatives
    tp = (predictions * gt).sum()
    fp = ((1 - gt) * predictions).sum()
    fn = (gt * (1 - predictions)).sum()

    tversky = (tp + eps) / (
            tp + alpha * fp + beta * fn + eps
    )
    return tversky

but I still get the exact same runtime error (one of the variables needed for gradient computation has been modified by an inplace operation). Is it because of the line
 gt = gt.scatter_(1, targets.to(dtype=torch.int64), 1)

Is it necessary to perform gt.requires_grad = True since an entirely separate tensor is being created outside the graph?