def ensure_directory_exists(filename):
    """Build filename's path if it does not already exists."""
    dirname = os.path.dirname(filename)
    if not os.path.exists(dirname):
        os.makedirs(dirname)
Build filename's path if it does not already exists.
megatron_lm/megatron/checkpointing.py