def clone_tensor_object(obj: _Any):
    """
    Clone a nested list, tuple or dict of tensors.
    """
    if isinstance(obj, _torch.Tensor):
        return obj.clone()
    elif isinstance(obj, tuple):
        return tuple(clone_tensor_object(item) for item in obj)
    elif isinstance(obj, list):
        return [clone_tensor_object(item) for item in obj]
    elif isinstance(obj, dict):
        return {key: clone_tensor_object(val) for key, val in obj.items()}
    else:
        raise ValueError(f"Cannot clone unrecognized object type: {obj}.")

    Clone a nested list, tuple or dict of tensors.
    
coremltools/optimize/torch/_utils/torch_utils.py