Skip to content

Commit 52ba04b

Browse files
fzyzcjytarinkk
authored andcommitted
Tiny add warning when cannot recognize bool env var (sgl-project#5348)
1 parent 44adc90 commit 52ba04b

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

python/sglang/srt/utils.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,24 @@
7878

7979
HIP_FP8_E4M3_FNUZ_MAX = 224.0
8080

81+
_warned_bool_env_var_keys = set()
82+
8183

8284
def get_bool_env_var(name: str, default: str = "false") -> bool:
8385
value = os.getenv(name, default)
84-
return value.lower() in ("true", "1")
86+
value = value.lower()
87+
88+
truthy_values = ("true", "1")
89+
falsy_values = ("false", "0")
90+
91+
if (value not in truthy_values) and (value not in falsy_values):
92+
if value not in _warned_bool_env_var_keys:
93+
logger.warning(
94+
f"get_bool_env_var({name}) see non-understandable value={value} and treat as false"
95+
)
96+
_warned_bool_env_var_keys.add(value)
97+
98+
return value in truthy_values
8599

86100

87101
# https://pytorch.org/docs/stable/notes/hip.html#checking-for-hip

0 commit comments

Comments
 (0)