|
24 | 24 | import warnings
|
25 | 25 | from ast import literal_eval
|
26 | 26 | from collections.abc import Callable, Iterable, Sequence
|
27 |
| -from distutils.util import strtobool |
28 | 27 | from math import log10
|
29 | 28 | from pathlib import Path
|
30 | 29 | from typing import TYPE_CHECKING, Any, TypeVar, cast, overload
|
|
78 | 77 | "run_cmd",
|
79 | 78 | ]
|
80 | 79 |
|
| 80 | +def _strtobool(val: str) -> bool: |
| 81 | + """ |
| 82 | + Replaces deprecated (pre python 3.12) |
| 83 | + distutils strtobool function. |
| 84 | +
|
| 85 | + True values are y, yes, t, true, on and 1; |
| 86 | + False values are n, no, f, false, off and 0. |
| 87 | + Raises ValueError if val is anything else. |
| 88 | + """ |
| 89 | + val = val.lower() |
| 90 | + if val in ("y", "yes", "t", "true", "on", "1"): |
| 91 | + return 1 |
| 92 | + elif val in ("n", "no", "f", "false", "off", "0"): |
| 93 | + return 0 |
| 94 | + else: |
| 95 | + raise ValueError(f"invalid truth value {val}") |
| 96 | + |
| 97 | + |
81 | 98 | _seed = None
|
82 | 99 | _flag_deterministic = torch.backends.cudnn.deterministic
|
83 | 100 | _flag_cudnn_benchmark = torch.backends.cudnn.benchmark
|
@@ -400,7 +417,7 @@ def _parse_var(s):
|
400 | 417 | d[key] = literal_eval(value)
|
401 | 418 | except ValueError:
|
402 | 419 | try:
|
403 |
| - d[key] = bool(strtobool(str(value))) |
| 420 | + d[key] = bool(_strtobool(str(value))) |
404 | 421 | except ValueError:
|
405 | 422 | d[key] = value
|
406 | 423 | return d
|
|
0 commit comments