mirror of https://github.com/hpcaitech/ColossalAI
moved ensure_path_exists to utils.common (#591)
parent
e956d93ac2
commit
54e688b623
|
@ -1,7 +1,9 @@
|
||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# -*- encoding: utf-8 -*-
|
# -*- encoding: utf-8 -*-
|
||||||
|
import os
|
||||||
import random
|
import random
|
||||||
import socket
|
import socket
|
||||||
|
from pathlib import Path
|
||||||
from typing import List, Union
|
from typing import List, Union
|
||||||
|
|
||||||
import torch
|
import torch
|
||||||
|
@ -39,6 +41,13 @@ def print_rank_0(msg: str, logger=None):
|
||||||
logger.info(msg)
|
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():
|
def free_port():
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
|
@ -103,7 +112,6 @@ def conditional_context(context_manager, enable=True):
|
||||||
|
|
||||||
|
|
||||||
class model_branch_context(object):
|
class model_branch_context(object):
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
self.env_status = env.save()
|
self.env_status = env.save()
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue