§
    [zni  ã                   ó  — d dl Z d dlZd dlmZ d dlmZ d dlmZ d dlZddl	m
Z
mZ  ej        e¦  «        ZdZ G d„ d	e¦  «        Z G d
„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Z G d„ de¦  «        Zdededefd„ZdS )é    N)ÚABC)Údeepcopy)ÚOptionalé   )Úadd_start_docstringsÚloggingaå  
    Args:
        input_ids (`torch.LongTensor` of shape `(batch_size, sequence_length)`):
            Indices of input sequence tokens in the vocabulary.

            Indices can be obtained using [`AutoTokenizer`]. See [`PreTrainedTokenizer.encode`] and
            [`PreTrainedTokenizer.__call__`] for details.

            [What are input IDs?](../glossary#input-ids)
        scores (`torch.FloatTensor` of shape `(batch_size, config.vocab_size)`):
            Prediction scores of a language modeling head. These can be scores for each vocabulary token before SoftMax
            or scores for each vocabulary token after SoftMax. If this stopping criteria depends on the `scores` input,
            make sure you pass `return_dict_in_generate=True, output_scores=True` to `generate`.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional stopping criteria specific kwargs.

    Return:
        `bool`. `False` indicates we should continue, `True` indicates we should stop.

c                   ó\   — e Zd ZdZ ee¦  «        dej        dej        de	fd„¦   «         Z
dS )ÚStoppingCriteriazðAbstract base class for all stopping criteria that can be applied during generation.

    If your stopping criteria depends on the `scores` input, make sure you pass `return_dict_in_generate=True,
    output_scores=True` to `generate`.
    Ú	input_idsÚscoresÚreturnc                 ó    — t          d¦  «        ‚)Nz'StoppingCriteria needs to be subclassed)ÚNotImplementedError©Úselfr   r   Úkwargss       ú‰/var/www/html/cool-property-finder/image-detection-backend/venv/lib/python3.11/site-packages/transformers/generation/stopping_criteria.pyÚ__call__zStoppingCriteria.__call__,   s   € å!Ð"KÑLÔLÐLó    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú"STOPPING_CRITERIA_INPUTS_DOCSTRINGÚtorchÚ
LongTensorÚFloatTensorÚboolr   © r   r   r
   r
   %   sp   € € € € € ðð ð ÐÐ<Ñ=Ô=ðM %Ô"2ð M¸EÔ<Mð MÐ\`ð Mð Mð Mñ >Ô=ðMð Mð Mr   r
   c                   óz   — e Zd ZdZd
dedee         fd„Z ee¦  «        de	j
        de	j        defd	„¦   «         ZdS )ÚMaxLengthCriteriaaû  
    This class can be used to stop generation whenever the full generated number of tokens exceeds `max_length`. Keep
    in mind for decoder-only type of transformers, this will include the initial prompted tokens.

    Args:
        max_length (`int`):
            The maximum length that the output sequence can have in number of tokens.
        max_position_embeddings (`int`, *optional*):
            The maximum model length, as defined by the model's `config.max_position_embeddings` attribute.
    NÚ
max_lengthÚmax_position_embeddingsc                 ó"   — || _         || _        d S ©N)r"   r#   )r   r"   r#   s      r   Ú__init__zMaxLengthCriteria.__init__=   s   € Ø$ˆŒØ'>ˆÔ$Ð$Ð$r   r   r   r   c                 ó¤   — |j         d         }|| j        k    }| j        �0|s.|| j        k    r#t                               d| j        › d�¦  «         |S )NéÿÿÿÿzrThis is a friendly reminder - the current text generation call will exceed the model's predefined maximum length (zb). Depending on the model, you may observe exceptions, performance degradation, or nothing at all.)Úshaper"   r#   ÚloggerÚwarning_once)r   r   r   r   Úcur_lenÚis_dones         r   r   zMaxLengthCriteria.__call__A   ss   € à”/ "Ô%ˆØ˜Tœ_Ò,ˆØÔ'Ð3¸GÐ3ÈÐSWÔSoÒHoÐHoÝ×ÒðJØ#'Ô#?ðJð Jð Jñô ð ð
 ˆr   r%   )r   r   r   r   Úintr   r&   r   r   r   r   r   r   r   r   r   r   r!   r!   1   s’   € € € € € ð	ð 	ð?ð ? 3ð ?ÀÈ#Äð ?ð ?ð ?ð ?ð ÐÐ<Ñ=Ô=ð	 %Ô"2ð 	¸EÔ<Mð 	Ð\`ð 	ð 	ð 	ñ >Ô=ð	ð 	ð 	r   r!   c                   ól   — e Zd ZdZdedefd„Z ee¦  «        dej	        dej
        defd„¦   «         Zd	S )
ÚMaxNewTokensCriteriaaå  
    This class can be used to stop generation whenever the generated number of tokens exceeds `max_new_tokens`. Keep in
    mind for decoder-only type of transformers, this will **not** include the initial prompted tokens. This is very
    close to `MaxLengthCriteria` but ignores the number of initial tokens.

    Args:
        start_length (`int`):
            The number of initial tokens.
        max_new_tokens (`int`):
            The maximum number of tokens to generate.
    Ústart_lengthÚmax_new_tokensc                 óx   — t          j        d||z   › d�t          ¦  «         || _        || _        ||z   | _        d S )NzYThe class `MaxNewTokensCriteria` is deprecated. Please use `MaxLengthCriteria(max_length=z=)` with `max_length = start_length + max_new_tokens` instead.)ÚwarningsÚwarnÚFutureWarningr1   r2   r"   )r   r1   r2   s      r   r&   zMaxNewTokensCriteria.__init__[   s]   € ÝŒðIØ8DÀ~Ñ8UðIð Ið Iõ ñ		
ô 	
ð 	
ð )ˆÔØ,ˆÔØ&¨Ñ7ˆŒˆˆr   r   r   r   c                 ó.   — |j         d         | j        k    S )Nr(   )r)   r"   r   s       r   r   zMaxNewTokensCriteria.__call__f   s   € àŒ˜rÔ" d¤oÒ5Ð5r   N)r   r   r   r   r.   r&   r   r   r   r   r   r   r   r   r   r   r0   r0   N   s‰   € € € € € ð
ð 
ð	8 Sð 	8¸#ð 	8ð 	8ð 	8ð 	8ð ÐÐ<Ñ=Ô=ð6 %Ô"2ð 6¸EÔ<Mð 6Ð\`ð 6ð 6ð 6ñ >Ô=ð6ð 6ð 6r   r0   c                   óz   — e Zd ZdZd
dedee         fd„Z ee¦  «        de	j
        de	j        defd	„¦   «         ZdS )ÚMaxTimeCriteriaaâ  
    This class can be used to stop generation whenever the full generation exceeds some amount of time. By default, the
    time will start being counted when you initialize this function. You can override this by passing an
    `initial_time`.

    Args:
        max_time (`float`):
            The maximum allowed time in seconds for the generation.
        initial_time (`float`, *optional*, defaults to `time.time()`):
            The start of the generation allowed time.
    NÚmax_timeÚinitial_timestampc                 óL   — || _         |€t          j        ¦   «         n|| _        d S r%   )r:   Útimer;   )r   r:   r;   s      r   r&   zMaxTimeCriteria.__init__x   s'   € Ø ˆŒØ0AÐ0I¥¤¡¤ ÐO`ˆÔÐÐr   r   r   r   c                 óJ   — t          j         ¦   «         | j        z
  | j        k    S r%   )r=   r;   r:   r   s       r   r   zMaxTimeCriteria.__call__|   s   € åŒy‰{Œ{˜TÔ3Ñ3°d´mÒCÐCr   r%   )r   r   r   r   Úfloatr   r&   r   r   r   r   r   r   r   r   r   r   r9   r9   k   s¢   € € € € € ð
ð 
ðað a ð a¸8ÀE¼?ð að að að að ÐÐ<Ñ=Ô=ðD %Ô"2ð D¸EÔ<Mð DÐ\`ð Dð Dð Dñ >Ô=ðDð Dð Dr   r9   c                   ó€   — e Zd Z ee¦  «        dej        dej        defd„¦   «         Z	e
dee         fd„¦   «         ZdS )ÚStoppingCriteriaListr   r   r   c                 ó>   ‡‡— t          ˆˆfd„| D ¦   «         ¦  «        S )Nc              3   ó0   •K  — | ]} |‰‰¦  «        V — Œd S r%   r   )Ú.0Úcriteriar   r   s     €€r   ú	<genexpr>z0StoppingCriteriaList.__call__.<locals>.<genexpr>„   s/   øè è € ÐDÐD°8�8�8˜I vÑ.Ô.ÐDÐDÐDÐDÐDÐDr   )Úanyr   s    `` r   r   zStoppingCriteriaList.__call__‚   s*   øø€ åÐDÐDÐDÐDÐD¸tÐDÑDÔDÑDÔDÐDr   c                 óˆ   — | D ]>}t          |t          ¦  «        r	|j        c S t          |t          ¦  «        r	|j        c S Œ?d S r%   )Ú
isinstancer!   r"   r0   )r   Ústopping_criteriums     r   r"   zStoppingCriteriaList.max_length†   sb   € à"&ð 	5ð 	5ÐÝÐ,Õ.?Ñ@Ô@ð 5Ø)Ô4Ð4Ð4Ð4ÝÐ.Õ0DÑEÔEð 5Ø)Ô4Ð4Ð4Ð4ð5àˆtr   N)r   r   r   r   r   r   r   r   r   r   Úpropertyr   r.   r"   r   r   r   rA   rA   �   s�   € € € € € ØÐÐ<Ñ=Ô=ðE %Ô"2ð E¸EÔ<Mð EÐ\`ð Eð Eð Eñ >Ô=ðEð ð˜H SœMð ð ð ñ „Xðð ð r   rA   Ústopping_criteriar"   r   c                 óÂ   — | j         }t          | ¦  «        }|�!||k    rt          j        dt          ¦  «         n%|€#|                     t          |¬¦  «        ¦  «         |S )NzOYou set different `max_length` for stopping criteria and `max_length` parameter)r"   )r"   r   r4   r5   ÚUserWarningÚappendr!   )rL   r"   Ústopping_max_lengthÚnew_stopping_criterias       r   Úvalidate_stopping_criteriarR   �   sn   € Ø+Ô6ÐÝ$Ð%6Ñ7Ô7ÐØÐ&Ð+>À*Ò+LÐ+LÝŒÐgÕitÑuÔuÐuÐuØ	Ð	$Ø×$Ò$Õ%6À*Ð%MÑ%MÔ%MÑNÔNÐNØ Ð r   )r=   r4   Úabcr   Úcopyr   Útypingr   r   Úutilsr   r   Ú
get_loggerr   r*   r   r
   r!   r0   r9   ÚlistrA   r.   rR   r   r   r   ú<module>rY      s¥  ðØ €€€Ø €€€Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à €€€à 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1Ð 1ð 
ˆÔ	˜HÑ	%Ô	%€ð&Ð "ð,	Mð 	Mð 	Mð 	Mð 	M�sñ 	Mô 	Mð 	Mðð ð ð ð Ð(ñ ô ð ð:6ð 6ð 6ð 6ð 6Ð+ñ 6ô 6ð 6ð:Dð Dð Dð Dð DÐ&ñ Dô Dð Dð,ð ð ð ð ˜4ñ ô ð ð!Ð2Fð !ÐTWð !Ð\pð !ð !ð !ð !ð !ð !r   