mirror of
https://github.com/pytorch/pytorch.git
synced 2025-10-20 21:14:14 +08:00
fix logging setup issue for Windows.. (#159887)
When we setup logging config as guide: https://docs.pytorch.org/docs/stable/logging.html Such as: TORCH_LOGS="+schedule,+inductor,+output_code" On Linux, it shows as: ```cmd declare -x SSH_TTY="/dev/pts/0" declare -x TERM="xterm" declare -x TORCH_LOGS="+schedule,+inductor,+output_code" declare -x USER="xu" ``` On Windows, it shows as: ```cmd TORCHINDUCTOR_WINDOWS_TESTS=1 TORCH_LOGS="+schedule,+inductor,+output_code" UCRTVersion=10.0.22000.0 ``` For Linux, it shows quotes by default, And Windows is not shows quotes. Besides that, Windows would auto assemble quotes when env var processing. On Linux, we will get variable: "+schedule,+inductor,+output_code" On Windows, we will get variable: '"+schedule,+inductor,+output_code"' So, we need remove the outer quotes for Windows. Pull Request resolved: https://github.com/pytorch/pytorch/pull/159887 Approved by: https://github.com/angelayi
This commit is contained in:
@ -726,8 +726,49 @@ Valid settings:
|
||||
return msg
|
||||
|
||||
|
||||
def process_env_var_string_for_windows(env_var_str: str) -> str:
|
||||
"""
|
||||
When we setup logging config as guide: https://docs.pytorch.org/docs/stable/logging.html
|
||||
Such as:
|
||||
TORCH_LOGS="+schedule,+inductor,+output_code"
|
||||
|
||||
On Linux, it shows as:
|
||||
declare -x SSH_TTY="/dev/pts/0"
|
||||
declare -x TERM="xterm"
|
||||
declare -x TORCH_LOGS="+schedule,+inductor,+output_code"
|
||||
declare -x USER="xu"
|
||||
|
||||
On Windows, it shows as:
|
||||
TORCHINDUCTOR_WINDOWS_TESTS=1
|
||||
TORCH_LOGS="+schedule,+inductor,+output_code"
|
||||
UCRTVersion=10.0.22000.0
|
||||
|
||||
For Linux, it shows quotes by default, And Windows is not shows quotes.
|
||||
Besides that, Windows would auto assemble quotes when env var processing.
|
||||
On Linux, we will get variable: "+schedule,+inductor,+output_code"
|
||||
On Windows, we will get variable: '"+schedule,+inductor,+output_code"'
|
||||
|
||||
So, we need remove the outer quotes for Windows.
|
||||
"""
|
||||
_IS_WINDOWS = sys.platform == "win32"
|
||||
|
||||
def remove_outer_quotes(s: str) -> str:
|
||||
if len(s) >= 2 and (
|
||||
(s[0] == '"' and s[-1] == '"') or (s[0] == "'" and s[-1] == "'")
|
||||
):
|
||||
return s[1:-1]
|
||||
return s
|
||||
|
||||
if _IS_WINDOWS:
|
||||
env_var_str = remove_outer_quotes(env_var_str)
|
||||
|
||||
return env_var_str
|
||||
|
||||
|
||||
@functools.lru_cache
|
||||
def _parse_log_settings(settings):
|
||||
settings = process_env_var_string_for_windows(settings)
|
||||
|
||||
if settings == "":
|
||||
return {}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user