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()

[((143, 160), 'random.seed', 'random.seed', (['seed'], {}), '(seed)\n', (154, 160), False, 'import random\n'), ((165, 185), 'numpy.random.seed', 'np.random.seed', (['seed'], {}), '(seed)\n', (179, 185), True, 'import numpy as np\n'), ((190, 213), 'torch.manual_seed', 'torch.manual_seed', (['seed'], {}), '(seed)\n', (207, 213), False, 'import torch\n'), ((218, 246), 'torch.cuda.manual_seed', 'torch.cuda.manual_seed', (['seed'], {}), '(seed)\n', (240, 246), False, 'import torch\n'), ((479, 495), 'gc.get_objects', 'gc.get_objects', ([], {}), '()\n', (493, 495), False, 'import gc\n'), ((555, 567), 'gc.collect', 'gc.collect', ([], {}), '()\n', (565, 567), False, 'import gc\n'), ((572, 596), 'torch.cuda.empty_cache', 'torch.cuda.empty_cache', ([], {}), '()\n', (594, 596), False, 'import torch\n'), ((508, 528), 'torch.is_tensor', 'torch.is_tensor', (['obj'], {}), '(obj)\n', (523, 528), False, 'import torch\n')]