Browse Source

moved ensure_path_exists to utils.common (#591)

pull/621/head
アマデウス 3 years ago committed by GitHub
parent
commit
54e688b623
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 10
      colossalai/utils/common.py

10
colossalai/utils/common.py

@ -1,7 +1,9 @@
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
import os
import random
import socket
from pathlib import Path
from typing import List, Union
import torch
@ -39,6 +41,13 @@ def print_rank_0(msg: str, logger=None):
logger.info(msg)
def ensure_path_exists(filename: str):
# ensure the path exists
dirpath = os.path.dirname(filename)
if not os.path.exists(dirpath):
Path(dirpath).mkdir(parents=True, exist_ok=True)
def free_port():
while True:
try:
@ -103,7 +112,6 @@ def conditional_context(context_manager, enable=True):
class model_branch_context(object):
def __enter__(self):
self.env_status = env.save()

Loading…
Cancel
Save