2424import numpy
2525import torch
2626from compressed_tensors .quantization import disable_quantization , enable_quantization
27+ from compressed_tensors .utils import deprecated
2728from loguru import logger
2829from transformers import PreTrainedModel
2930
8889##############################
8990
9091
92+ @deprecated ()
9193def flatten_iterable (li : Iterable ):
9294 """
9395 :param li: a possibly nested iterable of items to be flattened
@@ -105,6 +107,7 @@ def _flatten_gen(_li):
105107 return list (_flatten_gen (li ))
106108
107109
110+ @deprecated ()
108111def convert_to_bool (val : Any ):
109112 """
110113 :param val: the value to be converted to a bool,
@@ -119,6 +122,7 @@ def convert_to_bool(val: Any):
119122 )
120123
121124
125+ @deprecated ()
122126def validate_str_iterable (
123127 val : Union [str , Iterable [str ]], error_desc : str = ""
124128) -> Union [str , Iterable [str ]]:
@@ -144,6 +148,7 @@ def validate_str_iterable(
144148 raise ValueError ("unsupported type ({}) given in {}" .format (val , error_desc ))
145149
146150
151+ @deprecated ()
147152def bucket_iterable (
148153 val : Iterable [Any ],
149154 num_buckets : int = 3 ,
@@ -191,6 +196,7 @@ def bucket_iterable(
191196INTERPOLATION_FUNCS = ["linear" , "cubic" , "inverse_cubic" ]
192197
193198
199+ @deprecated (future_name = "torch.lerp" )
194200def interpolate (
195201 x_cur : float , x0 : float , x1 : float , y0 : Any , y1 : Any , inter_func : str = "linear"
196202) -> Any :
@@ -243,6 +249,7 @@ def interpolate(
243249 return y_per * (y1 - y0 ) + y0
244250
245251
252+ @deprecated (future_name = "torch.lerp" )
246253def interpolate_list_linear (
247254 measurements : List [Tuple [float , float ]], x_val : Union [float , List [float ]]
248255) -> List [Tuple [float , float ]]:
@@ -279,6 +286,7 @@ def interpolate_list_linear(
279286 return interpolated
280287
281288
289+ @deprecated (future_name = "torch.lerp" )
282290def interpolated_integral (measurements : List [Tuple [float , float ]]):
283291 """
284292 Calculate the interpolated integal for a group of measurements of the form
@@ -308,6 +316,7 @@ def interpolated_integral(measurements: List[Tuple[float, float]]):
308316 return integral
309317
310318
319+ @deprecated ()
311320def clean_path (path : str ) -> str :
312321 """
313322 :param path: the directory or file path to clean
@@ -316,6 +325,7 @@ def clean_path(path: str) -> str:
316325 return os .path .abspath (os .path .expanduser (path ))
317326
318327
328+ @deprecated ()
319329def create_dirs (path : str ):
320330 """
321331 :param path: the directory path to try and create
@@ -332,6 +342,7 @@ def create_dirs(path: str):
332342 raise
333343
334344
345+ @deprecated ()
335346def create_parent_dirs (path : str ):
336347 """
337348 :param path: the file path to try to create the parent directories for
@@ -340,6 +351,7 @@ def create_parent_dirs(path: str):
340351 create_dirs (parent )
341352
342353
354+ @deprecated ()
343355def create_unique_dir (path : str , check_number : int = 0 ) -> str :
344356 """
345357 :param path: the file path to create a unique version of
@@ -355,6 +367,7 @@ def create_unique_dir(path: str, check_number: int = 0) -> str:
355367 return create_unique_dir (path , check_number + 1 )
356368
357369
370+ @deprecated ()
358371def path_file_count (path : str , pattern : str = "*" ) -> int :
359372 """
360373 Return the number of files that match the given pattern under the given path
@@ -368,6 +381,7 @@ def path_file_count(path: str, pattern: str = "*") -> int:
368381 return len (fnmatch .filter (os .listdir (path ), pattern ))
369382
370383
384+ @deprecated ()
371385def path_file_size (path : str ) -> int :
372386 """
373387 Return the total size, in bytes, for a path on the file system
@@ -405,6 +419,7 @@ def path_file_size(path: str) -> int:
405419 return total_size
406420
407421
422+ @deprecated ()
408423def is_url (val : str ):
409424 """
410425 :param val: value to check if it is a url or not
@@ -429,6 +444,7 @@ def is_url(val: str):
429444NDARRAY_KEY = "ndarray"
430445
431446
447+ @deprecated ()
432448def load_numpy (file_path : str ) -> Union [numpy .ndarray , Dict [str , numpy .ndarray ]]:
433449 """
434450 Load a numpy file into either an ndarray or an OrderedDict representing what
@@ -449,6 +465,7 @@ def load_numpy(file_path: str) -> Union[numpy.ndarray, Dict[str, numpy.ndarray]]
449465 return array
450466
451467
468+ @deprecated ()
452469def save_numpy (
453470 array : Union [numpy .ndarray , Dict [str , numpy .ndarray ], Iterable [numpy .ndarray ]],
454471 export_dir : str ,
@@ -488,6 +505,7 @@ def save_numpy(
488505 return export_path
489506
490507
508+ @deprecated ()
491509def _fix_loaded_numpy (array ) -> Union [numpy .ndarray , Dict [str , numpy .ndarray ]]:
492510 if not isinstance (array , numpy .ndarray ):
493511 tmp_arrray = array
@@ -498,6 +516,7 @@ def _fix_loaded_numpy(array) -> Union[numpy.ndarray, Dict[str, numpy.ndarray]]:
498516 return array
499517
500518
519+ @deprecated ()
501520def load_numpy_from_tar (
502521 path : str ,
503522) -> List [Union [numpy .ndarray , Dict [str , numpy .ndarray ]]]:
@@ -522,6 +541,7 @@ def load_numpy_from_tar(
522541 return data
523542
524543
544+ @deprecated ()
525545def load_numpy_list (
526546 data : Union [str , Iterable [Union [str , numpy .ndarray , Dict [str , numpy .ndarray ]]]],
527547) -> List [Union [numpy .ndarray , Dict [str , numpy .ndarray ]]]:
@@ -553,6 +573,7 @@ def load_numpy_list(
553573 return loaded
554574
555575
576+ @deprecated ()
556577def load_labeled_data (
557578 data : Union [str , Iterable [Union [str , numpy .ndarray , Dict [str , numpy .ndarray ]]]],
558579 labels : Union [
@@ -631,6 +652,7 @@ def __len__(self):
631652
632653 return len (self ._items [list (self ._items .keys ())[0 ]])
633654
655+ @deprecated ()
634656 def append (self , item : Union [numpy .ndarray , Dict [str , numpy .ndarray ]]):
635657 """
636658 Append a new item into the current batch.
@@ -684,6 +706,7 @@ def append(self, item: Union[numpy.ndarray, Dict[str, numpy.ndarray]]):
684706
685707 self ._items [key ].append (val )
686708
709+ @deprecated ()
687710 def stack (self ) -> Dict [str , numpy .ndarray ]:
688711 """
689712 Stack the current items into a batch along a new, zeroed dimension
@@ -698,6 +721,7 @@ def stack(self) -> Dict[str, numpy.ndarray]:
698721 return batch_dict
699722
700723
724+ @deprecated ()
701725def tensor_export (
702726 tensor : Union [numpy .ndarray , Dict [str , numpy .ndarray ], Iterable [numpy .ndarray ]],
703727 export_dir : str ,
@@ -734,6 +758,7 @@ def tensor_export(
734758 return export_path
735759
736760
761+ @deprecated ()
737762def tensors_export (
738763 tensors : Union [numpy .ndarray , Dict [str , numpy .ndarray ], Iterable [numpy .ndarray ]],
739764 export_dir : str ,
@@ -765,6 +790,7 @@ def tensors_export(
765790 return exported_paths
766791
767792
793+ @deprecated ()
768794def _tensors_export_recursive (
769795 tensors : Union [numpy .ndarray , Iterable [numpy .ndarray ]],
770796 export_dir : str ,
@@ -799,6 +825,7 @@ def _tensors_export_recursive(
799825 )
800826
801827
828+ @deprecated ()
802829def _tensors_export_batch (
803830 tensors : Union [numpy .ndarray , Dict [str , numpy .ndarray ], Iterable [numpy .ndarray ]],
804831 export_dir : str ,
@@ -845,6 +872,7 @@ def _tensors_export_batch(
845872 )
846873
847874
875+ @deprecated ()
848876def json_to_jsonl (json_file_path : str , overwrite : bool = True ):
849877 """
850878 Converts a json list file to jsonl file format (used for sharding efficienty)
@@ -876,6 +904,7 @@ def json_to_jsonl(json_file_path: str, overwrite: bool = True):
876904 jsonl_file .write ("\n " ) # newline
877905
878906
907+ @deprecated ()
879908def deprecation_warning (message : str ):
880909 warnings .simplefilter ("always" , DeprecationWarning )
881910 warnings .warn (
@@ -946,6 +975,7 @@ def import_from_path(path: str) -> str:
946975 raise AttributeError (f"Cannot find { class_name } in { _path } " )
947976
948977
978+ @deprecated ()
949979def getattr_chain (obj : Any , chain_str : str , * args , ** kwargs ) -> Any :
950980 """
951981 Chain multiple getattr calls, separated by `.`
@@ -1063,6 +1093,7 @@ def calibration_forward_context(model: torch.nn.Module):
10631093 yield
10641094
10651095
1096+ @deprecated ()
10661097@contextlib .contextmanager
10671098def disable_lm_head (model : torch .nn .Module ):
10681099 """
0 commit comments