L iddlZddlZddlmZddlmZddlZddlm Z ddlm Z m Z m Z e rddl Z Gdd e Z dd ed ed eed edededeefdZy)N)wraps)Optional) __version__) ExplicitEnumis_torch_availableis_torchdynamo_compilingceZdZdZdZdZdZy)Actionnonenotify notify_alwaysraiseN)__name__ __module__ __qualname__NONENOTIFY NOTIFY_ALWAYSRAISEd/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/transformers/utils/deprecation.pyr r s D F#M Err old_nameversionnew_name warn_if_greater_or_equal_version!raise_if_greater_or_equal_versionraise_if_both_namesadditional_messagec tjj|}tjjt}||k\ rd| nd|   fd} | S)a[ Function or method decorator to notify users about deprecated keyword arguments, replacing them with a new name if specified. Note that is decorator is `torch.compile`-safe, i.e. it will not cause graph breaks (but no warning will be displayed if compiling). This decorator allows you to: - Notify users when a keyword argument is deprecated. - Automatically replace deprecated keyword arguments with new ones. - Raise an error if deprecated arguments are used, depending on the specified conditions. By default, the decorator notifies the user about the deprecated argument while the `transformers.__version__` < specified `version` in the decorator. To keep notifications with any version `warn_if_greater_or_equal_version=True` can be set. Parameters: old_name (`str`): Name of the deprecated keyword argument. version (`str`): The version in which the keyword argument was (or will be) deprecated. new_name (`Optional[str]`, *optional*): The new name for the deprecated keyword argument. If specified, the deprecated keyword argument will be replaced with this new name. warn_if_greater_or_equal_version (`bool`, *optional*, defaults to `False`): Whether to show warning if current `transformers` version is greater or equal to the deprecated version. raise_if_greater_or_equal_version (`bool`, *optional*, defaults to `False`): Whether to raise `ValueError` if current `transformers` version is greater or equal to the deprecated version. raise_if_both_names (`bool`, *optional*, defaults to `False`): Whether to raise `ValueError` if both deprecated and new keyword arguments are set. additional_message (`Optional[str]`, *optional*): An additional message to append to the default deprecation message. Raises: ValueError: If raise_if_greater_or_equal_version is True and the current version is greater than or equal to the deprecated version, or if raise_if_both_names is True and both old and new keyword arguments are provided. Returns: Callable: A wrapped function that handles the deprecated keyword arguments according to the specified parameters. Example usage with renaming argument: ```python @deprecate_kwarg("reduce_labels", new_name="do_reduce_labels", version="6.0.0") def my_function(do_reduce_labels): print(do_reduce_labels) my_function(reduce_labels=True) # Will show a deprecation warning and use do_reduce_labels=True ``` Example usage without renaming argument: ```python @deprecate_kwarg("max_size", version="6.0.0") def my_function(max_size): print(max_size) my_function(max_size=1333) # Will show a deprecation warning ``` z"and removed starting from version zand will be removed in version c tj}t|jj }d|vd|vt  f d}|S)Nselfclsc j} r|djjd|}nr|djd|}tj}d} |vrV |vrR rtjntj }d d d|d d| d d| d }|j n^ |vr: 8 |vr4tj}d d d |d d }|j | <n |vrtj}d d d |d }| |d}rK r$|tjk7rtj}n%s#|tjk(rtj}|tjk(r t||tjtj fvr&tstj|td|i|S)Nr.zBoth `z` and `z` are set for `z `. Using `=z` and ignoring deprecated `z`.`z` is deprecated z for `z`. Use `z ` instead. r) stacklevel) r __class__r rrrpopr ValueErrorr warningswarn FutureWarning)argskwargs func_nameminimum_actionmessager!funcis_class_methodis_greater_or_equal_versionis_instance_methodrrr rversion_messagers r wrapped_funcz6deprecate_kwarg..wrapper..wrapped_funcxs7 I!#Aw0099:!I;G  #Aw//0)= #[[NG6!h&&81D&J^J^"8*GH:_YKWabjakklmst|m}l~Z[cZddeflmufvewwyz 8$V#(<QWAW!'hZ'77HykYabjakkuv#)::h#7x V#!'hZ'77HykY[\"'9'E$IQ'9&:;+56;;9V%+\\N:nPVP]P]>]%+[[N- ))FMM63G3G#HHQiQk g}C(( (r)inspect signatureset parameterskeysr)r7sigfunction_named_argsr<r8r:r!r9rrr rr;rs` @@rwrapperz deprecate_kwarg..wrapperqsf%!#.."5"5"78#'::#66 t3 )3 ) 3 )jr) packagingrparser) rrrrrr r!deprecated_versioncurrent_versionrDr9r;s ` ````` @@rdeprecate_kwargrI%slF#**009''--k:O"15G"G">wiH;G9E==~ Nr)NFFFN)r=r/ functoolsrtypingrpackaging.versionrErrr r torchr strboolrIrrrrQsHH\#-2.3 %(,KK KsmK'+ K (, K  K! Kr