def safe_div(a, b):
    '\n    returns a / b, unless b is zero, in which case returns 0\n    this is primarily for usage in cases where b might be systemtically zero, eg because comms are disabled or similar\n    also accounts for a or b being tensors\n    '
    if isinstance(a, torch.Tensor):
        a = a.item()
    if isinstance(b, torch.Tensor):
        b = b.item()
    return (0 if (b == 0) else (a / b))
returns a / b, unless b is zero, in which case returns 0
this is primarily for usage in cases where b might be systemtically zero, eg because comms are disabled or similar
also accounts for a or b being tensors
def safe_div(a, b):
    '\n    returns a / b, unless b is zero, in which case returns 0\n    this is primarily for usage in cases where b might be systemtically zero, eg because comms are disabled or similar\n    also accounts for a or b being tensors\n    '
    if isinstance(a, torch.Tensor):
        a = a.item()
    if isinstance(b, torch.Tensor):
        b = b.item()
    return (0 if (b == 0) else (a / b))