+
    QV-já@  ã                  óÒ   € ^ RI Ht ^ RIt^ RIt^ RIt^ RIHt ^ RIHtH	t	H
t
 ]'       d   ^RIHt  ! R R4      t ! R R	]4      t ! R
 R]4      t ! R R]4      t ! R R]4      tR# )é    )ÚannotationsN)ÚQueue)ÚTYPE_CHECKINGÚAnyÚcast)ÚPreTrainedTokenizerBasec                  ó&   € ] tR t^tRtR tR tRtR# )ÚBaseStreamerz?
Base class from which `.generate()` streamers should inherit.
c                ó   € \        4       h)z;Function that is called by `.generate()` to push new tokens©ÚNotImplementedError©ÚselfÚvalues   &&Úr/Volumes/fast/ai/experiments/ui-tars-smoke/.venv/lib/python3.14/site-packages/transformers/generation/streamers.pyÚputÚBaseStreamer.put!   ó   € ä!Ó#Ð#ó    c                ó   € \        4       h)zHFunction that is called by `.generate()` to signal the end of generationr   ©r   s   &r   ÚendÚBaseStreamer.end%   r   r   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__static_attributes__r   r   r   r
   r
      s   † ñò$ö$r   r
   c                  óL   € ] tR t^*tRtRR R lltR tR tRR R lltR t	R	t
R
# )ÚTextStreameraT  
Simple text streamer that prints the token(s) to stdout as soon as entire words are formed.

Parameters:
    tokenizer (`AutoTokenizer`):
        The tokenizer used to decode the tokens.
    skip_prompt (`bool`, *optional*, defaults to `False`):
        Whether to skip the prompt to `.generate()` or not. Useful e.g. for chatbots.
    decode_kwargs (`dict`, *optional*):
        Additional keyword arguments to pass to the tokenizer's `decode` method.

Examples:

    ```python
    >>> from transformers import AutoModelForCausalLM, AutoTokenizer, TextStreamer

    >>> tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
    >>> model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")
    >>> inputs = tok(["An increasing sequence: one,"], return_tensors="pt")
    >>> streamer = TextStreamer(tok)

    >>> # Despite returning the usual output, the streamer will also print the generated text to stdout.
    >>> _ = model.generate(**inputs, streamer=streamer, max_new_tokens=20)
    An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,
    ```
c               ó$   € V ^8„  d   QhRRRRRR/# )é   Ú	tokenizerr   Úskip_promptÚboolÚdecode_kwargsr   r   )Úformats   "r   Ú__annotate__ÚTextStreamer.__annotate__F   s#   € ÷ +ñ +Ð"9ð +Èð +Ðgjñ +r   c                	óT   € Wn         W n        W0n        . V n        ^ V n        RV n        R# )r   TN)r%   r&   r(   Útoken_cacheÚ	print_lenÚnext_tokens_are_prompt)r   r%   r&   r(   s   &&&,r   Ú__init__ÚTextStreamer.__init__F   s,   € Ø"ŒØ&ÔØ*Ôð ')ˆÔØˆŒØ&*ˆÖ#r   c                óÖ  € \        VP                  4      ^8”  d$   VP                  ^ ,          ^8”  d   \        R4      h\        VP                  4      ^8”  d
   V^ ,          pV P                  '       d   V P                  '       d
   RV n        R# V P
                  P                  VP                  4       4       \        \        V P                  P                  ! V P
                  3/ V P                  B 4      pVP                  R4      '       d   W P                  R p. V n        ^ V n        M®\        V4      ^ 8”  dY   V P                  \!        VR,          4      4      '       d2   W P                  R pV ;P                  \        V4      ,          un        MFW P                  VP#                  R4      ^,            pV ;P                  \        V4      ,          un        V P%                  V4       R# )z]
Receives tokens, decodes them, and prints them to stdout as soon as they form entire words.
z'TextStreamer only supports batch size 1FNÚ
Ú éÿÿÿÿ)ÚlenÚshapeÚ
ValueErrorr&   r/   r-   ÚextendÚtolistr   Ústrr%   Údecoder(   Úendswithr.   Ú_is_chinese_charÚordÚrfindÚon_finalized_text)r   r   ÚtextÚprintable_texts   &&  r   r   ÚTextStreamer.putP   sf  € ô ˆu�{‰{Ó˜aÔ E§K¡K°¥N°QÔ$6ÜÐFÓGÐGÜ�—‘Ó Ô!Ø˜!•HˆEà××Ð × ;× ;Ð ;Ø*/ˆDÔ'Ùð 	×Ñ×Ñ §¡£Ô/Ü”C˜Ÿ™×.Ò.¨t×/?Ñ/?ÑVÀ4×CUÑCUÑVÓWˆð �=‰=˜×ÒØ!§.¡.Ð"2Ð3ˆNØ!ˆDÔØˆD�Nä�‹Y˜Œ]˜t×4Ñ4´S¸¸b½³]×CÒCØ!§.¡.Ð"2Ð3ˆNØ�NŠNœc .Ó1Õ1ŽNð "§.¡.°4·:±:¸c³?ÀQÕ3FÐGˆNØ�NŠNœc .Ó1Õ1�Nà×Ñ˜~Ö.r   c                ó*  € \        V P                  4      ^ 8”  d]   \        \        V P                  P
                  ! V P                  3/ V P                  B 4      pWP                  R p. V n        ^ V n        MRpRV n        V P                  VRR7       R# )z;Flushes any remaining cache and prints a newline to stdout.NÚ T)Ú
stream_end)
r6   r-   r   r;   r%   r<   r(   r.   r/   rA   )r   rB   rC   s   &  r   r   ÚTextStreamer.endr   s�   € ô ˆt×ÑÓ  1Ô$Üœ˜TŸ^™^×2Ò2°4×3CÑ3CÑZÀt×GYÑGYÑZÓ[ˆDØ!§.¡.Ð"2Ð3ˆNØ!ˆDÔØˆD�NàˆNà&*ˆÔ#Ø×Ñ˜~¸$ÐÖ?r   c               ó    € V ^8„  d   QhRRRR/# ©r$   rB   r;   rG   r'   r   )r)   s   "r   r*   r+   €   s   € ÷ Dñ D cð D°tñ Dr   c                ó6   € \        TRV'       g   RMRR7       R# )zNPrints the new text to stdout. If the stream is ending, also prints a newline.TrF   N)Úflushr   )Úprint©r   rB   rG   s   &&&r   rA   ÚTextStreamer.on_finalized_text€   s   € äˆd˜$¯j¡B¸d×Cr   c                óê   € VR8¼  d   VR8:  gc   VR8¼  d   VR8:  gU   VR8¼  d   VR8:  gG   VR8¼  d   VR8:  g9   VR	8¼  d   VR
8:  g+   VR8¼  d   VR8:  g   VR8¼  d   VR8:  g   VR8¼  d
   VR8:  d   R# R# )z6Checks whether CP is the codepoint of a CJK character.i N  iÿŸ  i 4  i¿M  i   iß¦ i § i?· i@· i¸ i ¸ i¯Î i ù  iÿú  i ø iú TFr   )r   Úcps   &&r   r>   ÚTextStreamer._is_chinese_char„   sr   € ð �6Œ\˜b FœlØ�f”  v¤Ø�g” "¨¤-Ø�g” "¨¤-Ø�g” "¨¤-Ø�g” "¨¤-Ø�f”  v¤Ø�g” "¨¤-áár   )r(   r/   r.   r&   r-   r%   N©F)r   r   r   r   r   r0   r   r   rA   r>   r    r   r   r   r"   r"   *   s#   † ñ÷6+ò /òD@÷Dör   r"   c                  óR   a € ] tR t^�tRtR	R V 3R llltR
R R lltR tR tRt	V ;t
# )ÚTextIteratorStreameraã  
Streamer that stores print-ready text in a queue, to be used by a downstream application as an iterator. This is
useful for applications that benefit from accessing the generated text in a non-blocking way (e.g. in an interactive
Gradio demo).

Parameters:
    tokenizer (`AutoTokenizer`):
        The tokenizer used to decode the tokens.
    skip_prompt (`bool`, *optional*, defaults to `False`):
        Whether to skip the prompt to `.generate()` or not. Useful e.g. for chatbots.
    timeout (`float`, *optional*):
        The timeout for the text queue. If `None`, the queue will block indefinitely. Useful to handle exceptions
        in `.generate()`, when it is called in a separate thread.
    decode_kwargs (`dict`, *optional*):
        Additional keyword arguments to pass to the tokenizer's `decode` method.

Examples:

    ```python
    >>> from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
    >>> from threading import Thread

    >>> tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
    >>> model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")
    >>> inputs = tok(["An increasing sequence: one,"], return_tensors="pt")
    >>> streamer = TextIteratorStreamer(tok)

    >>> # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way.
    >>> generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=20)
    >>> thread = Thread(target=model.generate, kwargs=generation_kwargs)
    >>> thread.start()
    >>> generated_text = ""
    >>> for new_text in streamer:
    ...     generated_text += new_text
    >>> generated_text
    'An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,'
    ```
c               ó(   € V ^8„  d   QhRRRRRRRR/# ©	r$   r%   r   r&   r'   Útimeoutúfloat | Noner(   r   r   )r)   s   "r   r*   Ú!TextIteratorStreamer.__annotate__Å   s2   € ÷ 
ñ 
à*ð
ð ð
ð ð	
ð
 ñ
r   c                	ób   <€ \         SV `  ! W3/ VB  \        4       V n        R V n        W0n        R # ©N)Úsuperr0   r   Ú
text_queueÚstop_signalrX   )r   r%   r&   rX   r(   Ú	__class__s   &&&&,€r   r0   ÚTextIteratorStreamer.__init__Å   s-   ø€ ô 	‰Ò˜ÑA°=ÒAÜ›'ˆŒØˆÔØŽr   c               ó    € V ^8„  d   QhRRRR/# rJ   r   )r)   s   "r   r*   rZ   Ñ   s   € ÷ Hñ H cð H°tñ Hr   c                óÈ   € V P                   P                  WP                  R7       V'       d4   V P                   P                  V P                  V P                  R7       R# R# )ú\Put the new text in the queue. If the stream is ending, also put a stop signal in the queue.©rX   N)r^   r   rX   r_   rN   s   &&&r   rA   Ú&TextIteratorStreamer.on_finalized_textÑ   sD   € à�‰×Ñ˜D¯,©,ÐÔ7ßØ�O‰O×Ñ × 0Ñ 0¸$¿,¹,ÐÖGñ r   c                	ó   € V # r\   r   r   s   &r   Ú__iter__ÚTextIteratorStreamer.__iter__×   ó   € Øˆr   c                	ó†   € V P                   P                  V P                  R 7      pWP                  8X  d   \	        4       hV# )re   )r^   ÚgetrX   r_   ÚStopIterationr   s   & r   Ú__next__ÚTextIteratorStreamer.__next__Ú   s6   € Ø—‘×#Ñ#¨D¯L©LÐ#Ó9ˆØ×$Ñ$Ô$Ü“/Ð!àˆLr   )r_   r^   rX   ©FNrS   )r   r   r   r   r   r0   rA   rh   rn   r    Ú__classcell__©r`   s   @r   rU   rU   �   s(   ø† ñ%÷N
ò 
÷Hò÷ð r   rU   c                  óR   a € ] tR t^âtRtR	R V 3R llltR
R R lltR tR tRt	V ;t
# )ÚAsyncTextIteratorStreamera
  
Streamer that stores print-ready text in a queue, to be used by a downstream application as an async iterator.
This is useful for applications that benefit from accessing the generated text asynchronously (e.g. in an
interactive Gradio demo).

Parameters:
    tokenizer (`AutoTokenizer`):
        The tokenizer used to decode the tokens.
    skip_prompt (`bool`, *optional*, defaults to `False`):
        Whether to skip the prompt to `.generate()` or not. Useful e.g. for chatbots.
    timeout (`float`, *optional*):
        The timeout for the text queue. If `None`, the queue will block indefinitely. Useful to handle exceptions
        in `.generate()`, when it is called in a separate thread.
    decode_kwargs (`dict`, *optional*):
        Additional keyword arguments to pass to the tokenizer's `decode` method.

Raises:
    TimeoutError: If token generation time exceeds timeout value.

Examples:

    ```python
    >>> from transformers import AutoModelForCausalLM, AutoTokenizer, AsyncTextIteratorStreamer
    >>> from threading import Thread
    >>> import asyncio

    >>> tok = AutoTokenizer.from_pretrained("openai-community/gpt2")
    >>> model = AutoModelForCausalLM.from_pretrained("openai-community/gpt2")
    >>> inputs = tok(["An increasing sequence: one,"], return_tensors="pt")

    >>> # Run the generation in a separate thread, so that we can fetch the generated text in a non-blocking way.
    >>> async def main():
    ...     # Important: AsyncTextIteratorStreamer must be initialized inside a coroutine!
    ...     streamer = AsyncTextIteratorStreamer(tok)
    ...     generation_kwargs = dict(inputs, streamer=streamer, max_new_tokens=20)
    ...     thread = Thread(target=model.generate, kwargs=generation_kwargs)
    ...     thread.start()
    ...     generated_text = ""
    ...     async for new_text in streamer:
    ...         generated_text += new_text
    >>>     print(generated_text)
    >>> asyncio.run(main())
    An increasing sequence: one, two, three, four, five, six, seven, eight, nine, ten, eleven,
    ```
c               ó(   € V ^8„  d   QhRRRRRRRR/# rW   r   )r)   s   "r   r*   Ú&AsyncTextIteratorStreamer.__annotate__  s8   € ÷ Uñ Uà*ðUð ðUð ð	Uð
 ñUr   c                	óf  <€ \         SV `  ! W3/ VB  \        P                  ! 4       V n        R V n        W0n        \        P                  ! 4       V n        \        \        RR 4      p\        P                  R8¬  ;'       d    \        V4      V n        V P                  '       d	   WPn        R # R V n        R # )NrX   )é   é   )r]   r0   Úasyncior   r^   r_   rX   Úget_running_loopÚloopÚgetattrÚsysÚversion_infoÚcallableÚhas_asyncio_timeoutÚasyncio_timeout)r   r%   r&   rX   r(   Útimeout_contextr`   s   &&&&, €r   r0   Ú"AsyncTextIteratorStreamer.__init__  sˆ   ø€ ô 	‰Ò˜ÑA°=ÒAÜ!Ÿ-š-›/ˆŒØˆÔØŒÜ×,Ò,Ó.ˆŒ	Ü!¤'¨9°dÓ;ˆÜ#&×#3Ñ#3°wÑ#>×#\Ð#\Ä8ÈOÓC\ˆÔ Ø26×2J×2JÐ2J˜ÖÐPTˆÖr   c               ó    € V ^8„  d   QhRRRR/# rJ   r   )r)   s   "r   r*   rv   !  s   € ÷ Yñ Y cð Y°tñ Yr   c                óî   € V P                   P                  V P                  P                  V4       V'       d=   V P                   P                  V P                  P                  V P                  4       R# R# )rd   N)r|   Úcall_soon_threadsafer^   Ú
put_nowaitr_   rN   s   &&&r   rA   Ú+AsyncTextIteratorStreamer.on_finalized_text!  sL   € à�	‰	×&Ñ& t§¡×'AÑ'AÀ4ÔHßØ�I‰I×*Ñ*¨4¯?©?×+EÑ+EÀt×GWÑGWÖXñ r   c                	ó   € V # r\   r   r   s   &r   Ú	__aiter__Ú#AsyncTextIteratorStreamer.__aiter__'  rj   r   c              ƒ  	óV  "  €  V P                   '       dn   V P                  e`   V P                  V P                  4      ;_uu_4       GR j  x€L
  V P                  P	                  4       G R j  x€L
 pR R R 4      GR j  x€L
  MB\
        P                  ! V P                  P	                  4       V P                  R7      G R j  x€L
 pXV P                  8X  d   \        4       hV#  L– Lv Lh  + GR j  x€L 
 '       g   i     L<; i LC  \
        P                   d    \        4       hi ; i5i)Nre   )
r�   r‚   rX   r^   rl   rz   Úwait_forr_   ÚStopAsyncIterationÚTimeoutErrorr   s   & r   Ú	__anext__Ú#AsyncTextIteratorStreamer.__anext__*  sØ   é € ð	Ø×'×'Ð'¨D×,@Ñ,@Ò,LØ×/Ñ/°·±×=×=Õ=Ø"&§/¡/×"5Ñ"5Ó"7×7�E÷ >×=Ð=ô &×.Ò.¨t¯©×/BÑ/BÓ/DÈdÏlÉlÔ[×[�ð ˜×(Ñ(Ô(Ü(Ó*Ð*à�ñ >Ù7÷ >×=×=Ò=úñ \øÜ×#Ñ#ô 	!Ü“.Ð ð	!üsŠ   ‚D)„AD ÁC"ÁD ÁC(Á-C$Á.C(Á2D Á=C&Á>AD Ã DÃD ÃD)Ã"D Ã$C(Ã&D Ã(D	Ã.C1Ã/
D	Ã:D	Ã<	D Ä D&Ä&D))r‚   r�   r|   r_   r^   rX   rp   rS   )r   r   r   r   r   r0   rA   r‹   r‘   r    rq   rr   s   @r   rt   rt   â   s*   ø† ñ,÷\Uò U÷ Yò÷ð r   rt   c                  óZ   a € ] tR tRtRtR
R V 3R llltR tR tV 3R ltV 3R lt	R	t
V ;t# )ÚTextDiffusionStreameri:  a  
Streamer that prints text diffusion outputs. Intermediate diffusion steps (drafts) are temporary
and overwritten by subsequent drafts, and removed when confirmed text is printed.

<Tip warning={true}>

If you're running on an environment like tmux, the draft text may fail to overwrite itself.

</Tip>


Parameters:
    tokenizer (`AutoTokenizer`):
        The tokenized used to decode the tokens.
    skip_prompt (`bool`, *optional*, defaults to `False`):
        Whether to skip the prompt to `.generate()` or not. Useful e.g. for chatbots.
    sleep_time (`float`, *optional*):
        Time to sleep between diffusion drafts, which may be helpful to visualize intermediate outputs.
    decode_kwargs (`dict`, *optional*):
        Additional keyword arguments to pass to the tokenizer's `decode` method.

Examples:

    ```python
    >>> from transformers import DiffusionGemmaForBlockDiffusion, AutoProcessor, TextDiffusionStreamer

    >>> model = DiffusionGemmaForBlockDiffusion.from_pretrained(
    ...     "google/diffusiongemma-26B-A4B-it", device_map="auto",
    ... )
    >>> processor = AutoProcessor.from_pretrained("google/diffusiongemma-26B-A4B-it")

    >>> chat = [{"role": "user", "content": "Why is the sky blue?"},]
    >>> input_ids = processor.apply_chat_template(
    ...     chat, tokenize=True, return_tensors="pt", add_generation_prompt=True
    ... )
    >>> streamer = TextDiffusionStreamer(tokenizer=processor.tokenizer)
    >>> model.generate(input_ids.to(model.device), max_new_tokens=512, streamer=streamer)
    ```
c               ó(   € V ^8„  d   QhRRRRRRRR/# )	r$   r%   r   r&   r'   Ú
sleep_timerY   r(   r   r   )r)   s   "r   r*   Ú"TextDiffusionStreamer.__annotate__c  s2   € ÷ %ñ %à*ð%ð ð%ð !ð	%ð
 ñ%r   c                	óR   <€ \         SV `  ! W3/ VB  R V n        R V n        W0n        R# rp   )r]   r0   Ú
_has_draftÚ_takes_logitsr–   )r   r%   r&   r–   r(   r`   s   &&&&,€r   r0   ÚTextDiffusionStreamer.__init__c  s-   ø€ ô 	‰Ò˜ÑA°=ÒAØˆŒð #ˆÔØ$Žr   c                	óX   € V P                   '       d   \        R RRR7       RV n         R# R# )z8[JrF   T©r   rL   FN)r™   rM   r   s   &r   Ú_clear_draftÚ"TextDiffusionStreamer._clear_draftr  s#   € Ø�?�?ˆ?ä�- R¨tÕ4Ø#ˆDŽOñ r   c                óâ  € V P                  4        \        VP                  4      ^8”  d$   VP                  ^ ,          ^8”  d   \        R4      h\        VP                  4      ^8”  d
   V^ ,          pV P                  P
                  ! V3/ V P                  B p\        RRRR7       \        RV R2RRR7       RV n        V P                  e#   \        P                  ! V P                  4       R# R# )	zq
Receives the full sequence of draft tokens, decodes them, and prints them in yellow.
Overwrites previous draft.
z0TextDiffusionStreamer only supports batch size 1z7rF   Tr�   z[33mz[0mN)rž   r6   r7   r8   r%   r<   r(   rM   r™   r–   ÚtimeÚsleep)r   r   ÚkwargsrB   s   &&, r   Ú	put_draftÚTextDiffusionStreamer.put_draftx  s¾   € ð
 	×ÑÔäˆu�{‰{Ó˜aÔ E§K¡K°¥N°QÔ$6ÜÐOÓPÐPÜ�—‘Ó Ô!Ø˜!•HˆEà�~‰~×$Ò$ UÑA¨d×.@Ñ.@ÑAˆô 	ˆg˜2 TÕ*ä�˜˜˜gÐ&¨B°dÕ;ØˆŒØ�?‰?Ò&Ü�JŠJ�t—‘Ö'ñ 'r   c                óF   <€ V P                  4        \        SV `	  V4       R# )zEReceives confirmed tokens, clears draft, and prints them permanently.N)rž   r]   r   )r   r   r`   s   &&€r   r   ÚTextDiffusionStreamer.putŽ  s   ø€ à×ÑÔÜ‰‰�EÖr   c                óD   <€ V P                  4        \        SV `	  4        R# )z1Flushes any remaining cache and prints a newline.N)rž   r]   r   )r   r`   s   &€r   r   ÚTextDiffusionStreamer.end“  s   ø€ à×ÑÔÜ‰‰Žr   )r™   rš   r–   rp   )r   r   r   r   r   r0   rž   r¤   r   r   r    rq   rr   s   @r   r”   r”   :  s,   ø† ñ&÷P%ò %ò$ò(õ,÷
ó r   r”   )Ú
__future__r   rz   r~   r¡   Úqueuer   Útypingr   r   r   Útokenization_utils_baser   r
   r"   rU   rt   r”   r   r   r   Ú<module>r®      si   ðõ #ã Û 
Û Ý ß +Ñ +÷ ÝA÷$ñ $ôp�<ô pôfB˜<ô BôJU ô Uôp\˜Lö \r   