Converts a string representation of truth to `True` (1) or `False` (0). True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
(value)
| 215 | # Taken from the following PR: |
| 216 | # https://github.com/huggingface/accelerate/pull/1964 |
| 217 | def str_to_bool(value) -> int: |
| 218 | """ |
| 219 | Converts a string representation of truth to `True` (1) or `False` (0). True values are `y`, `yes`, `t`, `true`, |
| 220 | `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`; |
| 221 | """ |
| 222 | value = value.lower() |
| 223 | if value in ("y", "yes", "t", "true", "on", "1"): |
| 224 | return 1 |
| 225 | elif value in ("n", "no", "f", "false", "off", "0"): |
| 226 | return 0 |
| 227 | else: |
| 228 | raise ValueError(f"invalid truth value {value}") |
| 229 | |
| 230 | |
| 231 | def parse_flag_from_env(key, default=False): |
no outgoing calls
no test coverage detected
searching dependent graphs…