Ë
    ÛÓ^j°õ  ã                   óð  — d dl Z d dlZd dlZd dlZd dlmZ d dlmZmZ d dl	m
Z
m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 d d	lmZ d
dlmZ d
dlmZmZ d
dlmZ ddlmZ ddlmZ ddl m!Z! ddl"m#Z# ddl$m%Z%m&Z& ddl'm(Z(m)Z) ddl*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4m5Z5m6Z6 ddl7m8Z8m9Z9 	  G d„ dejt                  «      Z; G d„ d«      Z< G d„ d «      Z= G d!„ d"«      Z> G d#„ d$«      Z? G d%„ d&«      Z@y)'é    N)Úabstractmethod)ÚCallableÚ	Generator)ÚcontextmanagerÚnullcontext)Úperf_counter)ÚAny)Únn)Útqdm)Úlogging_redirect_tqdmé   )ÚPretrainedConfig)ÚContinuousBatchingConfigÚGenerationConfig)Úloggingé   )ÚLogitsProcessorListé   )ÚPagedAttentionCache)Ú%ContinuousBatchingLogitsProcessorList)ÚDistributedHelper)Ú"resolve_continuous_batching_configÚ%update_cb_config_after_cache_creation)ÚContinuousBatchingAsyncIOsÚContinuousBatchingIOs)ÚModelRunner)ÚOffloadingManager)ÚGenerationOutputÚRequestStateÚRequestStatusÚlogger)ÚSCHEDULER_MAPPINGÚFIFOSchedulerÚ	Scheduler)ÚWorkloadHintsÚdrain_queuec                   óˆ   — e Zd ZU eed<   ej                  ed<   ej                  ed<   ede	ddfd„«       Z
ededefd	„«       Zy)
ÚProtoPretrainedModelÚconfigÚdtypeÚdeviceÚattn_implementationÚreturnNc                  ó   — y ©N© )Úselfr,   s     ú…/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/generation/continuous_batching/continuous_api.pyÚset_attn_implementationz,ProtoPretrainedModel.set_attn_implementationI   ó   € àó    Úgeneration_configc                  ó   — y r/   r0   )r1   r6   s     r2   Ú_get_logits_processorz*ProtoPretrainedModel._get_logits_processorM   r4   r5   )Ú__name__Ú
__module__Ú__qualname__r   Ú__annotations__Útorchr*   r+   r   Ústrr3   r   r   r8   r0   r5   r2   r(   r(   D   s`   … ØÓØ�;‰;ÓØ�L‰LÓàð¸3ð À4ò ó ðð ðÐ7Gð ÐL_ò ó ñr5   r(   c                   ó>   — e Zd ZdZd	d„Zdeddfd„Zdee   ddfd„Zy)
ÚOutputRoutera  Dedicated object for routing generation outputs to the right destination.

    When an async handler is registered for a request, the output is forwarded
    to that handler via ``call_soon_threadsafe``. Otherwise the output is placed
    on the shared ``output_queue``.
    r-   Nc                 óv   — t        j                  «       | _        i | _        t	        j
                  «       | _        y r/   )ÚqueueÚQueueÚoutput_queueÚresult_handlersÚ	threadingÚLockÚ_lock©r1   s    r2   Ú__init__zOutputRouter.__init__Z   s&   € Ü!ŸK™K›MˆÔØVXˆÔÜ—^‘^Ó%ˆ�
r5   Úoutputc                 óú   — | j                   5  | j                  j                  |j                  «      }ddd«       �|\  }}|j	                  ||«       y| j
                  j                  |«       y# 1 sw Y   Œ?xY w)zDRoute a single output to its registered handler or the output_queue.N)rH   rE   ÚgetÚ
request_idÚcall_soon_threadsaferD   Úput)r1   rK   ÚentryÚcallbackÚloops        r2   ÚdeliverzOutputRouter.deliver_   sq   € à�Z‰Zñ 	@Ø×(Ñ(×,Ñ,¨V×->Ñ->Ó?ˆE÷	@àÐØ"‰NˆH�dØ×%Ñ% h°Õ7à×Ñ×!Ñ! &Õ)÷	@ð 	@ús   �&A1Á1A:Úoutputsc                 óL  — g }d}| j                   5  |D ]]  }| j                  j                  |j                  «      }|�|\  }}|j	                  ||f«       ŒC| j
                  j                  |«       Œ_ 	 ddd«       |r|�|fd„}|j                  |«       yyy# 1 sw Y   Œ&xY w)zÅRoute a batch of outputs, using a single ``call_soon_threadsafe`` to minimize cross-thread overhead.

        Outputs without a registered handler fall back to the shared ``output_queue``.
        Nc                 ó(   — | D ]  \  }} ||«       Œ y r/   r0   )ÚbatchÚcbÚouts      r2   Ú
_run_batchz.OutputRouter.deliver_batch.<locals>._run_batchz   s   € Ø$ò ‘G�B˜Ù�s•Gñr5   )rH   rE   rM   rN   ÚappendrD   rP   rO   )r1   rU   Ú	callbacksrS   rK   rQ   rR   r[   s           r2   Údeliver_batchzOutputRouter.deliver_batchi   sµ   € ð
 >@ˆ	ØˆØ�Z‰Zñ 	2Ø!ò 2�Ø×,Ñ,×0Ñ0°×1BÑ1BÓC�ØÐ$Ø%*‘N�H˜dØ×$Ñ$ h°Ð%7Õ8à×%Ñ%×)Ñ)¨&Õ1ñ2÷	2ñ ˜Ð)à!*ó ð ×%Ñ% jÕ1ð *ˆ9÷	2ð 	2ús   ‘A#BÂB#©r-   N)	r9   r:   r;   Ú__doc__rJ   r   rT   Úlistr^   r0   r5   r2   r@   r@   R   s9   „ ñó&ð
*Ð.ð *°4ó *ð2 TÐ*:Ñ%;ð 2Àô 2r5   r@   c                   óˆ   — e Zd ZdZdZdZdZdZdd„Zdd	„Z	d
e
de
ddfd„Zdd„Zde
ddfd„Zede
fd„«       Zede
fd„«       Zy)ÚBackgroundThreadStatusz¦Tracks the status of the background thread locally and in its TP group. The status is an int that can only
    increase, representing how soon the thread should stop.r   r   r   r   r-   Nc                 óz   — t        j                  «       | _        | j                  | _        | j                  | _        y r/   )rF   rG   Ú_local_status_lockÚ	DONT_STOPÚ_local_statusÚ
_tp_statusrI   s    r2   rJ   zBackgroundThreadStatus.__init__Š   s(   € Ü"+§.¡.Ó"2ˆÔØ!Ÿ^™^ˆÔØŸ.™.ˆ�r5   c                 óŠ   — | j                   | _        | j                  5  | j                   | _        ddd«       y# 1 sw Y   yxY w)z‹Clear the local and TP statuses. This method should ONLY be called by the main thread itself BEFORE starting
        the background thread.N)rf   rh   re   rg   rI   s    r2   ÚclearzBackgroundThreadStatus.clear�   s9   € ð Ÿ.™.ˆŒØ×$Ñ$ñ 	0Ø!%§¡ˆDÔ÷	0÷ 	0ñ 	0ús	   ž9¹AÚstatusÚglobal_rankc                 ó8  — || j                   | j                  fvrt        d|› d|› �«      ‚| j                  5  t	        || j
                  | j                  «      | _        ddd«       t        j                  d|› d|›d| j
                  ›�«       y# 1 sw Y   Œ2xY w)zRequest the background thread to stop. This does not take effect immediately, only after the TP group has
        communicated.zInvalid stop status z from rank NzRank z3 requested background thread to stop with status = z. Now self._local_status = )	ÚFLUSH_AND_STOPÚ	HARD_STOPÚ
ValueErrorre   Úmaxrg   rh   r!   Úinfo)r1   rk   rl   s      r2   Úrequest_stopz#BackgroundThreadStatus.request_stop–   s�   € ð ˜$×-Ñ-¨t¯~©~Ð>Ñ>ÜÐ3°F°8¸;À{ÀmÐTÓUÐUØ×$Ñ$ñ 	RÜ!$ V¨T×-?Ñ-?ÀÇÁÓ!QˆDÔ÷	Rä�‰Ø�K�=Ð TÈ6È+ÐUqÐ\`×\nÑ\nÐ[rÐsõ	
÷	Rð 	Rús   ¸'BÂBc                 óh   — | j                   5  | j                  | _        ddd«       y# 1 sw Y   yxY w)zzMark the background thread as stopped. This should be called by the main thread when the generation loop
        finishes.N)re   ÚSTOPPEDrg   rI   s    r2   Úmark_as_stoppedz&BackgroundThreadStatus.mark_as_stopped¡   s.   € ð ×$Ñ$ñ 	.Ø!%§¡ˆDÔ÷	.÷ 	.ñ 	.ús   �(¨1Ú	tp_statusc                 óÞ   — || j                   k  rt        d|›d| j                   ›�«      ‚|| _         | j                  5  t        | j                  |«      | _        ddd«       y# 1 sw Y   yxY w)z8Update the local and TP statuses with the new TP status.z1TP communicated a lower stop status: tp_status = z, self._tp_status = N)rh   rp   re   rq   rg   )r1   rw   s     r2   Úupdate_with_tp_statusz,BackgroundThreadStatus.update_with_tp_status§   sn   € à�t—‘Ò&ÜÐQÀYÀNÐRgÐUY×UdÑUdÐThÐiÓjÐjØ#ˆŒà×$Ñ$ñ 	DÜ!$ T×%7Ñ%7¸Ó!CˆDÔ÷	D÷ 	Dñ 	Dús   ¾A#Á#A,c                 ó   — | j                   S )zVThe locally requested status, possibly ahead of the value agreed upon by the TP group.)rg   rI   s    r2   Úlocal_statusz#BackgroundThreadStatus.local_status°   s   € ð ×!Ñ!Ð!r5   c                 ó   — | j                   S )zKThe status last agreed upon by the TP group through a MAX-reduce operation.)rh   rI   s    r2   rw   z BackgroundThreadStatus.tp_statusµ   s   € ð �‰Ðr5   r_   )r9   r:   r;   r`   rf   rn   ro   ru   rJ   rj   Úintrs   rv   ry   Úpropertyr{   rw   r0   r5   r2   rc   rc   �   s’   „ ñ?ð €IØ€NØ€IØ€Gó)ó
0ð	
 3ð 	
°Sð 	
¸Tó 	
ó.ðD¨sð D°tó Dð ð"˜cò "ó ð"ð ð˜3ò ó ñr5   rc   c                   óÎ  — e Zd ZU eez  ed<   eed<   dedede	de
dedej                  d	z  d
ej                  d	z  dededej"                  dej$                  dededd	fd„Zdefd„Zd!d„Zd!d„Zdefd„Zdededd	fd„Zdefd„Zd!d„Zdefd„Z d„ Z!dedd	fd„Z" ejF                  «       de$jJ                  dd	fd„«       Z& ejF                  «       de$jJ                  dd	fd „«       Z'y	)"ÚContinuousBatchProcessorÚinputs_and_outputsÚ	schedulerÚcacher)   r6   Úcontinuous_batching_configÚlogit_processorÚinput_queueNÚcancel_queueÚoutput_routerÚbackground_thread_statusÚmodel_deviceÚmodel_dtypeÚdistributed_helperr-   c                 óŠ  — || _         || _        || _        || _        || _        || _        || _        |	| _        |
| _        || _	        || _
        || _        t        |dd«      | _        |j                  | _        | j                  j                  |j                   |
«       t        |dd«      €dn|j"                  | _        |j$                  | _        ||||
|| j                  dœ}| j                  j&                  | _        | j&                  rt)        d	i |¤Ž| _        nt-        d	i |¤Ž| _        t/        |||j0                  |j2                  | j*                  j4                  | j                  ¬«      | _        t9        | j                  | j                  | j                   | j*                  | j                  | j                  ¬«      | _        y)
a)  Initialize the continuous batch processor.

        Args:
            cache: A [`PagedAttentionCache`] object
            config: The model configuration
            generation_config: The generation configuration
            continuous_batching_config: The continuous batching configuration
            logit_processor: The [`ContinuousBatchingLogitsProcessorList`] object used to process the logits.
            input_queue: Queue for incoming requests. Is None if this process is not a TP driver.
            cancel_queue: Queue for cancellation request_ids. Is None if this process is not a TP driver.
            output_router: An [`OutputRouter`] object that routes outputs to handlers or the output queue.
            background_thread_status: A [`BackgroundThreadStatus`] object to track the background thread status.
            model_device: Device for model inputs/outputs
            model_dtype: Data type for model inputs/outputs
            scheduler: The [`Scheduler`] to use
            distributed_helper: The [`DistributedHelper`] to use
        Ú	do_sampleTÚsliding_windowNr   )rƒ   r)   r„   r+   r‹   r…   )rƒ   r‚   Úcpu_offload_space_gibÚsafety_thresholdÚcompute_streamrŒ   )r…   Ú	cb_configrƒ   r�   rŽ   Úreturn_logprobsr0   )rƒ   r)   r“   r…   r†   r‡   rˆ   r‰   rŠ   r‹   r‚   rŒ   ÚgetattrrŽ   r”   Úset_tp_seedÚseedr�   Úmax_batch_tokensÚuse_async_batchingr   r�   r   r   Úcpu_offload_spaceÚ"cpu_offload_space_safety_thresholdr’   Úoffloading_managerr   Úmodel_runner)r1   rƒ   r)   r6   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   r‚   rŒ   Ú	io_kwargss                  r2   rJ   z!ContinuousBatchProcessor.__init__À   s­  € ðB ˆŒ
ØˆŒØ3ˆŒØ.ˆÔØ&ˆÔØ(ˆÔØ*ˆÔØ(@ˆÔ%Ø(ˆÔØ&ˆÔØ"ˆŒØ"4ˆÔô !Ð!2°KÀÓFˆŒØ9×IÑIˆÔð 	×Ñ×+Ñ+Ð,F×,KÑ,KÈ\ÔZô $+¨6Ð3CÀTÓ#JÐ#R™aÐX^×XmÑXmˆÔà %× 6Ñ 6ˆÔð ØØ*DØ"Ø&Ø#×3Ñ3ñ
ˆ	ð #'§.¡.×"CÑ"CˆÔà×"Ò"Ü&@Ñ&MÀ9Ñ&MˆDÕ#ä&;Ñ&H¸iÑ&HˆDÔ#ô #4ØØØ"<×"NÑ"NØ7×ZÑZØ×2Ñ2×AÑAØ#×6Ñ6ô#
ˆÔô (Ø ×0Ñ0Ø—n‘nØ—*‘*Ø#×6Ñ6Ø—n‘nØ ×0Ñ0ô
ˆÕr5   c                 óÐ   — d| j                   › d| j                  j                  › d| j                  j                  › d�| j                  j                  «       j                  «       z   S )Nz%ContinuousBatchProcessor(input_queue=z, active_requests=z, waiting_requests=ú))r†   r‚   Úactive_requestsÚwaiting_requestsr�   Úget_model_kwargsÚ__repr__rI   s    r2   r¤   z!ContinuousBatchProcessor.__repr__  sj   € à3°D×4DÑ4DÐ3Eð FØ#Ÿ~™~×=Ñ=Ð>Ð>QÐRV×R`ÑR`×RqÑRqÐQrÐrsðuà×%Ñ%×6Ñ6Ó8×AÑAÓCñDð	
r5   c                 ó´   — d | _         t        j                  «        t        j                  j                  «       rt        j                  j                  «        y y r/   )r�   ÚgcÚcollectr=   ÚcudaÚis_availableÚempty_cacherI   s    r2   Ú__del__z ContinuousBatchProcessor.__del__%  s8   € Ø"&ˆÔÜ
�
‰
ŒÜ�:‰:×"Ñ"Ô$Ü�J‰J×"Ñ"Õ$ð %r5   c                 óÔ   — | j                   j                  «        | j                  j                  «        | j                  j                  «        | j                  j                  «        y)z4Reset the batch processor for a new generation loop.N)rœ   Úresetr‚   r�   rƒ   Úfree_all_requestsrI   s    r2   r­   zContinuousBatchProcessor.reset+  sF   € à×Ñ×%Ñ%Ô'Ø�‰×ÑÔØ×Ñ×%Ñ%Ô'Ø�
‰
×$Ñ$Õ&r5   c                 ó\  — | j                   �7| j                  �+t        | j                   «      t        | j                  «      f}ng g f}t        |d   «      t        |d   «      z   }| j                  j
                  }| j                  j                  ||«      \  }}| j                  j                  |«       | j                  j                  t        j                  k(  ry|dk(  ry| j                  j                  |«      \  }}|D ]C  }	 | j                  j                  |j                  «       | j                   j#                  |«       ŒE |D ]  }	| j                   j-                  |	«       Œ y# t$        $ r6}t'        j(                  d|› �d¬«       | j+                  ||«       Y d}~Œ£d}~ww xY w)zïCommunicates with the TP group to get A. the new requests and cancellations from the TP driver, and B. an
        eventual stop signal from any process in the TP group. Returns True if the TP group is hard-stopping, False
        otherwiseNr   r   TFzError processing new request: ©Úexc_info)r†   r‡   r&   Úlenr‰   r{   rŒ   Útp_all_reduce_statery   rw   rc   ro   Útp_broadcast_object_from_rank_0r…   Úcheck_kwargsÚlogit_processor_kwargsr‚   Úadd_waiting_requestÚ	Exceptionr!   ÚerrorÚ_handle_request_errorÚset_request_cancellation)
r1   ÚpayloadÚpayload_sizeÚlocal_requested_statusrw   Ú
new_statesÚcancellationsÚstateÚerN   s
             r2   Ú_update_tp_group_statez/ContinuousBatchProcessor._update_tp_group_state2  s�  € ð
 ×ÑÐ'¨D×,=Ñ,=Ð,IÜ" 4×#3Ñ#3Ó4´kÀ$×BSÑBSÓ6TÐU‰Gà˜2�hˆGä˜7 1™:“¬¨W°Q©Z«Ñ8ˆð "&×!>Ñ!>×!KÑ!KÐØ"&×"9Ñ"9×"MÑ"MÈlÐ\rÓ"sÑˆ�ià×%Ñ%×;Ñ;¸IÔFð ×(Ñ(×2Ñ2Ô6L×6VÑ6VÒVØà˜1ÒØà$(×$;Ñ$;×$[Ñ$[Ð\cÓ$dÑ!ˆ
�Mð  ò 	5ˆEð5Ø×$Ñ$×1Ñ1°%×2NÑ2NÔOØ—‘×2Ñ2°5Õ9ð	5ð (ò 	@ˆJØ�N‰N×3Ñ3°JÕ?ð	@àøô ò 5Ü—‘Ð=¸a¸SÐAÈDÕQØ×*Ñ*¨1¨e×4Ñ4ûð5ús   ÄA E,Å,	F+Å5,F&Æ&F+r¹   rÁ   c                 ó8  — t         j                  |_        t        |«      |_        t        |j                  t        «      r+| j                  j                  |j                  «      |_	        ng |_	        | j                  j                  |j                  «       «       y)z(Handle general request processing error.N)r    ÚFAILEDrk   r>   r¹   Ú
isinstancerN   r‚   Ú!get_active_request_static_outputsÚgenerated_tokensrˆ   rT   Úto_generation_output)r1   r¹   rÁ   s      r2   rº   z.ContinuousBatchProcessor._handle_request_errorY  so   € ä$×+Ñ+ˆŒÜ˜%“jˆŒô �e×&Ñ&¬Ô,Ø%)§^¡^×%UÑ%UÐV[×VfÑVfÓ%gˆEÕ"à%'ˆEÔ"à×Ñ×"Ñ" 5×#=Ñ#=Ó#?Õ@r5   c                 óÒ  — | j                  «       }|ry| j                  j                  «       }|D ]  }| j                  j	                  |«       Œ | j                  j                  «       sy| j                  j                  | j                  | j                  j                  «      \  }}}}|€j| j                  j                  «       dk(  rt        d«      ‚| j                  j                  | j                  | j                  j                  «      \  }}}}|€Œj|sy| j                  j                  r| j                  j                  «        | j                  j                  |«       t        j                  t         j"                  «      r‚t        j$                  dt'        |«      › dt'        | j                  j(                  «      › dt'        | j                  j*                  «      › d|› d|› d	| j                  j-                  «       › �«       | j.                  j1                  |||«      \  }}| j2                  j5                  || j6                  |||| j.                  j8                  ¬
«       y)z…Prepare tensors and metadata for the next model forward pass. Returns True if there are requests to process,
        False otherwise.Fr   z>No requests can be scheduled and no requests can be offloaded.zScheduled: z, Waiting: z
, Active: z	. cum Q: z
. cum KV: z, free blocks: )Úrequests_in_batchÚlogits_processorsÚuse_decode_fast_pathÚnum_q_tokensÚmax_kv_readÚuse_paddingT)rÃ   r‚   Úclear_cancelled_requestsrœ   Úfree_request_cpu_cacheÚhas_pending_requestsÚschedule_batchr˜   rƒ   Ú	num_pagesÚoffload_requestsÚRuntimeErrorÚstarved_requestsÚrestore_scheduled_requestsr!   ÚisEnabledForr   ÚDEBUGÚdebugr²   r¢   r¡   Úget_num_free_blocksr�   Úmaybe_pad_inputsr�   Úprepare_batch_tensorsr…   Ú
pad_inputs)r1   Úhard_stoppingÚcancelled_statesrÁ   rË   rÍ   rÎ   rÏ   s           r2   Úprepare_next_batchz+ContinuousBatchProcessor.prepare_next_batchf  s3  € ð
 ×3Ñ3Ó5ˆÙØàŸ>™>×BÑBÓDÐà%ò 	BˆEØ×#Ñ#×:Ñ:¸5ÕAð	Bà�~‰~×2Ñ2Ô4Øð NRÏ^É^×MjÑMjØ×!Ñ! 4§:¡:×#7Ñ#7óN
ÑJÐÐ/°¸{ð  Ð'à×&Ñ&×7Ñ7Ó9¸QÒ>Ü"Ð#cÓdÐdàQU×Q_ÑQ_×QnÑQnØ×%Ñ% t§z¡z×';Ñ';óRÑNÐÐ3°\À;ð  Ñ'ñ !Øà�>‰>×*Ò*Ø×#Ñ#×4Ñ4Ô6ð 	×Ñ×:Ñ:Ð;LÔMô ×ÑœwŸ}™}Ô-Ü�L‰LØœcÐ"3Ó4Ð5°[ÄÀTÇ^Á^×EdÑEdÓAeÐ@fð gÜ˜tŸ~™~×=Ñ=Ó>Ð?¸yÈÈð WØ&˜- °t·z±z×7UÑ7UÓ7WÐ6XðZôð %)×$5Ñ$5×$FÑ$FÀ|ÐU`ÐbvÓ$wÑ!ˆ�kà×Ñ×5Ñ5Ø/Ø"×2Ñ2Ø!5Ø%Ø#Ø×)Ñ)×4Ñ4ð 	6ô 	
ð r5   c                 óX  — | j                   j                  «       \  }}}d}g }|D �]Ñ  }|j                  }|j                  t        j
                  t        j                  fv rN| j                  r|j                  r|dz  }ŒZt        d|j                  j                  › d|j                  › d�«      ‚|j                  r÷|j                  «       dk(  rt        j                  |_        ||   }|�||   nd}	|dz  }|j                  ||	«      }
| j                  j!                  ||j"                  «       |
r6| j$                  j'                  |j                  «       d| j$                  _        |j*                  s|j                  t        j
                  k(  s�Œl|j-                  |j/                  «       «       �Œ�|j                  t        j0                  k(  s�Œ¬| j                  j!                  ||j"                  «       �ŒÔ |r| j2                  j5                  |«       g g }}| j$                  j6                  �r}| j$                  j6                  j9                  «       }|j:                  }d|_        t=        |«      D �cg c]  }|j                  › d|› �‘Œ }}t?        || j                  jA                  |j                  «      «      }||z
  }t=        |«      D ]D  }|j9                  «       }|jC                  «       }||_        | j$                  jE                  |«       ŒF |dk(  r�Œ|D ]*  }|jG                  |«      | j$                  jH                  |<   Œ, | j                  jK                  |j                  |«      \  }}|jM                  |«       |jM                  |«       | j$                  j6                  r�Œ}|ri| j                   jN                  }|�tP        jR                  jU                  |«      n	tW        «       }|5  | j                  jY                  ||«       ddd«       yyc c}w # 1 sw Y   yxY w)	z0Update request states based on generated tokens.r   r   zTried to update z	 request z in sync mode.NFz__child#)-r�   Úprepare_batch_updaterÁ   rk   r    ÚFINISHEDÚPENDINGr™   Úhas_new_tokenr×   ÚnamerN   Úgenerated_lenÚDECODINGÚupdate_and_check_completionrƒ   Ú!mark_shareable_blocks_as_completeÚcomplete_blocksr‚   Úfinish_requestÚblock_new_requestsÚ	streamingr\   rÉ   Ú
PREFILLINGrˆ   r^   Ú_requests_to_forkÚpopÚnum_childrenÚrangeÚminÚcompute_max_num_forksÚ!create_equivalent_initial_requestr·   Úforkr¡   Úfork_requestÚextendr’   r=   r¨   Ústreamr   Ú
copy_cache)r1   rË   Ú
new_tokensÚlogprobsÚcurrent_logits_indexÚpending_outputsÚfuture_staterÁ   ÚtokenÚlogprobÚis_finishedÚcopy_sourceÚcopy_destinationÚstate_to_forkrõ   ÚiÚnew_request_idsÚnum_to_forkÚnum_to_scheduleÚ_Únew_request_idÚchild_stateÚcopy_srcÚcopy_dstr’   Úmaybe_streams                             r2   Úupdate_batchz%ContinuousBatchProcessor.update_batch¦  s·  € à26×2IÑ2I×2^Ñ2^Ó2`Ñ/Ð˜: xØ ÐØˆØ-ó 	bˆLØ ×&Ñ&ˆEà�|‰|¤× 6Ñ 6¼×8MÑ8MÐNÑNØ×*Ò*à#×1Ò1Ø,°Ñ1Ð,ØÜ"Ð%5°e·l±l×6GÑ6GÐ5HÈ	ÐRW×RbÑRbÐQcÐcqÐ#rÓsÐsà×)Ò)à×&Ñ&Ó(¨AÒ-Ü#0×#9Ñ#9�E”Là"Ð#7Ñ8�Ø<DÐ<P˜(Ð#7Ò8ÐVZ�Ø$¨Ñ)Ð$ð $×?Ñ?ÀÀwÓO�à—
‘
×<Ñ<¸UÀL×D`ÑD`ÔaÙØ—N‘N×1Ñ1°%×2BÑ2BÔCØ8=�D—N‘NÔ5Ø—?’? e§l¡l´m×6LÑ6LÔ&LØ#×*Ñ*¨5×+EÑ+EÓ+GÖHà—‘¤×!9Ñ!9Ô9Ø—
‘
×<Ñ<¸UÀL×D`ÑD`Öað?	bñB Ø×Ñ×,Ñ,¨_Ô=ð )+¨BÐ%ˆØ�n‰n×.Ó.à ŸN™N×<Ñ<×@Ñ@ÓBˆMØ(×5Ñ5ˆLØ)*ˆMÔ&ÜQVÐWcÓQdÖeÈA -×":Ñ":Ð!;¸8ÀAÀ3ÒGÐeˆOÐeä˜l¨D¯J©J×,LÑ,LÈ]×MeÑMeÓ,fÓgˆKØ*¨[Ñ8ˆOÜ˜?Ó+ò @�Ø!0×!4Ñ!4Ó!6�Ø+×MÑMÓO�Ø)7�Ô&Ø—‘×2Ñ2°;Õ?ð	@ð ˜aÒÙà"1ò d�ØAN×ASÑASÐTbÓAc�—‘×.Ñ.¨~Ò>ðdð "&§¡×!8Ñ!8¸×9QÑ9QÐSbÓ!cÑˆH�hØ×Ñ˜xÔ(Ø×#Ñ# HÔ-ð/ �n‰n×.Ô.ñ4 ð "×4Ñ4×CÑCˆNØ@NÐ@Zœ5Ÿ:™:×,Ñ,¨^Ô<Ô`kÓ`mˆLØñ EØ—
‘
×%Ñ% kÐ3CÔD÷Eð Eð ùò+ f÷4Eð Eús   É6PÏ4P Ð P)c                 ó6   — | j                   j                  «       S )z2Check if there are any active or waiting requests.)r‚   rÓ   rI   s    r2   rÓ   z-ContinuousBatchProcessor.has_pending_requestsó  s   € à�~‰~×2Ñ2Ó4Ð4r5   c                 óâ   — | j                   j                  «       d   }|D ]M  }| j                  ||j                  «       | j                  j                  |j                  j                  «       ŒO y)z&Handle errors during batch processing.r   N)r�   rå   rº   rÁ   r‚   rï   rN   )r1   r¹   Úfailed_future_statesr  s       r2   Úhandle_batch_errorz+ContinuousBatchProcessor.handle_batch_error÷  sa   € à#×6Ñ6×KÑKÓMÈaÑPÐØ0ò 	IˆLØ×&Ñ& u¨l×.@Ñ.@ÔAØ�N‰N×)Ñ)¨,×*<Ñ*<×*GÑ*GÕHñ	Ir5   c                 ó(  — t        | j                  j                  j                  «       «      }|D ]9  }| j	                  ||«       | j                  j                  |j                  «       Œ; | j                  j                  «        t        | j                  j                  j                  «       «      D ]9  }| j                  j                  j                  |«      }| j	                  ||«       Œ; | j                  j                  j                  «        y)z.Fail all active requests with the given error.N)ra   r‚   r¡   Úvaluesrº   rï   rN   rœ   Úfree_all_waiting_cpu_cachesr¢   Úkeysrô   Úwaiting_requests_orderrj   )r1   r¹   ÚrequestsrÁ   Úreq_ids        r2   Úfail_all_requestsz*ContinuousBatchProcessor.fail_all_requestsþ  sÕ   € ô ˜Ÿ™×6Ñ6×=Ñ=Ó?Ó@ˆØò 	<ˆEØ×&Ñ& u¨eÔ4Ø�N‰N×)Ñ)¨%×*:Ñ*:Õ;ð	<ð
 	×Ñ×;Ñ;Ô=Ü˜4Ÿ>™>×:Ñ:×?Ñ?ÓAÓBò 	5ˆFØ—N‘N×3Ñ3×7Ñ7¸Ó?ˆEØ×&Ñ& u¨eÕ4ð	5ð
 	�‰×-Ñ-×3Ñ3Õ5r5   Úmodelc                 óÐ   — | j                   j                  | j                  j                  ¬«      }| j                  j	                  ||«       | j                   j                  «        y)z!Perform a single generation step.)rÐ   N)r�   r£   r�   rà   Úcompute_batchÚretrieve_device_outputs)r1   r!  Ú
batch_datas      r2   Ú_generation_stepz)ContinuousBatchProcessor._generation_step  sU   € ð
 ×,Ñ,×=Ñ=È$×J[ÑJ[×JfÑJfÐ=Ógˆ
ð 	×Ñ×'Ñ'¨¨zÔ:ð 	×Ñ×7Ñ7Õ9r5   c                 ó:   — | j                   j                  |«       y)aG  Pre-capture CUDA graphs (or trigger compile warmup) for varlen and decode paths. In async mode, both IO
        pairs are warmed up since each has its own graph buffer and static tensors. The varlen path is warmed up at
        the largest possible `(q, kv)` sizes so subsequent captures fit inside it without growing the pool.N)r�   Úwarmup©r1   r!  s     r2   r(  zContinuousBatchProcessor.warmup  s   € ð
 	×Ñ× Ñ  Õ'r5   r_   )(r9   r:   r;   r   r   r<   r$   r   r   r   r   r   rB   rC   r@   rc   r=   r+   r*   r   rJ   r>   r¤   r«   r­   ÚboolrÃ   r¸   r   rº   rã   r  rÓ   r  r   Úno_gradr
   ÚModuler&  r(  r0   r5   r2   r€   r€   ¼   s¤  … Ø-Ð0JÑJÓJØÓð\
à"ð\
ð !ð\
ð ,ð	\
ð
 %=ð\
ð ?ð\
ð —[‘[ 4Ñ'ð\
ð —k‘k DÑ(ð\
ð $ð\
ð #9ð\
ð —l‘lð\
ð —[‘[ð\
ð ð\
ð .ð\
ð 
ó\
ð|
˜#ó 
ó%ó'ð%¨ó %ðNA¨9ð A¸\ð AÈdó Að> Dó >ó@KEðZ5 dó 5òIð6 yð 6°Tó 6ð" €U‡]�]ƒ_ð: b§i¡ið :°Dò :ó ð:ð €U‡]�]ƒ_ð(˜BŸI™Ið (¨$ò (ó ñ(r5   r€   c                   ó0  — e Zd ZdZ	 d,dededededz  ddf
d„Zdeddfd	„Z	d-d
„Z
defd„Zd-d„Z	 	 	 	 d.dededz  dededdf
d„Zd,dededz  ddfd„Zd-d„Z	 	 	 	 	 d/dee   dedz  dedz  dededeee   z  dz  dededz  fd„Z	 	 	 d0deee      dedz  dedededee   fd„Zdeddfd„Zd1dedz  dedz  dedz  fd „Zd!„ Zdedee   fd"„Zded#eddfd$„Z e jB                  «       d-d%„«       Z"d-d&„Z#de$fd'„Z%d(e&d)e$dz  ddfd*„Z'd(e&d)e$dz  ddfd+„Z(y)2ÚContinuousBatchingManagera¼  Manager for handling continuous batching of generation requests. It provides a user interface for submitting
    generation requests, retrieving results, and managing the background generation thread. This class should not be
    created directly, but through one of the following entry points (all methods of the `ContinuousMixin` mixin):
    - `init_continuous_batching`
    - `continuous_batching_context_manager`
    - `generate_batch`
    Nr!  r6   r„   Úworkload_hintsr-   c                 ó  — t        j                  |j                  ¬«      | _        t        j                  «       | _        d| _        t        j                  «       | _        t        j                  «       | _
        t        «       | _        t        «       | _        d| _        d| _        d| _        d| _        d| _        | j)                  |«       |j+                  «       | _        || _        t1        |dd«      }|�|nd| _        t5        t1        | j,                  dd«      |j6                  ¬«      | _        | j8                  j:                  | _        |j<                  r| j8                  j?                  «        tA        | j,                  jC                  |«      |jD                  |jF                  ¬	«      | _$        tK        | j,                  jL                  ||| jH                  jN                  ¬
«      | _(        | jP                  jR                  | _*        y)ay  Initialize the continuous batching manager.

        Args:
            model: The language model for generation
            generation_config: Configuration for generation parameters
            continuous_batching_config: Configuration for continuous batching parameters
            workload_hints: Workload hints for the continuous batching initialization (optional)
        )Úmaxsizer   NFÚnum_return_sequencesr   Ú_device_mesh)Údevice_meshÚcpu_group_timeout)Úlogits_processorÚper_request_processorsÚdrop_unsupported_processors)r)   r“   r/  Úhas_logit_processors)+rB   rC   Úmax_queue_sizer†   r‡   Ú_request_counterrF   rG   Ú_request_lockÚEventÚ_has_new_requestsrc   r‰   r@   rˆ   Úbatch_processorÚ_generation_threadÚfatal_errorÚ	warmed_upÚ_original_attn_implÚswitch_to_paged_attnÚevalr!  r6   r•   r2  r   r5  rŒ   Úis_tp_driverÚdisable_nccl_graph_mixingÚmaybe_warn_nccl_graph_mixingr   r8   r7  r8  r…   r   r)   Údo_processingr„   Úallow_block_sharingÚ_use_prefix_sharing)r1   r!  r6   r„   r/  r2  s         r2   rJ   z"ContinuousBatchingManager.__init__0  s°  € ô  !Ÿ;™;Ð/I×/XÑ/XÔYˆÔÜ.3¯k©k«mˆÔØ !ˆÔÜ&Ÿ^™^Ó-ˆÔÜ!*§¡Ó!2ˆÔô )?Ó(@ˆÔ%Ü)›^ˆÔØ@DˆÔØ"&ˆÔð .2ˆÔØˆŒð $(ˆÔ Ø×!Ñ! %Ô(Ø—Z‘Z“\ˆŒ
ð "3ˆÔÜ&Ð'8Ð:PÐRVÓWÐØ<PÐ<\Ñ$8ÐbcˆÔ!ô #4Ü §
¡
¨N¸DÓAØ8×JÑJô#
ˆÔð !×3Ñ3×@Ñ@ˆÔà%×?Ò?Ø×#Ñ#×@Ñ@ÔBô  EØ!ŸZ™Z×=Ñ=Ð>OÓPØ#=×#TÑ#TØ(B×(^Ñ(^ô 
ˆÔô +MØ—:‘:×$Ñ$Ø0Ø)Ø!%×!5Ñ!5×!CÑ!Cô	+
ˆÔ'ð $(×#BÑ#B×#VÑ#VˆÕ r5   c                 ó¼   — d|j                   j                  vrD|j                   j                  | _        |j                  d|j                   j                  › �«       yy)zhSwitch to the paged version of the attention implementation. If the attn is already paged, does nothing.zpaged|N)r)   Ú_attn_implementationrC  r3   r)  s     r2   rD  z.ContinuousBatchingManager.switch_to_paged_attnu  sK   € à˜5Ÿ<™<×<Ñ<Ñ<Ø',§|¡|×'HÑ'HˆDÔ$Ø×)Ñ)¨F°5·<±<×3TÑ3TÐ2UÐ*VÕWð =r5   c                 óž   — | j                   €| j                  «       | _         | j                   j                  | j                  «       d| _        y)zŠPre-capture CUDA graphs for varlen and decode paths by running dummy batches. Initializes the batch
        processor if not already done.NT)r?  Ú_create_batch_processorr(  r!  rB  rI   s    r2   r(  z ContinuousBatchingManager.warmup{  s@   € ð ×ÑÐ'Ø#'×#?Ñ#?Ó#AˆDÔ Ø×Ñ×#Ñ# D§J¡JÔ/Øˆ�r5   c                 óV   — | j                   duxr | j                   j                  «       S )zUReturns True if the background generation thread has been started and is still alive.N)r@  Úis_aliverI   s    r2   Ú
is_runningz$ContinuousBatchingManager.is_running…  s'   € à×&Ñ&¨dÐ2ÒY°t×7NÑ7N×7WÑ7WÓ7YÐYr5   c                 ó  — | j                  «       rt        j                  d«       y| j                  j	                  «        d| _        t        j                  | j                  ¬«      | _	        | j                  j                  «        y)z'Start the background generation thread.z"Manager thread is already running.N)Útarget)rR  r!   Úwarningr‰   rj   rA  rF   ÚThreadÚ_run_generation_loopr@  ÚstartrI   s    r2   rX  zContinuousBatchingManager.start‰  sa   € à�?‰?ÔÜ�N‰NÐ?Ô@ØØ×%Ñ%×+Ñ+Ô-ØˆÔÜ"+×"2Ñ"2¸$×:SÑ:SÔ"TˆÔØ×Ñ×%Ñ%Õ'r5   ÚblockÚtimeoutÚkeep_for_next_sessionÚ	hard_stopc                 óî  — | j                   €t        j                  d«       | j                  €d}|r|dz  }t        j                  |«       yt	        «       }|rt
        j                  nt
        j                  }| j                  j                  || j                  j                  «       |r| j                  ||«       |sd| _         n&t        j                  d«       | | j                  _        | j                   �,| j                  j#                  | j                   «       d| _        t%        j&                  «        t(        j*                  j-                  «       rt(        j*                  j/                  «        yy)a¿  Stop the background generation thread. If the `block` flag is set to True, then this method waits for the
        thread to stop for a maximum time of `timeout` seconds (None means no timeout). If the `keep_for_next_session`
        flag is set to True, then the manager is cached on the model for future use. If the `hard_stop` flag is set,
        the background generation thread will be stopped immediately and pending requests will be failed.Nz%
Batch processor was not initialized.zManager not started.z? Hence the unstarted manager will not be kept for next session.z:Continuous batching manager will be kept for next session.)r?  r!   rU  r@  r   rc   ro   rn   r‰   rs   rŒ   rl   Újoinrr   r!  Ú#_cached_continuous_batching_managerrC  r3   r¦   r§   r=   r¨   r©   rª   )r1   rY  rZ  r[  r\  ÚmsgÚstop_trigger_timeÚstop_statuss           r2   ÚstopzContinuousBatchingManager.stop“  s(  € ð ×ÑÐ'Ü�N‰NÐCÔDð ×"Ñ"Ð*Ø(ˆCÙ$ØÐXÑX�Ü�N‰N˜3ÔØô )›NÐÙ:CÔ,×6Ò6ÔI_×InÑInˆØ×%Ñ%×2Ñ2°;À×@WÑ@W×@cÑ@cÔdáØ�I‰IÐ'¨Ô1ñ %Ø#'ˆDÕ ô �K‰KÐTÔUØ=AˆD�J‰JÔ:ð ×#Ñ#Ð/Ø�J‰J×.Ñ.¨t×/GÑ/GÔHØ'+ˆDÔ$ô 	�
‰
ŒÜ�:‰:×"Ñ"Ô$Ü�J‰J×"Ñ"Õ$ð %r5   ra  c                 ó  — | j                   €y| j                   j                  |¬«       | j                   j                  «       rt        j                  d|› d�«       yt        «       }t        j                  d||z
  d›d�«       d| _         y)zeWait for the background thread to finish. Wait can be capped using the timeout argument (in seconds).N©rZ  z3Generation thread did not exit after join timeout (z).z+Background generation thread stopped after ú.2fús.)r@  r^  rQ  r!   rU  r   rr   )r1   ra  rZ  Úends       r2   r^  zContinuousBatchingManager.joinÅ  s‡   € ð ×"Ñ"Ð*Øð 	×Ñ×$Ñ$¨WÐ$Ô5Ø×"Ñ"×+Ñ+Ô-Ü�N‰NÐPÐQXÐPYÐY[Ð\Õ]ä“.ˆCÜ�K‰KÐEÀcÐL]ÑF]Ð^aÐEbÐbdÐeÔfØ&*ˆDÕ#r5   c                 ó~   — | j                  «       r| j                  dd¬«       | j                  j                  «        y)z’Terminate the manager and release distributed resources. Safe to call multiple times. After calling this,
        the manager cannot be restarted.TF)rY  r[  N)rR  rc  rŒ   Údestroy_cpu_comm_grouprI   s    r2   Údestroyz!ContinuousBatchingManager.destroyÔ  s0   € ð �?‰?ÔØ�I‰I˜D¸ˆIÔ>Ø×Ñ×6Ñ6Õ8r5   Ú	input_idsrN   Úmax_new_tokensrñ   Úrecord_timestampsÚeos_token_idr¶   c           
      ó†  — | j                   sy| j                  j                  t        j                  k\  r0|dd › dd dz   |dd › dd z   }t        j                  d|› d�«       y|€9| j                  5  d	| j                  › �}| xj                  dz  c_        ddd«       |€| j                  j                  n|}|€| j                  j                  n|}t        |t        |«      | j                  dz
  |||||¬
«      }	| j                  j!                  |	dd¬«       | j"                  j%                  «        |S # 1 sw Y   Œ xY w)aÇ  Add a new generation request to the queue. If the process is not a TP driver, this is a no-op.

        Args:
            input_ids: Input token IDs to use as prompt
            request_id: Optional custom request ID (auto-generated if None)
            max_new_tokens: Maximum number of new tokens to generate
            streaming: Whether to stream tokens as they're generated
            record_timestamps: Whether to record timestamps for each generated token
            eos_token_id: End-of-sequence token ID(s)
            logit_processor_kwargs: Keyword arguments for the logits processor.

        Returns:
            str | None: The request ID if the process is a TP driver, None otherwise.
        Nr   éÿÿÿÿz, ..., éýÿÿÿr   z0Background thread is stopping. Request with ids z will be dropped.Úreq_)rN   Úinitial_tokensrõ   rn  rm  ro  rñ   r¶   Té
   ©rY  rZ  )rF  r‰   r{   rc   rn   r!   rU  r<  r;  r6   rm  ro  r   ra   r2  r†   rP   r>  Úset)
r1   rl  rN   rm  rñ   rn  ro  r¶   ÚpreviewrÁ   s
             r2   Úadd_requestz%ContinuousBatchingManager.add_requestÝ  s[  € ð2 × Ò Øà×(Ñ(×5Ñ5Ô9O×9^Ñ9^Ò^Ø" 2 A˜˜¨¨"Ð-°	Ñ9¸yÈÈ¸~Ð>NÐPQÐPRÐ<SÑSˆGÜ�N‰NÐMÈgÈYÐVgÐhÔiØàÐØ×#Ñ#ñ +Ø# D×$9Ñ$9Ð#:Ð;�
Ø×%Ò%¨Ñ*Õ%÷+ð CQÐBX˜×/Ñ/×>Ò>Ð^lˆØ>JÐ>R�t×-Ñ-×:Ò:ÐXdˆô Ø!Ü 	›?Ø×2Ñ2°QÑ6Ø/Ø)Ø%ØØ#9ô	
ˆð 	×Ñ×Ñ˜U¨$¸ÐÔ;Ø×Ñ×"Ñ"Ô$ØÐ÷++ð +ús   Á3%D7Ä7E Úinputsc                 ó  — t        |«      }| j                  5  t        | j                  | j                  |z   «      D �cg c]  }d|› �‘Œ	 }}| xj                  |z  c_        ddd«       t	        t        |«      «      }	| j                  rt        |	d„ d¬«      }	| j                  j                  }
|
€ | j                  j                  j                  n|
}
|
€dn|
}
|	D ]  \  }} | j                  d||||||
dœ|¤Ž Œ  |S c c}w # 1 sw Y   Œ£xY w)	zgUtility function to batch `add_request` and return their IDs. Check its documentation for more details.rs  Nc                 ó   — | d   S )Nr   r0   )Úxs    r2   ú<lambda>z8ContinuousBatchingManager.add_requests.<locals>.<lambda>'  s
   € À!ÀAÁ$€ r5   T)ÚkeyÚreverserq  )rl  rN   rm  rñ   rn  ro  r0   )r²   r<  rö   r;  ra   ÚziprK  Úsortedr6   ro  r!  r)   ry  )r1   rz  rm  rñ   rn  r¶   Únum_requestsr
  Úrequest_idsÚids_and_inputsro  rN   rl  s                r2   Úadd_requestsz&ContinuousBatchingManager.add_requests  s&  € ô ˜6“{ˆØ×Ññ 	2Ü/4°T×5JÑ5JÈD×LaÑLaÐdpÑLpÓ/qÖr¨!˜T ! š:ÐrˆKÐrØ×!Ò! \Ñ1Õ!÷	2ô œc +¨vÓ6Ó7ˆØ×#Ò#Ü# N¹ÐPTÔUˆNà×-Ñ-×:Ñ:ˆØ9EÐ9M�t—z‘z×(Ñ(×5Ò5ÐS_ˆØ)Ð1‘r°|ˆà%3ò 		Ñ!ˆJ˜	ØˆD×Ñð Ø#Ø%Ø-Ø#Ø"3Ø)ñð )óð		ð Ðùò+ s÷	2ð 	2ús   ˜&D¾C>Á
DÃ>DÄDc                 óˆ   — | j                   r6| j                  j                  |«       | j                  j	                  «        yy)zœCancel a request by its ID. If this called from a process that is not a TP driver, it's a no-op: only TP
        driver processes interact with the manager.N)rF  r‡   rP   r>  rw  )r1   rN   s     r2   Úcancel_requestz(ContinuousBatchingManager.cancel_request9  s8   € ð ×ÒØ×Ñ×!Ñ! *Ô-Ø×"Ñ"×&Ñ&Õ(ð r5   c                 óX  — | j                   €%| j                  j                  j                  «       ry	 | j                  j                  j	                  d|¬«      }|�5|j
                  |k7  r&| j                  j                  j                  |«       y|S # t        j                  $ r Y yw xY w)z³Retrieve one result from the output queue. If an ID is provided, returns the first matching request. If a
        timeout is provided, returns None after the timeout (in seconds).NTrv  )	r@  rˆ   rD   ÚemptyrM   rN   rP   rB   ÚEmpty)r1   rN   rZ  Úresults       r2   Ú
get_resultz$ContinuousBatchingManager.get_resultB  s›   € ð ×"Ñ"Ð*¨t×/AÑ/A×/NÑ/N×/TÑ/TÔ/VØð	Ø×'Ñ'×4Ñ4×8Ñ8¸tÈWÐ8ÓUˆFØÐ%¨&×*;Ñ*;¸zÒ*IØ×"Ñ"×/Ñ/×3Ñ3°FÔ;ØØˆMøÜ�{‰{ò 	Ùð	ús   ³AB ÂB ÂB)Â(B)c              #   óÜ   K  — | j                   �\| j                   j                  «       rA| j                  d¬«      }|�|–— | j                   �| j                   j                  «       rŒ?yyyy­w)z.Iterate over results as they become available.Nçš™™™™™¹?re  )r@  rQ  r�  )r1   rŒ  s     r2   Ú__iter__z"ContinuousBatchingManager.__iter__P  sf   è ø€ à×%Ñ%Ð1°d×6MÑ6M×6VÑ6VÔ6XØ—_‘_¨S�_Ó1ˆFØÐ!Ø’ð ×%Ñ%Ð1°d×6MÑ6M×6VÑ6VÖ6XÐ1Ð6XÐ1ùs   ‚A%A,Á(A,c              #   ó   K  — | j                   �n| j                   j                  «       rS| j                  |d¬«      }|�|–— |j                  «       ry| j                   �| j                   j                  «       rŒQyyyy­w)zÏIterate over results matching a specific request id (blocking).

        Uses the shared output queue with requeue. For high-concurrency serving,
        use :meth:`register_result_handler` instead.
        Nr�  )rN   rZ  )r@  rQ  r�  r  )r1   rN   rŒ  s      r2   Úrequest_id_iterz)ContinuousBatchingManager.request_id_iterW  sy   è ø€ ð ×%Ñ%Ð1°d×6MÑ6M×6VÑ6VÔ6XØ—_‘_°
ÀC�_ÓHˆFØÐ!Ø’Ø×%Ñ%Ô'Øð ×%Ñ%Ð1°d×6MÑ6M×6VÑ6VÖ6XÐ1Ð6XÐ1ùs   ‚A7A>Á:A>rR   c                 óÌ   ‡ ‡‡— t        j                  «       }ˆˆˆ fd„}‰ j                  j                  5  ||f‰ j                  j                  ‰<   ddd«       y# 1 sw Y   yxY w)a+  Register a callback for result delivery (streaming or non-streaming).

        The callback is invoked on the event loop via ``call_soon_threadsafe`` each time a result is produced for this
        request. For streaming requests, this happens on every token; for non-streaming, only on completion. The handler
        is automatically cleaned up when the request finishes.

        Args:
            request_id (`str`): The request ID to receive outputs for.
            callback (`callable`): Called with a ``GenerationOutput`` for each result.
        c                 óÚ   •—  ‰| «       | j                  «       rF‰j                  j                  5  ‰j                  j                  j	                  ‰d «       d d d «       y y # 1 sw Y   y xY wr/   )r  rˆ   rH   rE   rô   )rŒ  rR   rN   r1   s    €€€r2   Ú_auto_cleanupzHContinuousBatchingManager.register_result_handler.<locals>._auto_cleanupq  sf   ø€ Ù�VÔØ×!Ñ!Ô#Ø×'Ñ'×-Ñ-ñ MØ×&Ñ&×6Ñ6×:Ñ:¸:ÀtÔL÷Mð Mð $÷Mð Mús   °'A!Á!A*N)ÚasyncioÚget_running_looprˆ   rH   rE   )r1   rN   rR   rS   r•  s   ```  r2   Úregister_result_handlerz1ContinuousBatchingManager.register_result_handlerd  s^   ú€ ô ×'Ñ'Ó)ˆö	Mð ×Ñ×%Ñ%ñ 	SØ>KÈTÐ=RˆD×Ñ×.Ñ.¨zÑ:÷	S÷ 	Sñ 	Sús   µAÁA#c                 óô  — d}	 | j                  «       }|| _        d| _        |j                  r@|j	                  «       st        d«      ‚| j                  «        | xj                  dz  c_        	 |j	                  «       }|r6| j                  «        |j                  «        | xj                  dz  c_        n–| j                  j                  t        j                  k(  rno| j                  j                  t        j                  k(  r|j                  «       sn7| j                  j                  d¬«       | j                  j!                  «        Œßt#        |j$                  t&        «      r8d|j$                  j(                  z
  |j$                  _        |j                  «        t        d| j                  j                  ›�«      }| j+                  ||«       | j                  j5                  «        t/        j6                  d«       y# t,        $ r6}t/        j0                  d	|› �d¬
«       | j3                  ||«       Y d}~Œjd}~ww xY w# | j                  j5                  «        t/        j6                  d«       w xY w)z6Main processing loop running in the background thread.Nr   z$Failed to bootstrap the first batch.r   Tr�  re  zdGeneration loop finished before this request completed w/ self.background_thread_status.tp_status = zError in generation loop: r°   zCGeneration loop finished and background thread exited successfully.)rO  r?  Úcurrent_batchr™   rã   r×   r&  r  r‰   rw   rc   ro   rn   rÓ   r>  Úwaitrj   rÆ   r�   r   Úcurrent_pairÚ_fail_all_remaining_requestsr¸   r!   r¹   Ú_handle_critical_errorrv   rr   )r1   r?  Úrequests_availabler¹   rÂ   s        r2   rW  z.ContinuousBatchingManager._run_generation_loop|  s  € ð ˆð8	_à"×:Ñ:Ó<ˆOØ#2ˆDÔ Ø!"ˆDÔð ×1Ò1Ø&×9Ñ9Ô;Ü&Ð'MÓNÐNØ×%Ñ%Ô'Ø×"Ò" aÑ'Õ"ð Ø%4×%GÑ%GÓ%IÐ"ñ &Ø×)Ñ)Ô+Ø#×0Ñ0Ô2Ø×&Ò&¨!Ñ+Ö&ð ×2Ñ2×<Ñ<Ô@V×@`Ñ@`Ò`Øð ×1Ñ1×;Ñ;Ô?U×?dÑ?dÒdØ+×@Ñ@ÔBàð ×*Ñ*×/Ñ/¸Ð/Ô<Ø×*Ñ*×0Ñ0Ô2ð- ô4 ˜/×<Ñ<Ô>XÔYØBCÀo×FhÑFh×FuÑFuÑBu�×2Ñ2Ô?Ø×,Ñ,Ô.ô !ØwÈT×MjÑMj×MtÑMtÐLxÐyóˆEð ×-Ñ-¨e°_ÔEð ×)Ñ)×9Ñ9Ô;Ü�K‰KÐ]Õ^øô ò 	<Ü�L‰LÐ5°a°SÐ9ÀDÕIØ×'Ñ'¨¨?×;Ñ;ûð	<ûð ×)Ñ)×9Ñ9Ô;Ü�K‰KÐ]Õ^ús*   „GH È	IÈ,H>È9I È>IÉI É1I7c                 ó|   — | j                   €t        d«      ‚| j                   j                  | j                  «       y)z=Perform a single generation step. This is mostly cuda graphedNzNTried to perform a generation step before the batch processor was initialized.)r?  r×   r&  r!  rI   s    r2   r&  z*ContinuousBatchingManager._generation_step¼  s2   € à×ÑÐ'ÜÐoÓpÐpØ×Ñ×-Ñ-¨d¯j©jÕ9r5   c                 ó   — t        | dd«      }t        |t        «      r|j                  «        |S t	        | j
                  j                  | j                  | j
                  j                  | j                  t        | j
                  di «      | j
                  j                  ¬«      }|j                  | _        t        | j                  |j                  |j                  | j                  ¬«       |j                   dkD  rd| j                  _        | j                  j$                  }t'        j(                  |d«      }|€t+        j,                  d|› d�«       t.        } ||| j                  j0                  | j                  j2                  ¬	«      }t        || j
                  j                  | j4                  | j                  | j6                  | j8                  r| j:                  nd| j8                  r| j<                  nd| j>                  | j@                  | j
                  j                  | j
                  j                  || j                  ¬
«      }|S )ziCreate a new batch processor. If an already initialized batch processor exists, it is reset and returned.r?  NÚtp_plan)r)   r„   r+   rŒ   r¢  r*   )r“   Ú
num_blocksr˜   Úuse_prefix_sharingr   zScheduler 'z ' not found. Defaulting to FIFO.)rƒ   Úsafety_marginÚmax_requests_per_batch)rƒ   r)   r6   r„   r…   r†   r‡   rˆ   r‰   rŠ   r‹   r‚   rŒ   )!r•   rÆ   r€   r­   r   r!  r)   r„   r+   rŒ   r*   r¤  rK  r   r£  r˜   Únum_sliding_attention_groupsÚmax_blocks_per_requestÚscheduler_typer"   rM   r!   rU  r#   r¥  r¦  r6   r…   rF  r†   r‡   rˆ   r‰   )r1   r?  Úpaged_attention_cacher©  Úscheduler_clsr‚   s         r2   rO  z1ContinuousBatchingManager._create_batch_processorÂ  sï  € ô " $Ð(9¸4Ó@ˆÜ�oÔ'?Ô@Ø×!Ñ!Ô#Ø"Ð"ô !4Ø—:‘:×$Ñ$Ø'+×'FÑ'FØ—:‘:×$Ñ$Ø#×6Ñ6Ü˜DŸJ™J¨	°2Ó6Ø—*‘*×"Ñ"ô!
Ðð $9×#KÑ#KˆÔ ä-Ø×5Ñ5Ø,×7Ñ7Ø2×CÑCØ#×7Ñ7õ		
ð !×=Ñ=ÀÒAØEFˆD×+Ñ+ÔBð ×8Ñ8×GÑGˆÜ)×-Ñ-¨n¸dÓCˆØÐ Ü�N‰N˜[¨Ð(8Ð8XÐYÔZÜ)ˆMá!Ø'Ø×9Ñ9×GÑGØ#'×#BÑ#B×#YÑ#Yô
ˆ	ô 3Ø'Ø—:‘:×$Ñ$Ø"×4Ñ4Ø'+×'FÑ'FØ ×0Ñ0Ø,0×,=Ò,=˜×(Ò(À4Ø.2×.?Ò.?˜×*Ò*ÀTØ×,Ñ,Ø%)×%BÑ%BØŸ™×*Ñ*ØŸ
™
×(Ñ(ØØ#×6Ñ6ô
ˆð Ðr5   r¹   r?  c                 ó  — || _         | j                  j                  t        j                  | j
                  j                  ¬«       | j
                  j                  dt        j                  «       | j                  ||«       y)z:Handle critical errors that terminate the generation loop.)rk   rl   r   N)	rA  r‰   rs   rc   ro   rŒ   rl   r³   r�  )r1   r¹   r?  s      r2   rž  z0ContinuousBatchingManager._handle_critical_error   sk   € ð !ˆÔà×%Ñ%×2Ñ2Ü)×3Ñ3À×AXÑAX×AdÑAdð 	3ô 	
ð
 	×Ñ×3Ñ3°AÔ7M×7WÑ7WÔXà×)Ñ)¨%°ÕAr5   c                 óÀ   — 	 	 | j                   j                  «       }|�|j                  ||«       Œ/# t        j                  $ r Y nw xY w|�|j                  |«       yy)zCFail all remaining requests in the input queue and active requests.N)r†   Ú
get_nowaitrº   rB   r‹  r   )r1   r¹   r?  Úreq_datas       r2   r�  z6ContinuousBatchingManager._fail_all_remaining_requests  sl   € ð	ØØ×+Ñ+×6Ñ6Ó8�Ø"Ð.Ø#×9Ñ9¸%ÀÔJð øô �{‰{ò 	Ùð	úð Ð&Ø×-Ñ-¨eÕ4ð 's   ‚02 ²AÁAr/   r_   )TNFF)NNFFN)NFF)NN))r9   r:   r;   r`   r(   r   r   r%   rJ   rD  r(  r*  rR  rX  Úfloatrc  r^  rk  ra   r}   r>   r	   ry  r†  rˆ  r   r�  r�  r   r’  r   r˜  r=   r+  rW  r&  r€   rO  r¸   rž  r�  r0   r5   r2   r.  r.  '  s¼  „ ñð 04ñCWà#ðCWð ,ðCWð %=ð	CWð
 &¨Ñ,ðCWð 
óCWðJXÐ*>ð XÀ4ó XóðZ˜Dó Zó(ð Ø $Ø&+Øñ0%àð0%ð ˜‘ð0%ð  $ð	0%ð
 ð0%ð 
ó0%ñd+ eð +°e¸d±lð +Èdó +ó9ð "&Ø%)ØØ"'Ø/3ñ7à˜‘9ð7ð ˜$‘Jð7ð ˜d™
ð	7ð
 ð7ð  ð7ð ˜D ™I‘o¨Ñ,ð7ð #&ð7ð 
ˆt‰ó7ðx &*ØØ"'ñ!à�T˜#‘Y‘ð!ð ˜d™
ð!ð ð	!ð
  ð!ð #&ð!ð 
ˆc‰ó!ðF)¨ð )°ó )ñ S¨4¡Zð ÀÈÁð ÐYiÐlpÑYpó òð¨#ð °)Ð<LÑ2Mó ðS°#ð SÀð SÈdó Sð0 €U‡]�]ƒ_ò=_ó ð=_ó~:ð<Ð)Aó <ð|B¨Ið BÐH`ÐcgÑHgð BÐlpó Bð5°)ð 5ÐNfÐimÑNmð 5Ðrvô 5r5   r.  c                   ó†  — e Zd ZU dZeed<    ej                  «       	 	 	 ddedz  dedz  de	dz  de
fd„«       Zdd„Ze ej                  «       	 	 	 	 	 	 	 ddedz  d	ed
edz  dedz  dedede	dz  dee
   fd„«       «       Z ej                  «       	 	 	 	 	 	 ddeee      dedz  dedz  dededededeeef   fd„«       Zy)ÚContinuousMixina  Mixin class for models to add continuous batching capabilities. Continuous batching has three entry points:
    - `init_continuous_batching`, which is the actual entry point for continuous batching
    - `continuous_batching_context_manager`, which itself is a wrapper around `init_continuous_batching`
    - `generate_batch`, which is really a wrapper around `continuous_batching_context_manager`

    They are defined in this order. Any change made to any of those three entry points should be reflected in the other
    two.
    r6   Nr„   r/  r-   c                 óú  — t        | d«      rt        | d«      rt        | d«      st        d«      ‚t        | dd«      }t        |t        «      r(t        j                  d«       |j                  | «       |S |�|n| j                  }|€t        d«      ‚|j                  €t        j                  d	«       d
|_
        |€2t        t        |dd«      t        «      r|j                  }n
t        «       }t	        | |||¬«      S )a  Initialize a manager for continuous batching inference.

        Args:
            generation_config: An optional generation configuration, which may contain a CompileConfig object
            continuous_batching_config: An optional continuous batching configuration
            workload_hints: Optional WorkloadHints to help the continuous batching manager make better decisions for
                default values
        Returns:
            `ContinuousBatchingManager`: The manager instance to add requests and retrieve results.
        r)   r+   r*   z;Model must have 'config', 'device', and 'dtype' attributes.r_  NzÄCached continuous batching manager found: it will be re-used instead of creating a new one. If you want to create a new manager, you should call `destroy_cached_continuous_batching_manager` first.z8A GenerationConfig must be provided or set in the model.zE`eos_token_id` not set in GenerationConfig. Setting to -1 (disabled).rq  r„   )r!  r6   r„   r/  )ÚhasattrÚAttributeErrorr•   rÆ   r.  r!   rr   rD  r6   rp   ro  rU  r   r„   )r1   r6   r„   r/  Úcached_managerÚ
gen_configs         r2   Úinit_continuous_batchingz(ContinuousMixin.init_continuous_batching)  s  € ô$ �t˜XÔ&¬g°d¸HÔ.EÌWÐUYÐ[bÔMcÜ Ð!^Ó_Ð_ô ! Ð'LÈdÓSˆÜ�nÔ&?Ô@Ü�K‰Kðuôð ×/Ñ/°Ô5Ø!Ð!ð +<Ð*GÑ&ÈT×McÑMcˆ
ØÐÜÐWÓXÐXà×"Ñ"Ð*Ü�N‰NÐbÔcØ&(ˆJÔ#ð &Ð-Üœ' *Ð.JÈDÓQÔSkÔlØ-7×-RÑ-RÑ*ä-EÓ-GÐ*ô )ØØ(Ø'AØ)ô	
ð 	
r5   c                 óx   — t        | dd«      }t        |t        «      r|j                  «        t	        | d«       yy)zFDestroy the cached continuous batching manager and free GPU resources.r_  N)r•   rÆ   r.  rk  Údelattr)r1   r¶  s     r2   Ú*destroy_cached_continuous_batching_managerz:ContinuousMixin.destroy_cached_continuous_batching_manager`  s9   € ä  Ð'LÈdÓSˆÜ�nÔ&?Ô@Ø×"Ñ"Ô$Ü�DÐ?Õ@ð Ar5   rY  rZ  Úpersistent_managerr(  c              #   ó  K  — | j                  |||¬«      }|r`|j                  sTt        j                  d«       t	        «       }	|j                  «        t        j                  dt	        «       |	z
  d›d�«       |j                  «        	 |–— t        j                  d«       |j                  |||¬«       |s|j                  «        yy# t        j                  d«       |j                  |||¬«       |s|j                  «        w w xY w­w)	aÌ  A context manager to safely use the continuous batching manager. Arguments are similar to the ones of
        `init_continuous_batching`, except for:
            - block: whether to block the thread when stopping the manager. Default is True.
            - timeout: maximum time to wait for the thread to stop. Default is None (no timeout).
            - warmup: whether to pre-capture CUDA graphs at the largest sizes before running. Default is True.
        )r6   r„   r/  z%Warming up for continuous batching...zWarming up completed in rf  rg  z!Continuous batching loop finished)rY  rZ  r[  N)
r¸  rB  r!   rU  r   r(  rX  rÜ   rc  rk  )
r1   r6   rY  rZ  r„   r¼  r(  r/  ÚmanagerrX  s
             r2   Ú#continuous_batching_context_managerz3ContinuousMixin.continuous_batching_context_managerg  sî   è ø€ ð$ ×/Ñ/Ø/Ø'AØ)ð 0ó 
ˆñ
 ˜'×+Ò+ä�N‰NÐBÔCÜ “NˆEØ�N‰NÔÜ�N‰NÐ5´l³nÀuÑ6LÈSÐ5QÐQSÐTÔUØ�‰Œð	"ØŠMô �L‰LÐ<Ô=Ø�L‰L˜u¨gÐM_ˆLÔ`Ù%Ø—‘Õ!ð &øô �L‰LÐ<Ô=Ø�L‰L˜u¨gÐM_ˆLÔ`Ù%Ø—‘Õ!ð &üs   ‚BDÂ
C Â=DÃ>D	Ä	Drz  rn  Úprogress_barc           	      óð  — |si S t        j                  «       t        j                  k  rt        j                  d«       d}|€| j
                  n|}	|	j                  �|	j                  nd}
t        |«      |
z  }|j                  dd«      }|€|	j                  n|}t        t        d„ |D «       «      |�|nd|¬«      }|rt        j                  d	«       | j                  ||d
d|||¬«      }t        t         g«      }t        || d|› d�d¬«      }i }d}|5 }|5  |5 }	 |j                  |||¬«      }||k  rƒ|j!                  d¬«      }|r8|j"                  }|j%                  «       rM|||<   |dz  }|j'                  d«       n1|j)                  «       s!t        j*                  d«       t-        d«       n||k  rŒƒddd«       ddd«       ddd«       i }g }D ],  }|j1                  |«      }|�|||<   Œ|j3                  |«       Œ. |rt        j*                  d|› d�«       |S # t.        $ r$}t        j*                  d|› �d
¬«       Y d}~Œ’d}~ww xY w# 1 sw Y   Œ›xY w# 1 sw Y   ŒŸxY w# 1 sw Y   Œ£xY w)a-  Generate sequences for a batch of prompts using continuous batching.

        Args:
            inputs: List of input token sequences (prompts)
            generation_config: Optional generation configuration
            continuous_batching_config: Optional continuous batching configuration
            record_timestamps: If set to true, the requests will have a timestamp for each token generated
            progress_bar: If set to true, a progress bar will be displayed
            persistent_manager: whether to persist the manager after the generation is finished. Default is False.
            warmup: whether to pre-capture CUDA graphs before processing requests. Default is True.
        Returns:
            `dict[str, GenerationOutput]`: a dictionary of request ids to GenerationOutput objects
        z=Progress bar is disabled when logger level is less than DEBUGFNr   rm  c              3   ó2   K  — | ]  }t        |«      –— Œ y ­wr/   )r²   )Ú.0rl  s     r2   ú	<genexpr>z1ContinuousMixin.generate_batch.<locals>.<genexpr>¼  s   è ø€ Ò!I°Y¤# i§.Ñ!Iùs   ‚r   )Úmax_prompt_lengthÚmax_generated_lengthrƒ  a,  Since you passed `persistent_manager=True`, the manager will be kept alive after the generation is finished. However, it was sized specifically for the requests passed in `generate_batch`. If you plan to reuse the manager for a very different workload, you might want to create a new manager instead.Té   )r6   r„   rY  rZ  r¼  r(  r/  zSolving z	 requestsÚrequest)ÚtotalÚdisableÚdescÚunit)rz  rm  rn  re  z*Generation thread terminated unexpectedly.zCReturning results of generate_batch despite unexpected termination.zError during batch generation: r°   z	Requests z not found in results.)r!   ÚgetEffectiveLevelr   rÛ   rU  r6   r2  r²   rô   rm  r%   rq   r¿  r   r   r†  r�  rN   r  ÚupdaterR  r¹   Úprintr¸   rM   r\   )r1   rz  r6   r„   rn  rÀ  r¼  r(  ÚkwargsÚgen_cfgr2  rƒ  rm  r/  Ú
manager_cmÚ
logging_cmÚpbar_cmÚresultsÚfinished_countr¾  Úpbarr„  rŒ  r  rÂ   Úreordered_resultsÚmissing_keyss                              r2   Úgenerate_batchzContinuousMixin.generate_batch�  sÓ  € ñ4 ØˆIô ×#Ñ#Ó%¬¯©Ò6Ü�N‰NÐZÔ[Ø ˆLð ->Ð,E�$×(Ò(ÐK\ˆØ?F×?[Ñ?[Ð?g˜w×;Ò;ÐmnÐÜ˜6“{Ð%9Ñ9ˆð  Ÿ™Ð$4°dÓ;ˆØ3AÐ3I˜×/Ò/È~ˆô 'Ü!Ñ!IÀ&Ô!IÓIØ3AÐ3M¡ÐSTØ%ô
ˆñ
 Ü�N‰Nðvôð ×=Ñ=Ø/Ø'AØØØ1ØØ)ð >ó 
ˆ
ô +¬F¨8Ó4ˆ
ÜØØ%Ð%Ø˜L˜>¨Ð3Øô	
ˆð ˆØˆØð 	S˜7 Jñ 	S°ð 	S¸4ðSØ%×2Ñ2Ø!°.ÐTeð 3ó �ð % |Ò3Ø$×/Ñ/¸Ð/Ó:�FÙØ!'×!2Ñ!2˜Ø!×-Ñ-Ô/Ø.4˜G F™OØ*¨aÑ/˜NØ ŸK™K¨�NØ$×/Ñ/Ô1ÜŸ™Ð%QÔRäÐcÔdØð % |Ó3÷	S÷ 	S÷ 	Sð. ÐØˆØ!ò 	,ˆFØ—[‘[ Ó(ˆFØÐ!Ø,2Ð! &Ò)à×#Ñ# FÕ+ð	,ñ Ü�L‰L˜9 \ NÐ2HÐIÔJØ Ð øô ò SÜ—‘Ð>¸q¸cÐBÈT×RÒRûðSú÷'	Sð 	Sú÷ 	Sð 	Sú÷ 	Sð 	Súsa   ÄI,ÄI ÄIÄBH$Æ:I ÇI,È$	I	È-I	ÉIÉI	ÉIÉIÉI É I)	É%I,É,I5)NNNr_   )NTNNFTN)NNFTFT)r9   r:   r;   r`   r   r<   r=   r+  r   r%   r.  r¸  r»  r   r*  r°  r   r¿  ra   r}   Údictr>   r   rÚ  r0   r5   r2   r²  r²    s¸  … ñð (Ó'à€U‡]�]ƒ_ð 6:ØFJØ/3ñ	4
à+¨dÑ2ð4
ð %=¸tÑ$Cð4
ð &¨Ñ,ð	4
ð
 
#ò4
ó ð4
ólAð Ø€U‡]�]ƒ_ð 6:ØØ $ØFJØ#(ØØ/3ñ#"à+¨dÑ2ð#"ð ð#"ð ˜‘ð	#"ð
 %=¸tÑ$Cð#"ð !ð#"ð ð#"ð &¨Ñ,ð#"ð 
Ð,Ñ	-ò#"ó ó ð#"ðL €U‡]�]ƒ_ð 6:ØFJØ"'Ø!Ø#(Øñm!à�T˜#‘Y‘ðm!ð ,¨dÑ2ðm!ð %=¸tÑ$Cð	m!ð
  ðm!ð ðm!ð !ðm!ð ðm!ð 
ˆcÐ#Ð#Ñ	$òm!ó ñm!r5   r²  )Ar–  r¦   rB   rF   Úabcr   Úcollections.abcr   r   Ú
contextlibr   r   Útimer   Útypingr	   r=   r
   r   Útqdm.contrib.loggingr   Úconfiguration_utilsr   Úgeneration.configuration_utilsr   r   Úutils.loggingr   Úlogits_processr   rƒ   r   Úcb_logits_processorsr   Údistributedr   Úinitializationr   r   Úinput_outputsr   r   r�   r   rœ   r   r  r   r   r    r!   r‚   r"   r#   r$   Úutilsr%   r&   r,  r(   r@   rc   r€   r.  r²  r0   r5   r2   ú<module>rë     s¯   ðó Û 	Û Û Ý ß /ß 2Ý Ý ã Ý Ý Ý 6å 3ß XÝ $Ý 0Ý &Ý GÝ *ß eß LÝ %Ý 1ß KÓ Kß BÑ Bß -ðô,˜2Ÿ9™9ô ÷,2ñ ,2÷^7ñ 7÷vg(ñ g(÷Vs5ñ s5÷l`!ò `!r5   