import os
import gc
import random
import numpy as np
import torch

def seed_everything(seed):
    os.environ['PYTHONHASHSEED'] = str(seed)
    random.seed(seed)
    np.random.seed(seed)
    torch.manual_seed(seed)
    torch.cuda.manual_seed(seed)
    torch.backends.cudnn.deterministic = True
    torch.backends.cudnn.benchmark = True
    

def memory_cleanup():
    """
    Cleans up GPU memory
    https://github.com/huggingface/transformers/issues/1742
    """
    for obj in gc.get_objects():
        if torch.is_tensor(obj):
            del obj

    gc.collect()
    torch.cuda.empty_cache()

[(9, 'random.seed', 'random.seed', False, 'import random\n'), (10, 'numpy.random.seed', 'np.random.seed', True, 'import numpy as np\n'), (11, 'torch.manual_seed', 'torch.manual_seed', False, 'import torch\n'), (12, 'torch.cuda.manual_seed', 'torch.cuda.manual_seed', False, 'import torch\n'), (22, 'gc.get_objects', 'gc.get_objects', False, 'import gc\n'), (26, 'gc.collect', 'gc.collect', False, 'import gc\n'), (27, 'torch.cuda.empty_cache', 'torch.cuda.empty_cache', False, 'import torch\n'), (23, 'torch.is_tensor', 'torch.is_tensor', False, 'import torch\n')]