-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from muou55555/dev
Optimize log and update requriremnet.txt
- Loading branch information
Showing
7 changed files
with
62 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
from loguru import logger | ||
from common.utils import is_rank_0 | ||
from common.mp_wraps import rank_zero | ||
|
||
# Log config | ||
LOG_FILENAME = "ds_training.log" | ||
|
||
class GetLogger: | ||
__instance = None | ||
__init_flag = True | ||
|
||
def __new__(cls, *args, **kwargs): | ||
if not cls.__instance: | ||
cls.__instance = super(GetLogger, cls).__new__(cls, *args, **kwargs) | ||
return cls.__instance | ||
|
||
def __init__(self): | ||
if self.__init_flag: | ||
logger.add(LOG_FILENAME) | ||
self.__init_flag: False | ||
|
||
@rank_zero | ||
def trace(self, *args, **kwargs): | ||
logger.trace(*args, **kwargs) | ||
|
||
@rank_zero | ||
def debug(self, *args, **kwargs): | ||
logger.debug(*args, **kwargs) | ||
|
||
@rank_zero | ||
def info(self, *args, **kwargs): | ||
logger.info(*args, **kwargs) | ||
|
||
@rank_zero | ||
def warning(self, *args, **kwargs): | ||
logger.warning(*args, **kwargs) | ||
|
||
@rank_zero | ||
def error(self, *args, **kwargs): | ||
logger.error(*args, **kwargs) | ||
|
||
logger_rank0 = GetLogger() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
from functools import wraps | ||
from common.utils import is_rank_0 | ||
|
||
__all__ = ["rank_zero"] | ||
|
||
|
||
def rank_zero(func): | ||
@wraps(func) | ||
def wrapper(*args, **kwargs): | ||
if not is_rank_0(): | ||
return | ||
result = func(*args, **kwargs) | ||
return result | ||
|
||
return wrapper |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters