def _is_oom_error(error: RuntimeError) -> bool:
    """Check whether a runtime error was caused by insufficient memory."""
    message = error.args[0]

    # CUDA out of memory
    if 'CUDA out of memory.' in message:
        return True

    # CPU out of memory
    if "[enforce fail at CPUAllocator.cpp:64] . DefaultCPUAllocator: can't allocate memory:" in message:
        return True
    return False