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, 4, 9, 21), 'random.seed', 'random.seed', ({(9, 16, 9, 20): 'seed'}, {}), '(seed)', False, 'import random\n'), ((10, 4, 10, 24), 'numpy.random.seed', 'np.random.seed', ({(10, 19, 10, 23): 'seed'}, {}), '(seed)', True, 'import numpy as np\n'), ((11, 4, 11, 27), 'torch.manual_seed', 'torch.manual_seed', ({(11, 22, 11, 26): 'seed'}, {}), '(seed)', False, 'import torch\n'), ((12, 4, 12, 32), 'torch.cuda.manual_seed', 'torch.cuda.manual_seed', ({(12, 27, 12, 31): 'seed'}, {}), '(seed)', False, 'import torch\n'), ((22, 15, 22, 31), 'gc.get_objects', 'gc.get_objects', ({}, {}), '()', False, 'import gc\n'), ((26, 4, 26, 16), 'gc.collect', 'gc.collect', ({}, {}), '()', False, 'import gc\n'), ((27, 4, 27, 28), 'torch.cuda.empty_cache', 'torch.cuda.empty_cache', ({}, {}), '()', False, 'import torch\n'), ((23, 11, 23, 31), 'torch.is_tensor', 'torch.is_tensor', ({(23, 27, 23, 30): 'obj'}, {}), '(obj)', False, 'import torch\n')]