from typing import Dict
from typing import Any
import torch


def release_gpu(
    tensors_dict: Dict[str, Any]
) -> Dict[str, Any]:
    """Detach and move to cpu the tensors from the input dict.

    The non-tensor elements are kept intact.

    Parameters
    ----------
    tensors_dict : Dict[str, Any]
        A dictionary containing the tensors to move.

    Returns
    -------
    Dict[str, Any]
        The same dictionary, but with the tensors moved to cpu.
    """
    for k, v in tensors_dict.items():
        if isinstance(v, torch.Tensor):
            tensors_dict[k] = v.detach().cpu()
            del v
    return tensors_dict