o
    h                     @   s   d dl Z d dlZd dlmZ d dlmZ d dlZddlm	Z	 ddlm
Z
mZmZ e r/d dlZG dd	 d	e
Z		
	
	
	ddededee dedededee fddZdS )    N)wraps)Optional   )__version__   )ExplicitEnumis_torch_availableis_torchdynamo_compilingc                   @   s   e Zd ZdZdZdZdZdS )Actionnonenotifynotify_alwaysraiseN)__name__
__module____qualname__NONENOTIFYNOTIFY_ALWAYSRAISE r   r   r/var/www/html/construction_image-detection-poc/venv/lib/python3.10/site-packages/transformers/utils/deprecation.pyr
      s
    r
   Fold_nameversionnew_name warn_if_greater_or_equal_version!raise_if_greater_or_equal_versionraise_if_both_namesadditional_messagec           
         sX   t j|}t jt}||krd| nd|  fdd}	|	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 zand will be removed in version c                    sT   t  }t|j }d|v d|v t  	
fdd}|S )Nselfclsc                     s  j }r| d jj  d| }nr| d j  d| }tj}d }|v rT|v rTr/tjntj}d d d| d d|  d d|  d	}| n9|v rzd urz|vrztj}d
 d	 d| d d	}||< n|v rtj}d
 d	 d| d	}|d ur d ur| d  }rr|tjkrtj}n

s|tjkrtj}|tjkrt||tjtjfv rt	 st
j|tdd | i |S )Nr   .zBoth `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
   r   r   r   popr   
ValueErrorr	   warningswarnFutureWarning)argskwargs	func_nameminimum_actionmessage)r   funcis_class_methodis_greater_or_equal_versionis_instance_methodr   r   r   r   version_messager   r   r   wrapped_funcx   s<   8
z6deprecate_kwarg.<locals>.wrapper.<locals>.wrapped_func)inspect	signatureset
parameterskeysr   )r1   sigfunction_named_argsr6   r   r3   r   r   r   r   r5   r   )r1   r2   r4   r   wrapperq   s   
"5z deprecate_kwarg.<locals>.wrapper)	packagingr   parser   )
r   r   r   r   r   r   r   deprecated_versioncurrent_versionr?   r   r>   r   deprecate_kwarg%   s   C
?rD   )NFFFN)r7   r)   	functoolsr   typingr   packaging.versionr@    r   r   r   r	   torchr
   strboolrD   r   r   r   r   <module>   s<   
