change EXCEPTION level to CRITICAL level

This commit is contained in:
huangbingjian 2021-10-25 11:03:11 +08:00
parent db95f7493c
commit d7e97dd74a
22 changed files with 107 additions and 109 deletions

View File

@ -897,7 +897,7 @@ def _check_data_type_valid(data, valid_type):
if isinstance(data, valid_type):
if hasattr(data, 'size') and data.size == 0:
msg = "Please provide non-empty data."
logger.error(msg)
logger.critical(msg)
raise ValueError(msg)
return True
return False

View File

@ -1244,7 +1244,7 @@ class Tensor(Tensor_):
arr = np.ndarray(shape, dtype=mstype.dtype_to_nptype(self.dtype))
except ValueError:
msg = "Error shape={}".format(shape)
logger.error(msg)
logger.critical(msg)
raise ValueError(msg)
class seed_context:

View File

@ -62,7 +62,7 @@ def _make_directory(path):
os.makedirs(path)
real_path = path
except PermissionError as e:
logger.error(f"No write permission on the directory `{path}`, error = {e}")
logger.critical(f"No write permission on the directory `{path}`, error = {e}")
raise ValueError(f"No write permission on the directory `{path}`.")
return real_path

View File

@ -38,8 +38,8 @@ AnfNodePtr GetTraceNode(const AbstractBasePtr &abs) {
inline void AbstractTypeJoinLogging(const AbstractBasePtr &abstract1, const AbstractBasePtr &abstract2) {
std::ostringstream oss;
oss << "Type Join Failed: abstract type " << abstract1->type_name() << " cannot not join with "
<< abstract2->type_name() << ". For more details, please refer to the FAQ at https://www.mindspore.cn. "
oss << "Type Join Failed: abstract type " << abstract1->type_name() << " cannot join with " << abstract2->type_name()
<< ". For more details, please refer to the FAQ at https://www.mindspore.cn. "
<< "this: " << abstract1->ToString() << ", other: " << abstract2->ToString();
auto node = GetTraceNode(abstract1);
if (node != nullptr) {

View File

@ -51,7 +51,7 @@ static std::string GetProcName() {
static std::string GetLogLevel(MsLogLevel level) {
#define _TO_STRING(x) #x
static const char *const level_names[] = {
_TO_STRING(DEBUG), _TO_STRING(INFO), _TO_STRING(WARNING), _TO_STRING(ERROR), _TO_STRING(EXCEPTION),
"DEBUG", "INFO", "WARNING", "ERROR", "CRITICAL",
};
#undef _TO_STRING
if (level > this_thread_max_log_level) {
@ -79,11 +79,11 @@ static int GetGlogLevel(MsLogLevel level) {
static int GetThresholdLevel(const std::string &threshold) {
if (threshold.empty()) {
return google::GLOG_WARNING;
} else if (threshold == std::to_string(DEBUG) || threshold == std::to_string(INFO)) {
} else if (threshold == "DEBUG" || threshold == "INFO") {
return google::GLOG_INFO;
} else if (threshold == std::to_string(WARNING)) {
} else if (threshold == "WARNING") {
return google::GLOG_WARNING;
} else if (threshold == std::to_string(ERROR) || threshold == std::to_string(EXCEPTION)) {
} else if (threshold == "ERROR" || threshold == "CRITICAL") {
return google::GLOG_ERROR;
} else {
return google::GLOG_WARNING;
@ -299,7 +299,7 @@ class LogConfigParser {
}
// The text of config MS_SUBMODULE_LOG_v is in the form {submodule1:log_level1,submodule2:log_level2,...}.
// Valid values of log levels are: 0 - debug, 1 - info, 2 - warning, 3 - error, 4 - exception
// Valid values of log levels are: 0 - debug, 1 - info, 2 - warning, 3 - error, 4 - critical
// e.g. MS_SUBMODULE_LOG_v={PARSER:0, ANALYZER:2, PIPELINE:1}
std::map<std::string, std::string> Parse() {
std::map<std::string, std::string> log_levels;

View File

@ -634,7 +634,7 @@ class Dataset:
"""
dataset = None
if not hasattr(func, '__call__'):
logger.error("func must be a function.")
logger.critical("func must be a function.")
raise TypeError("func must be a function.")
for row_data in self.create_tuple_iterator(output_numpy=True):
@ -644,7 +644,7 @@ class Dataset:
dataset += func(row_data)
if not isinstance(dataset, Dataset):
logger.error("flat_map must return a Dataset object.")
logger.critical("flat_map must return a Dataset object.")
raise TypeError("flat_map must return a Dataset object.")
return dataset
@ -2568,8 +2568,8 @@ def _watch_dog(eot, pids):
wait_pid()
## multiprocessing.queue may hang in .get() forever when put() process was killed.
## We have to exit main process otherwise main process will hang.
logger.exception("The subprocess of dataset may exit unexpected or be killed, "
"main process will exit.")
logger.critical("The subprocess of dataset may exit unexpected or be killed, "
"main process will exit.")
os.kill(os.getpid(), signal.SIGTERM)
@ -2742,7 +2742,7 @@ class _ExceptHookHandler:
sys.excepthook = self.__handler_exception
def __handler_exception(self, ex_type, value, tb):
logger.exception("Uncaught exception: ", exc_info=(ex_type, value, tb))
logger.critical("Uncaught exception: ", exc_info=(ex_type, value, tb))
_mp_pool_exit_preprocess()

View File

@ -180,7 +180,7 @@ class DictIterator(Iterator):
## maybe "Out of memory" / "MemoryError" error
err_info = str(err)
if err_info.find("Out of memory") >= 0 or err_info.find("MemoryError") >= 0:
logger.exception("Memory error occurred, process will exit.")
logger.critical("Memory error occurred, process will exit.")
os.kill(os.getpid(), signal.SIGKILL)
raise err

View File

@ -386,7 +386,7 @@ if __name__ == "__main__":
os.chdir(os.path.join(script_path, "../../../../.."))
main()
except (OSError, IndexError, KeyError):
logger.error('FAILED: cropper_configure.py!')
logger.critical('FAILED: cropper_configure.py!')
raise
else:
logger.info('SUCCESS: cropper_configure.py ')

View File

@ -55,7 +55,7 @@ _name_to_level = {
'INFO': 20,
'WARNING': 30,
'ERROR': 40,
'EXCEPTION': 50,
'CRITICAL': 50,
}
# GLog level and level name
@ -64,7 +64,7 @@ _gloglevel_to_name = {
'1': 'INFO',
'2': 'WARNING',
'3': 'ERROR',
'4': 'EXCEPTION',
'4': 'CRITICAL',
}
# The mapping of logger configurations to glog configurations
@ -219,8 +219,8 @@ def warning(msg, *args, **kwargs):
_get_logger().warning(msg, *args, **kwargs)
def exception(msg, *args, **kwargs):
"""Use logging.critical to log a message with severity 'EXCEPTION' on the MindSpore logger."""
def critical(msg, *args, **kwargs):
"""Log a message with severity 'CRITICAL' on the MindSpore logger."""
_get_logger().critical(msg, *args, **kwargs)
@ -229,7 +229,7 @@ def get_level():
Get the logger level.
Returns:
str, the Log level includes 4(EXCEPTION), 3(ERROR), 2(WARNING), 1(INFO), 0(DEBUG).
str, the Log level includes 4(CRITICAL), 3(ERROR), 2(WARNING), 1(INFO), 0(DEBUG).
Examples:
>>> import os
@ -374,7 +374,7 @@ def _verify_level(level):
# Check the value of input level
if level_name not in _name_to_level:
raise ValueError(f'Incorrect log level:{level}, Please check the configuration of GLOG_v or '
'GLOG_stderrthreshold, desired log level: 4-EXCEPTION, 3-ERROR, 2-WARNING, '
'GLOG_stderrthreshold, desired log level: 4-CRITICAL, 3-ERROR, 2-WARNING, '
'1-INFO, 0-DEBUG')
@ -544,8 +544,6 @@ def _setup_logger(kwargs):
if _global_logger:
return _global_logger
# Set the level name of logging.CRITICAL to EXCEPTION
logging.addLevelName(logging.CRITICAL, 'EXCEPTION')
logger = logging.getLogger(name=f'{sub_module}.{log_name}')
# Override findCaller on the logger, Support for getting log record
logger.findCaller = _find_caller

View File

@ -49,7 +49,7 @@ class ShardHeader:
"""
schema_id = self._header.add_schema(schema)
if schema_id == -1:
logger.error("Failed to add schema.")
logger.critical("Failed to add schema.")
raise MRMAddSchemaError
return schema_id
@ -68,7 +68,7 @@ class ShardHeader:
"""
ret = self._header.add_index_fields(index_fields)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to add index field.")
logger.critical("Failed to add index field.")
raise MRMAddIndexError
return ret
@ -89,7 +89,7 @@ class ShardHeader:
desc = desc if desc else ""
schema = ms.Schema.build(desc, content)
if not schema:
logger.error("Failed to add build schema.")
logger.critical("Failed to add build schema.")
raise MRMBuildSchemaError
return schema
@ -127,7 +127,7 @@ class ShardHeader:
if ret and len(ret) == 1:
return ret[0].get_schema_content()
logger.error("Failed to get meta info.")
logger.critical("Failed to get meta info.")
raise MRMGetMetaError
@property

View File

@ -38,7 +38,7 @@ class ShardIndexGenerator:
def __init__(self, path, append=False):
self._generator = ms.ShardIndexGenerator(path, append)
if not self._generator:
logger.error("Failed to create index generator.")
logger.critical("Failed to create index generator.")
raise MRMIndexGeneratorError
def build(self):
@ -53,7 +53,7 @@ class ShardIndexGenerator:
"""
ret = self._generator.build()
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to build index generator.")
logger.critical("Failed to build index generator.")
raise MRMGenerateIndexError
return ret
@ -69,6 +69,6 @@ class ShardIndexGenerator:
"""
ret = self._generator.write_to_db()
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to write to database.")
logger.critical("Failed to write to database.")
raise MRMGenerateIndexError
return ret

View File

@ -55,7 +55,7 @@ class ShardReader:
file_name = [file_name]
ret = self._reader.open(file_name, load_dataset, num_consumer, columns, operator)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to open {}.".format(file_name))
logger.critical("Failed to open {}.".format(file_name))
self.close()
raise MRMOpenError
return ret
@ -72,7 +72,7 @@ class ShardReader:
"""
ret = self._reader.launch()
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to launch worker threads.")
logger.critical("Failed to launch worker threads.")
raise MRMLaunchError
return ret

View File

@ -60,7 +60,7 @@ class ShardSegment:
file_name = [file_name]
ret = self._segment.open(file_name, load_dataset, num_consumer, self._columns, operator)
if ret != SUCCESS:
logger.error("Failed to open {}.".format(file_name))
logger.critical("Failed to open {}.".format(file_name))
raise MRMOpenError
self._header = ShardHeader(self._segment.get_header())
return ret

View File

@ -51,7 +51,7 @@ class ShardWriter:
"""
ret = self._writer.open(paths, False)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to open paths")
logger.critical("Failed to open paths")
raise MRMOpenError
self._is_open = True
return ret
@ -71,7 +71,7 @@ class ShardWriter:
"""
ret = self._writer.open_for_append(path)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to open path to append.")
logger.critical("Failed to open path to append.")
raise MRMOpenForAppendError
self._is_open = True
return ret
@ -91,7 +91,7 @@ class ShardWriter:
"""
ret = self._writer.set_header_size(header_size)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to set header size.")
logger.critical("Failed to set header size.")
raise MRMInvalidHeaderSizeError
return ret
@ -110,7 +110,7 @@ class ShardWriter:
"""
ret = self._writer.set_page_size(page_size)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to set page size.")
logger.critical("Failed to set page size.")
raise MRMInvalidPageSizeError
return ret
@ -130,7 +130,7 @@ class ShardWriter:
self._header = shard_header
ret = self._writer.set_shard_header(shard_header.header)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to set header.")
logger.critical("Failed to set header.")
raise MRMSetHeaderError
return ret
@ -177,7 +177,7 @@ class ShardWriter:
raw_data = {0: raw_data} if raw_data else {}
ret = self._writer.write_raw_data(raw_data, blob_data, validate, parallel_writer)
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to write dataset.")
logger.critical("Failed to write dataset.")
raise MRMWriteDatasetError
return ret
@ -220,7 +220,7 @@ class ShardWriter:
"""
ret = self._writer.commit()
if ret != ms.MSRStatus.SUCCESS:
logger.error("Failed to commit.")
logger.critical("Failed to commit.")
raise MRMCommitError
return ret

View File

@ -165,15 +165,15 @@ class FlopsParser:
logger.info("the aicore file path is %s", aicore_file_path)
if not os.path.exists(aicore_file_path):
logger.error(f'The file {aicore_file_path} does not exist.')
logger.critical(f'The file {aicore_file_path} does not exist.')
raise ProfilerFileNotFoundException('aicore.data')
file_size = os.path.getsize(aicore_file_path)
read_count = file_size // self.AICORE_LOG_SIZE
if not read_count:
logger.error(f'the file {aicore_file_path} '
f'does not have enough content to be parsed.')
logger.critical(f'the file {aicore_file_path} '
f'does not have enough content to be parsed.')
raise ProfilerRawFileException(
'aicore.data file does not have enough content to be parsed'
)
@ -182,7 +182,7 @@ class FlopsParser:
with open(aicore_file_path, "rb") as aicore_file:
all_log_struct = aicore_file.read(self.AICORE_LOG_SIZE * read_count)
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {aicore_file_path} file: {err}')
logger.critical(f'Error occurred when read {aicore_file_path} file: {err}')
raise ProfilerIOException()
return read_count, all_log_struct
@ -195,7 +195,7 @@ class FlopsParser:
)
if not os.path.exists(info_json_file_path):
logger.error(f'The file {info_json_file_path} does not exist.')
logger.critical(f'The file {info_json_file_path} does not exist.')
raise ProfilerFileNotFoundException(info_json_file_path)
try:
@ -206,7 +206,7 @@ class FlopsParser:
# peak_flops formula (provided by Hisi): device_frequency * num_of_aicore * 4096 * 2.
peak_flops = device_frequency * 1e6 * ai_core_num * 4096 * 2
except (IOError, OSError, json.JSONDecodeError) as err:
logger.error(f'Error occurred when read {info_json_file_path} file: {err}')
logger.critical(f'Error occurred when read {info_json_file_path} file: {err}')
raise ProfilerIOException()
return peak_flops
@ -253,7 +253,7 @@ class FlopsParser:
optime_file_path = os.path.join(self._output_dir, self._optime_filename)
if not os.path.exists(optime_file_path):
logger.error(f'The {optime_file_path} file does not exist.')
logger.critical(f'The {optime_file_path} file does not exist.')
raise ProfilerFileNotFoundException(optime_file_path)
try:
@ -264,7 +264,7 @@ class FlopsParser:
op_name, avg_time = line.split()[:2]
op_avg_time_dict[op_name] = avg_time
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {optime_file_path} file: {err}')
logger.critical(f'Error occurred when read {optime_file_path} file: {err}')
raise ProfilerIOException()
return op_avg_time_dict
@ -356,7 +356,7 @@ class FlopsParser:
f.writelines(line + '\n')
os.chmod(output_file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error(f'Error occurred when writing {output_file_path} file: {err}')
logger.critical(f'Error occurred when writing {output_file_path} file: {err}')
raise ProfilerIOException()
for key in self._flops_summary:
@ -366,7 +366,7 @@ class FlopsParser:
json.dump(self._flops_summary, json_file)
os.chmod(output_summary_file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error(f'Error occurred when write {output_summary_file_path} file: {err}')
logger.critical(f'Error occurred when write {output_summary_file_path} file: {err}')
raise ProfilerIOException()
try:
@ -374,7 +374,7 @@ class FlopsParser:
json.dump(self._flops_sankey_diagram, json_file)
os.chmod(output_flops_scope_file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error(f'Error occurred when write {output_flops_scope_file_path} file: {err}')
logger.critical(f'Error occurred when write {output_flops_scope_file_path} file: {err}')
raise ProfilerIOException()
def _get_aicore_files(self, profiler_dir):
@ -431,7 +431,7 @@ class FlopsParser:
_step_trace_file_path = os.path.join(self._output_dir, self._step_trace_filename)
if not os.path.exists(_step_trace_file_path):
logger.error(f'The {_step_trace_file_path} file does not exist.')
logger.critical(f'The {_step_trace_file_path} file does not exist.')
raise ProfilerFileNotFoundException(_step_trace_file_path)
try:
with open(_step_trace_file_path, 'r') as f:
@ -456,7 +456,7 @@ class FlopsParser:
op_all_step_comp.append([0.0, end_point - fp])
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {optime_file_path} file: {err}')
logger.critical(f'Error occurred when read {optime_file_path} file: {err}')
raise ProfilerIOException()
logger.info("the train step is %d .", len(op_all_step_time))
if not op_all_step_time:
@ -470,7 +470,7 @@ class FlopsParser:
_timeline_file_path = os.path.join(self._output_dir, self._timeline_data_filename)
if not os.path.exists(_timeline_file_path):
logger.error(f'The {_timeline_file_path} file does not exist.')
logger.critical(f'The {_timeline_file_path} file does not exist.')
raise ProfilerFileNotFoundException(_timeline_file_path)
try:
with open(_timeline_file_path, 'r') as f:
@ -482,7 +482,7 @@ class FlopsParser:
op_start = float(line[2])
op_start_time.append([op_name, op_start])
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {optime_file_path} file: {err}')
logger.critical(f'Error occurred when read {optime_file_path} file: {err}')
raise ProfilerIOException()
if not op_start_time:
logger.warning(f'Empty when read {optime_file_path} file, please check the valid'

View File

@ -261,7 +261,7 @@ class Integrator:
"""Load data according to the parsed AICORE operator types file."""
file_path = query_latest_trace_time_file(self._profiling_dir, int(self._device_id))
if not file_path:
logger.error("Failed to find parsed trace time file.")
logger.critical("Failed to find parsed trace time file.")
raise ProfilerFileNotFoundException('parsed step trace time file')
file_path = validate_and_normalize_path(file_path)
with open(file_path, 'r') as handle:
@ -611,7 +611,7 @@ class BaseTimelineGenerator:
json_file.write(label_name_json)
os.chmod(display_file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error('Error occurred when write timeline display file: %s', err)
logger.critical('Error occurred when write timeline display file: %s', err)
raise ProfilerIOException()
def write_timeline_summary(self):
@ -628,7 +628,7 @@ class BaseTimelineGenerator:
json.dump(self._timeline_summary, json_file)
os.chmod(timeline_summary_file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error('Error occurred when write timeline summary file: %s', err)
logger.critical('Error occurred when write timeline summary file: %s', err)
raise ProfilerIOException()
@staticmethod
@ -806,7 +806,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
)
file_path = validate_and_normalize_path(file_path)
if not os.path.exists(file_path):
logger.error(f"Failed to find parsed timeline file {file_path}.")
logger.critical(f"Failed to find parsed timeline file {file_path}.")
raise ProfilerFileNotFoundException('parsed timeline file')
return file_path
@ -910,7 +910,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
# lines[1] stores the gpu time of start training.
gpu_start_time = int(lines[1].strip().split(':')[-1])
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {start_time_file_path}: {err}')
logger.critical(f'Error occurred when read {start_time_file_path}: {err}')
raise ProfilerIOException()
time_diff = gpu_start_time - host_monotonic_start_time
@ -932,7 +932,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
line_list = op_list[:2] + time
op_timeline_list.append(line_list)
except (IOError, OSError) as err:
logger.error('Error occurred when load operator timeline data intermediate file: %s', err)
logger.critical('Error occurred when load operator timeline data intermediate file: %s', err)
raise ProfilerIOException()
return op_timeline_list
@ -956,7 +956,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
line_list += args_dict[line_list[0]]
activity_timeline_list.append(line_list)
except (IOError, OSError) as err:
logger.error('Error occurred when load activity timeline data intermediate file: %s', err)
logger.critical('Error occurred when load activity timeline data intermediate file: %s', err)
raise ProfilerIOException()
return activity_timeline_list
@ -1024,7 +1024,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
step_time_list.append(step_time_item)
step_num += 1
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {step_trace_profiling_path}: {err}')
logger.critical(f'Error occurred when read {step_trace_profiling_path}: {err}')
raise ProfilerIOException()
return step_time_list
@ -1042,7 +1042,7 @@ class GpuTimelineGenerator(BaseTimelineGenerator):
# otherwise, the data format is "Default/op1 160123,12 "
return bool(len(first_string.split(',')) == 2)
except (IOError, OSError) as err:
logger.error(f'Error occurred when read {step_trace_profiling_path}: {err}')
logger.critical(f'Error occurred when read {step_trace_profiling_path}: {err}')
raise ProfilerIOException()
@ -1074,7 +1074,7 @@ class AscendTimelineGenerator(BaseTimelineGenerator):
)
file_path = validate_and_normalize_path(file_path)
if not os.path.exists(file_path):
logger.error("Failed to find parsed timeline file.")
logger.critical("Failed to find parsed timeline file.")
raise ProfilerFileNotFoundException('parsed timeline file')
timeline_list = []
@ -1086,7 +1086,7 @@ class AscendTimelineGenerator(BaseTimelineGenerator):
line_list[self._tid_idx] = f"Stream #{line_list[self._tid_idx]}"
timeline_list.append(line_list)
except (IOError, OSError) as err:
logger.error('Error occurred when read timeline intermediate file: %s', err)
logger.critical('Error occurred when read timeline intermediate file: %s', err)
raise ProfilerIOException()
return timeline_list
@ -1215,7 +1215,7 @@ class AscendTimelineGenerator(BaseTimelineGenerator):
# lines[2] stores host monotonic_raw time of start training.
host_monotonic = int(lines[2].strip().split(':')[1])
except (IOError, OSError) as err:
logger.error('Error occurred when read host_start.log: %s', err)
logger.critical('Error occurred when read host_start.log: %s', err)
raise ProfilerIOException()
try:
with open(dev_start_file_path) as f_obj:
@ -1223,7 +1223,7 @@ class AscendTimelineGenerator(BaseTimelineGenerator):
# lines[2] stores device cycle counter of start training.
dev_cntvct = int(lines[2].strip().split(':')[1])
except (IOError, OSError) as err:
logger.error('Error occurred when read dev_start.log: %s', err)
logger.critical('Error occurred when read dev_start.log: %s', err)
raise ProfilerIOException()
factor_ns_to_ms = 1e-6

View File

@ -85,7 +85,7 @@ class MemoryUsageParser:
with open(file_path, 'rb') as f:
content = f.read()
except (IOError, OSError) as err:
logger.error('Failed to read memory file: %s', err)
logger.critical('Failed to read memory file: %s', err)
raise ProfilerIOException
# Parse memory raw data from file.
@ -98,7 +98,7 @@ class MemoryUsageParser:
memory_proto.ParseFromString(content)
except ParseError as err:
msg = "Fail to parse memory proto file."
logger.error("Cannot parse the memory file. Please check the file schema.\n%s", err)
logger.critical("Cannot parse the memory file. Please check the file schema.\n%s", err)
raise ProfilerRawFileException(msg)
# Parse memory details based on graphs in the network.
@ -139,7 +139,7 @@ class MemoryUsageParser:
json.dump(content, json_file)
os.chmod(file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error('Fail to write memory file.\n%s', err)
logger.critical('Fail to write memory file.\n%s', err)
raise ProfilerIOException
def write_memory_files(self):

View File

@ -61,7 +61,7 @@ class OPComputeTimeParser:
hwts_list = []
if not os.path.exists(self._hwts_output_file):
logger.error('The hwts output file does not exist.')
logger.critical('The hwts output file does not exist.')
raise ProfilerFileNotFoundException('hwts output file')
with open(self._hwts_output_file, 'r') as data_file:
@ -169,7 +169,7 @@ class OPComputeTimeParser:
f_obj.write(','.join(timeline) + '\n')
os.chmod(file_path, stat.S_IREAD | stat.S_IWRITE)
except (IOError, OSError) as err:
logger.error('Error occurred when writing intermediate timeline file: %s', err)
logger.critical('Error occurred when writing intermediate timeline file: %s', err)
raise ProfilerIOException
def _calculate_op_execution_time(self):

View File

@ -163,7 +163,7 @@ class Profiler:
# Characters longer than 2048 are ignored, resulting in profiling option resolution errors
if len(profiling_options) > 2048:
msg = "The parameter length exceeds the limit (2048), please input valid parameters."
logger.error(msg)
logger.critical(msg)
raise ValueError(msg)
# use context interface to open profiling, for the new mindspore version(after 2020.5.21)
self._ascend_profiler = c_expression.AscendProfiler.get_instance()
@ -215,7 +215,7 @@ class Profiler:
job_dir = validate_and_normalize_path(job_dir)
if not os.path.exists(job_dir):
msg = f"Invalid ascend_job_id: {job_dir}, Please pass the absolute path of the JOB dir"
logger.error(msg)
logger.critical(msg)
raise ValueError(msg)
self._output_path, _ = os.path.split(job_dir)
@ -710,9 +710,9 @@ class Profiler:
from hccl_parser.entry import hccl_parse_op
hccl_parse_op(self._dev_id, self._output_path, hccl_path, op_type='all')
except ImportError as err:
logger.error("%s,please check if the hccl_parser-{version}-py3-none-any.whl is installed."
"The hccl_parser-{version}-py3-none-any.whl package is usually located "
"in the /usr/local/Ascend/tools Directory", err)
logger.critical("%s,please check if the hccl_parser-{version}-py3-none-any.whl is installed."
"The hccl_parser-{version}-py3-none-any.whl package is usually located "
"in the /usr/local/Ascend/tools Directory", err)
raise ImportError(err)
logger.info("Parse hccl info successfully.")
logger.info("Start analyse hccl info.")

View File

@ -80,23 +80,23 @@ def _exec_datagraph(exec_dataset, dataset_size, phase='dataset', create_data_inf
def _make_directory(path, arg_name='path'):
"""Make directory."""
if not isinstance(path, str):
logger.error("The %s is invalid, the type should be string.", arg_name)
logger.critical("The %s is invalid, the type should be string.", arg_name)
raise TypeError("The {} is invalid, the type should be string.".format(arg_name))
if path.strip() == "":
logger.error("The %s is invalid, it should be non-blank.", arg_name)
logger.critical("The %s is invalid, it should be non-blank.", arg_name)
raise ValueError("The {} is invalid, it should be non-blank.".format(arg_name))
path = os.path.realpath(path)
if len(path) > MAX_PATH_LENGTH:
logger.error("The %s length is too long, it should be limited in %s.", arg_name, MAX_PATH_LENGTH)
logger.critical("The %s length is too long, it should be limited in %s.", arg_name, MAX_PATH_LENGTH)
raise ValueError("The {} length is too long, it should be limited in {}.".format(arg_name, MAX_PATH_LENGTH))
logger.debug("The abs path is %r", path)
if os.path.exists(path):
if not os.path.isdir(path):
logger.error("The path(%r) is a file path, it should be a directory path.", path)
logger.critical("The path(%r) is a file path, it should be a directory path.", path)
raise NotADirectoryError("The path({}) is a file path, it should be a directory path.".format(path))
real_path = path
else:
@ -108,7 +108,7 @@ def _make_directory(path, arg_name='path'):
os.makedirs(path, mode=mode, exist_ok=True)
real_path = path
except PermissionError as e:
logger.error("No write permission on the directory(%r), error = %r", path, e)
logger.critical("No write permission on the directory(%r), error = %r", path, e)
raise TypeError("No write permission on the directory.")
finally:
pass
@ -251,7 +251,7 @@ def read_proto(file_name, proto_format="MINDIR", display_data=False):
pb_content = f.read()
model.ParseFromString(pb_content)
except BaseException as e:
logger.error("Failed to read the file `%s`, please check the correct of the file.", file_name)
logger.critical("Failed to read the file `%s`, please check the correct of the file.", file_name)
raise ValueError(e.__str__())
finally:
pass

View File

@ -95,7 +95,7 @@ def _update_param(param, new_param, strict_load):
if isinstance(param.data, Tensor) and isinstance(new_param.data, Tensor):
if param.data.shape != new_param.data.shape:
if not _special_process_par(param, new_param):
logger.error("Failed to combine the net and the parameters for param %s.", param.name)
logger.critical("Failed to combine the net and the parameters for param %s.", param.name)
msg = ("Net parameters {} shape({}) are different from parameter_dict's({})"
.format(param.name, param.data.shape, new_param.data.shape))
raise RuntimeError(msg)
@ -106,7 +106,7 @@ def _update_param(param, new_param, strict_load):
param.set_data(new_tensor)
return
logger.error("Failed to combine the net and the parameters for param %s.", param.name)
logger.critical("Failed to combine the net and the parameters for param %s.", param.name)
msg = ("Net parameters {} type({}) are different from parameter_dict's({})"
.format(param.name, param.data.dtype, new_param.data.dtype))
raise RuntimeError(msg)
@ -116,14 +116,14 @@ def _update_param(param, new_param, strict_load):
if isinstance(param.data, Tensor) and not isinstance(new_param.data, Tensor):
if param.data.shape != (1,) and param.data.shape != ():
logger.error("Failed to combine the net and the parameters for param %s.", param.name)
logger.critical("Failed to combine the net and the parameters for param %s.", param.name)
msg = ("Net parameters {} shape({}) is not (1,), inconsistent with parameter_dict's(scalar)."
.format(param.name, param.data.shape))
raise RuntimeError(msg)
param.set_data(initializer(new_param.data, param.data.shape, param.data.dtype))
elif isinstance(new_param.data, Tensor) and not isinstance(param.data, Tensor):
logger.error("Failed to combine the net and the parameters for param %s.", param.name)
logger.critical("Failed to combine the net and the parameters for param %s.", param.name)
msg = ("Net parameters {} type({}) are different from parameter_dict's({})"
.format(param.name, type(param.data), type(new_param.data)))
raise RuntimeError(msg)
@ -191,7 +191,7 @@ def _exec_save(ckpt_file_name, data_list, enc_key=None, enc_mode="AES-GCM"):
os.chmod(ckpt_file_name, stat.S_IRUSR)
except BaseException as e:
logger.error("Failed to save the checkpoint file %s.", ckpt_file_name)
logger.critical("Failed to save the checkpoint file %s.", ckpt_file_name)
raise e
@ -422,11 +422,11 @@ def load_checkpoint(ckpt_file_name, net=None, strict_load=False, filter_prefix=N
checkpoint_list.ParseFromString(pb_content)
except BaseException as e:
if _is_cipher_file(ckpt_file_name):
logger.error("Failed to read the checkpoint file `%s`. The file may be encrypted, please pass in the "
"correct dec_key.", ckpt_file_name)
logger.critical("Failed to read the checkpoint file `%s`. The file may be encrypted, please pass in the "
"correct dec_key.", ckpt_file_name)
else:
logger.error("Failed to read the checkpoint file `%s`, please check the correct of the file.", \
ckpt_file_name)
logger.critical("Failed to read the checkpoint file `%s`, please check the correct of the file.", \
ckpt_file_name)
raise ValueError(e.__str__())
parameter_dict = {}
@ -464,7 +464,7 @@ def load_checkpoint(ckpt_file_name, net=None, strict_load=False, filter_prefix=N
logger.info("Loading checkpoint files process is finished.")
except BaseException as e:
logger.error("Failed to load the checkpoint file `%s`.", ckpt_file_name)
logger.critical("Failed to load the checkpoint file `%s`.", ckpt_file_name)
raise RuntimeError(e.__str__())
if not parameter_dict:
@ -532,12 +532,12 @@ def load_param_into_net(net, parameter_dict, strict_load=False):
['conv1.weight']
"""
if not isinstance(net, nn.Cell):
logger.error("Failed to combine the net and the parameters.")
logger.critical("Failed to combine the net and the parameters.")
msg = ("Argument net should be a Cell, but got {}.".format(type(net)))
raise TypeError(msg)
if not isinstance(parameter_dict, dict):
logger.error("Failed to combine the net and the parameters.")
logger.critical("Failed to combine the net and the parameters.")
msg = ("Argument parameter_dict should be a dict, but got {}.".format(type(parameter_dict)))
raise TypeError(msg)
@ -549,7 +549,7 @@ def load_param_into_net(net, parameter_dict, strict_load=False):
if param.name in parameter_dict:
new_param = copy.deepcopy(parameter_dict[param.name])
if not isinstance(new_param, Parameter):
logger.error("Failed to combine the net and the parameters.")
logger.critical("Failed to combine the net and the parameters.")
msg = ("Argument parameter_dict element should be a Parameter, but got {}.".format(type(new_param)))
raise TypeError(msg)
_update_param(param, new_param, strict_load)
@ -909,7 +909,7 @@ def _save_mindir_together(net_dict, model, file_name, is_encrypt, **kwargs):
param_data = net_dict[param_name].data.asnumpy().tobytes()
param_proto.raw_data = param_data
else:
logger.error("The parameter %s in the graph is not in the network.", param_name)
logger.critical("The parameter %s in the graph is not in the network.", param_name)
raise ValueError("The parameter in the graph must be in the network.")
if not file_name.endswith('.mindir'):
file_name += ".mindir"
@ -1050,7 +1050,7 @@ def parse_print(print_file_name):
pb_content = f.read()
print_list.ParseFromString(pb_content)
except BaseException as e:
logger.error("Failed to read the print file %s, please check the correctness of the file.", print_file_name)
logger.critical("Failed to read the print file %s, please check the correctness of the file.", print_file_name)
raise ValueError(e.__str__())
tensor_list = []
@ -1082,7 +1082,7 @@ def parse_print(print_file_name):
tensor_list.append(Tensor(param_data, ms_type))
except BaseException as e:
logger.error("Failed to load the print file %s.", print_list)
logger.critical("Failed to load the print file %s.", print_list)
raise RuntimeError(e.__str__())
return tensor_list
@ -1415,8 +1415,8 @@ def load_distributed_checkpoint(network, checkpoint_filenames, predict_strategy=
try:
data_slice = np.split(data, size)[rank]
except BaseException as e:
logger.error("Failed to load opt shard slice in load distributed checkpoint for {}. Data shape is {}"
" and group is {}".format(param.name, split_param.data.shape, opt_shard_group))
logger.critical("Failed to load opt shard slice in load distributed checkpoint for {}. Data shape is {}"
" and group is {}".format(param.name, split_param.data.shape, opt_shard_group))
raise RuntimeError(e.__str__())
split_param = Parameter(Tensor(data_slice), param.name,
split_param.requires_grad, split_param.layerwise_parallel)

View File

@ -29,11 +29,11 @@ def test_log_stdout():
# print the logs without raising an exception.
from mindspore import log as logger
log_str = 'print informations'
logger.error("1 test log message error :%s", log_str)
logger.info("2 test log message info :%s", log_str)
logger.warning("3 test log message warning :%s", log_str)
logger.debug("4 test log message debug:%s", log_str)
logger.exception("5 test log message exception :{}".format(log_str))
logger.debug("test log message debug:%s", log_str)
logger.info("test log message info :%s", log_str)
logger.warning("test log message warning :%s", log_str)
logger.error("test log message error :%s", log_str)
logger.critical("test log message critical :%s", log_str)
# Clean up _global_logger to avoid affecting for next usecase
_clear_logger(logger)