(chance: float = 1.0)
Flip a coin and decide whether to flush PyTorch's cache. This allows the
    cache to be flushed periodically without maintaining a counter.

    I'm not sure why this is necessary, it shouldn't be. But it definitely does
    help...
Flip a coin and decide whether to flush PyTorch's cache. This allows the
    cache to be flushed periodically without maintaining a counter.
Flip a coin and decide whether to flush PyTorch s cache . This allows the cache to be flushed periodically without maintaining a counter .
def maybe_flush_pytorch_cache(chance: float = 1.0):
    """Flip a coin and decide whether to flush PyTorch's cache. This allows the
    cache to be flushed periodically without maintaining a counter.

    I'm not sure why this is necessary, it shouldn't be. But it definitely does
    help...
    """
    if random.random() < chance and torch.cuda.is_available():
        torch.cuda.empty_cache()
def maybe_flush_pytorch_cache ( chance : float = 1.0 ) : if random . random ( ) < chance and torch . cuda . is_available ( ) : torch . cuda . empty_cache ( )