mirror of
https://github.com/zebrajr/pytorch.git
synced 2025-12-07 12:21:27 +01:00
Improve TORCH_LOGS settings error msg (#97264)
Lists registered loggable entities if an invalid settings string is passed via TORCH_LOGS [before](https://gist.github.com/mlazos/91fcbc3d577f874bcb3daea44f8b41f2) [after](https://gist.github.com/mlazos/815ea9e76aca665602228f960e0eb0d6) Pull Request resolved: https://github.com/pytorch/pytorch/pull/97264 Approved by: https://github.com/ezyang, https://github.com/jansel
This commit is contained in:
parent
aab34a476f
commit
c37ab85d96
|
|
@ -253,15 +253,26 @@ def _validate_settings(settings):
|
|||
return re.fullmatch(_gen_settings_regex(), settings) is not None
|
||||
|
||||
|
||||
def _invalid_settings_err_msg(settings):
|
||||
entities = "\n " + "\n ".join(
|
||||
itertools.chain(
|
||||
log_registry.log_alias_to_log_qname.keys(), log_registry.artifact_names
|
||||
)
|
||||
)
|
||||
msg = (
|
||||
f"Invalid log settings: {settings}, must be a comma separated list of fully qualified module names, "
|
||||
f"registered log names or registered artifact names.\nCurrently registered names: {entities}"
|
||||
)
|
||||
return msg
|
||||
|
||||
|
||||
@functools.lru_cache()
|
||||
def _parse_log_settings(settings):
|
||||
if settings == "":
|
||||
return dict()
|
||||
|
||||
if not _validate_settings(settings):
|
||||
raise ValueError(
|
||||
f"Invalid log settings: {settings}, must be a comma separated list of registerered log or artifact names."
|
||||
)
|
||||
raise ValueError(_invalid_settings_err_msg(settings))
|
||||
|
||||
settings = re.sub(r"\s+", "", settings)
|
||||
log_names = settings.split(",")
|
||||
|
|
@ -295,9 +306,7 @@ def _parse_log_settings(settings):
|
|||
log_registry.register_child_log(name)
|
||||
log_state.enable_log(name, level)
|
||||
else:
|
||||
raise ValueError(
|
||||
f"Invalid log settings: '{settings}', must be a comma separated list of log or artifact names."
|
||||
)
|
||||
raise ValueError(_invalid_settings_err_msg(settings))
|
||||
|
||||
return log_state
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user