@@ -141,6 +141,22 @@ def get_tests_dir(append_path=None):
141141 return tests_dir
142142
143143
144+ # Taken from the following PR:
145+ # https://github.com/huggingface/accelerate/pull/1964
146+ def str_to_bool (value ) -> int :
147+ """
148+ Converts a string representation of truth to `True` (1) or `False` (0).
149+ True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
150+ """
151+ value = value .lower ()
152+ if value in ("y" , "yes" , "t" , "true" , "on" , "1" ):
153+ return 1
154+ elif value in ("n" , "no" , "f" , "false" , "off" , "0" ):
155+ return 0
156+ else :
157+ raise ValueError (f"invalid truth value { value } " )
158+
159+
144160def parse_flag_from_env (key , default = False ):
145161 try :
146162 value = os .environ [key ]
@@ -920,22 +936,6 @@ def backend_supports_training(device: str):
920936 return BACKEND_SUPPORTS_TRAINING [device ]
921937
922938
923- # Taken from the following PR:
924- # https://github.com/huggingface/accelerate/pull/1964
925- def str_to_bool (value ) -> int :
926- """
927- Converts a string representation of truth to `True` (1) or `False` (0).
928- True values are `y`, `yes`, `t`, `true`, `on`, and `1`; False value are `n`, `no`, `f`, `false`, `off`, and `0`;
929- """
930- value = value .lower ()
931- if value in ("y" , "yes" , "t" , "true" , "on" , "1" ):
932- return 1
933- elif value in ("n" , "no" , "f" , "false" , "off" , "0" ):
934- return 0
935- else :
936- raise ValueError (f"invalid truth value { value } " )
937-
938-
939939# Guard for when Torch is not available
940940if is_torch_available ():
941941 # Update device function dict mapping
0 commit comments