§
    H�’jÚU  ã                  ó  — d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
 d dlZd dlmZ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 e	rd dlmZmZ d dlmZ  e
dd¬¦  «        Zej                              e!d¦  «        Z"ej                              e!d¦  «        Z#e$e%ej&        z  dz           Z'ee$e         ge'f         Z(ej)        j*        j+        j,        ej)        j*        j+        j-        ej)        j*        j+        j.        ej)        j*        j+        j/        ej)        j*        j+        j0        fZ1 G d„ d¦  «        Z2 ej3        dd¬¦  «         G d„ d¦  «        ¦   «         Z4 ej3        dd¬¦  «         G d„ d¦  «        ¦   «         Z5 ej3        dd¬¦  «         G d„ d¦  «        ¦   «         Z6 ej3        dd¬¦  «         G d„ d¦  «        ¦   «         Z7dld#„Z8dmd%„Z9dnd(„Z:dod*„Z;dpd+„Z<dqd/„Z=drd2„Z>dsd7„Z?dtd=„Z@dud?„ZAdvdB„ZBdwdC„ZCdvdD„ZDdxdG„ZEej3         G dH„ dI¦  «        ¦   «         ZFdydP„ZGdzdR„ZH G dS„ dTe¦  «        ZId{dY„ZJd|d_„ZK ej3        d¬`¦  «         G da„ db¦  «        ¦   «         ZL ej3        d¬`¦  «         G dc„ dd¦  «        ¦   «         ZMd}dh„ZNd~dk„ZOdS )é    )ÚannotationsN)ÚCallable)ÚEnum)ÚAnyÚTYPE_CHECKINGÚTypeVar)ÚcountersÚget_metrics_context)ÚGraphPartitionMapÚ	InputType)Úget_plain_tensorsÚis_fake)Ú
OrderedSeté   )Úis_using_cudagraph_partition)ÚSequenceÚSet)Ú
OutputCodeÚ_OCr   )ÚboundÚ
cudagraphsÚcudagraph_static_inputsc                  ó*   — e Zd ZdZdd„Zdd„Zdd„ZdS )ÚCUDAGraphPolicya^  Pluggable policy controlling CUDA graph wrapping in Inductor's post_compile.

    Override methods to customize:
      - HOW compiled functions are cudagraph-wrapped (cudagraphify)
      - WHETHER inner CompiledFxGraphs should be wrapped (should_wrap)
      - OUTER wrapping of compound outputs like RegionalOutputCode (wrap_output)

    Set via ``torch._inductor.config.cudagraph_policy``.  When ``None``
    (the default), the existing built-in behaviour is used unchanged.

    Example usage::

        class MyCUDAGraphPolicy(CUDAGraphPolicy):
            def cudagraphify(self, model, example_inputs, static_input_idxs, **kwargs):
                return my_custom_wrapper(model, example_inputs, static_input_idxs)


        with torch._inductor.config.patch("cudagraph_policy", MyCUDAGraphPolicy()):
            compiled_fn = deserialize_artifacts(...)
    ÚmodelúCallable[..., Any]Úexample_inputsúSequence[InputType]Ústatic_input_idxsúSequence[int]Údevice_indexÚintÚis_backwardÚboolÚis_inferenceÚkwargsr   Úreturnc               ó*   — ddl m}  |||f|||dœ|¤ŽS )aÜ  Wrap a single compiled callable with CUDA graph capture/replay.

        Called by ``cudagraph_post_compile`` for each ``CompiledFxGraph``.
        The default delegates to ``compile_fx.cudagraphify`` (cudagraph_trees).

        ``example_inputs`` are the example inputs at post_compile time.
        The default implementation does not forward them because
        ``compile_fx.cudagraphify`` defers graph recording to the first
        real call via an inner closure.  Subclasses that need the
        example inputs for warmup or static-input detection may use them.

        When ``config.graph_partition=True``, setting a CUDAGraphPolicy
        bypasses ``cudagraph_partition_post_compile`` (which wraps each
        partition individually) and routes through ``cudagraph_post_compile``
        instead, so this method wraps the *entire* callable, not individual
        partitions.  Subclasses that need per-partition control should
        handle partitioning internally.
        r   )Úcudagraphify)r!   r#   r%   )Útorch._inductor.compile_fxr)   )	Úselfr   r   r   r!   r#   r%   r&   r)   s	            úMC:\Projects\DSCons\.venv\Lib\site-packages\torch\_inductor\cudagraph_utils.pyr)   zCUDAGraphPolicy.cudagraphifyC   sO   € ð: 	<Ð;Ð;Ð;Ð;Ð;àˆ|ØØð
ð &Ø#Ø%ð
ð 
ð ð
ð 
ð 	
ó    Úcompiled_graphr   c                ó   — dS )aQ  Whether to apply cudagraph wrapping to this CompiledFxGraph.

        Called for each inner ``CompiledFxGraph`` during ``post_compile``.
        Return ``False`` to skip wrapping (e.g. when wrapping at the outer
        level via ``wrap_output`` instead).

        Default: ``True`` (wrap everything, same as current behaviour).
        T© )r+   r.   s     r,   Úshould_wrapzCUDAGraphPolicy.should_wrapk   s	   € ð ˆtr-   Úoutput_coder   c                ó   — |S )aá  Optional outer-level wrapping after inner post_compile completes.

        Called by ``_compile_fx_inner``, ``BundledOutputCodeLoadable.post_compile``,
        and ``FxGraphCacheLoadable.post_compile`` on the ``OutputCode`` returned
        from ``post_compile``.  Subclasses that only want to wrap specific
        output types should check ``isinstance`` and return the input
        unchanged for types they don't handle.

        Default: identity (no outer wrapping).
        r0   )r+   r2   s     r,   Úwrap_outputzCUDAGraphPolicy.wrap_outputv   s
   € ð Ðr-   N)r   r   r   r   r   r    r!   r"   r#   r$   r%   r$   r&   r   r'   r   )r.   r   r'   r$   )r2   r   r'   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r1   r4   r0   r-   r,   r   r   -   s[   € € € € € ðð ð*&
ð &
ð &
ð &
ðP	ð 	ð 	ð 	ðð ð ð ð ð r-   r   T)ÚfrozenÚslotsc                  ó   — e Zd ZU dZded<   dS )Ú
FunctionIDz9Unique counter of a function wrapped in cudagraphify_implr"   ÚidN©r5   r6   r7   r8   Ú__annotations__r0   r-   r,   r<   r<   „   s   € € € € € € à?Ð?à€G€G�G€G€Gr-   r<   c                  ó<   — e Zd ZU dZded<   ded<   ded<   ded<   d	S )
ÚPlaceholderInfozÚ
    A serializable version of torch.fx.Node that contains information
    pertinent to placeholder stack traces. We use these in logging and error messages
    related to cudagraphs, and will cache these results.
    ÚstrÚnameú
str | NoneÚstack_traceúlist[PlaceholderInfo]ÚusersÚmutating_use_stack_traceNr>   r0   r-   r,   rA   rA   ‹   sK   € € € € € € ðð ð €I€I�IØÐÐÑà Ð Ð Ñ Ø(Ð(Ð(Ñ(Ð(Ð(r-   rA   c                  ó$   — e Zd ZU ded<   ded<   dS )ÚInputStorageMutationInfoúOrderedSet[int]Ú
input_idxsrD   rE   N)r5   r6   r7   r?   r0   r-   r,   rJ   rJ   š   s*   € € € € € € àÐÐÑØÐÐÑÐÐr-   rJ   c                  óP   — e Zd ZU dZded<   ded<   ded<   ded	<   d
ed<   ded<   dS )ÚWrappedFunctionzÈ
    Represents a function that you want to record for CUDA graph replay,
    with a little more metadata so we can identify if we have an applicable
    CUDA graph in our CUDA graph tree for it.
    r   r   r    r   r<   r=   ztuple[torch.Tensor, ...]Ú	constantsúSequence[PlaceholderInfo]ÚplaceholdersÚmutated_input_idxsNr>   r0   r-   r,   rN   rN       sc   € € € € € € ðð ð ÐÐÑØ$Ð$Ð$Ñ$Ø€N€N�NØ'Ð'Ð'Ñ'Ø+Ð+Ð+Ñ+Ø%Ð%Ð%Ñ%Ð%Ð%r-   rN   Úplaceholder_nodeútorch.fx.Noder'   rD   c                óD  — t          | j        ¦  «        dk    r:t          t          | j        ¦  «        ¦  «        j                             dd ¦  «        S | j        D ]E}|j        t          j        j	        j
        j        u r!|j                             dd ¦  «        x}r|c S ŒFd S )Nr   rE   )ÚlenrG   ÚnextÚiterÚmetaÚgetÚtargetÚtorchÚopsÚatenÚcopy_Údefault)rS   ÚuserE   s      r,   Ú&get_mutating_use_stack_trace_from_noderb   °   s    € õ ÐÔ!Ñ"Ô" aÒ'Ð'Ý•DÐ)Ô/Ñ0Ô0Ñ1Ô1Ô6×:Ò:¸=È$ÑOÔOÐOàÔ%ð #ð #ˆØŒ:�œœÔ-Ô5Ð5Ð5Ø!œhŸlšl¨=¸$Ñ?Ô?Ð?ˆ{ð #Ø"Ð"Ð"Ð"øàˆ4r-   Úplaceholder_infoc                ó   — | j         S ©N)rH   )rc   s    r,   Úget_mutating_use_stack_tracerf   ¿   s   € ØÔ4Ð4r-   Úgmútorch.fx.GraphModulec                óÔ  — d„ | j         j        D ¦   «         }d„ t          |¦  «        D ¦   «         }t          ¦   «         }d }| j         j        D ]�}|j        dk    s|j        t          vrŒ|j        r|j        d         nd }t          |t          j
        j        ¦  «        r<||v r8|                     ||         ¦  «         |€|j                             dd ¦  «        }ŒŽt          ||¦  «        S )Nc                ó(   — g | ]}|j         d k    ¯|‘ŒS ©Úplaceholder)Úop©Ú.0Únodes     r,   ú
<listcomp>z3get_input_storage_mutation_info.<locals>.<listcomp>Æ   s$   € ÐPÐPÐP˜T°t´wÀ-Ò7OÐ7O�DÐ7OÐ7OÐ7Or-   c                ó   — i | ]\  }}||“Œ	S r0   r0   )ro   Úidxrp   s      r,   ú
<dictcomp>z3get_input_storage_mutation_info.<locals>.<dictcomp>Ç   s   € ÐNÐNÐN©¨¨d˜4 ÐNÐNÐNr-   Úcall_functionr   rE   )ÚgraphÚnodesÚ	enumerater   rm   r[   ÚINPUT_STORAGE_MUTATION_TARGETSÚargsÚ
isinstancer\   ÚfxÚNodeÚaddrY   rZ   rJ   )rg   rQ   Úplaceholder_indicesÚstorage_mutation_input_idxsrE   rp   Úmutated_args          r,   Úget_input_storage_mutation_infor‚   Ã   sü   € ð QÐP R¤X¤^ÐPÑPÔP€LØNÐNµiÀÑ6MÔ6MÐNÑNÔNÐÝ3=±<´<ÐØ"€Kà””ð Að AˆàŒG�Ò&Ð&ØŒ{Õ"@Ð@Ð@àà&*¤iÐ9�d”i ”l�l°Tˆõ
 �{¥E¤H¤MÑ2Ô2ð	AàÐ2Ð2Ð2à'×+Ò+Ð,?ÀÔ,LÑMÔMÐMØÐ"Ø"œiŸmšm¨M¸4Ñ@Ô@�øå#Ð$?ÀÑMÔMÐMr-   Ústorage_mutation_infoc                óh   — | j         }|sd S dt          |¦  «        › d�}| j        r|› d| j        › �S |S )Nzinput storage mutation (ú instances)z. Found from:
 )rL   rV   rE   )rƒ   r€   Úmsgs      r,   Ú!get_input_storage_mutation_reasonr‡   á   s\   € ð #8Ô"BÐØ&ð Øˆtà
R¥SÐ)DÑ%EÔ%EÐ
RÐ
RÐ
R€CØÔ(ð KØÐJÐJÐ'<Ô'HÐJÐJÐJà€Jr-   c                óÈ   — | j         }| j                             dd ¦  «        }g }d }| j        dk    r d„ | j        D ¦   «         }t          | ¦  «        }t          ||||¦  «        S )NrE   rl   c                ó,   — g | ]}t          |¦  «        ‘ŒS r0   )Úto_placeholder_info)ro   Úis     r,   rq   z'to_placeholder_info.<locals>.<listcomp>ö   s!   € ÐHÐHÐH¨AÕ$ QÑ'Ô'ÐHÐHÐHr-   )rC   rY   rZ   rm   rG   rb   rA   )rS   rC   rE   rG   rH   s        r,   rŠ   rŠ   ï   s|   € ØÔ €DØ"Ô'×+Ò+¨M¸4Ñ@Ô@€KØ€EØ#ÐàÔ˜mÒ+Ð+ØHÐHÐ1AÔ1GÐHÑHÔHˆÝ#IØñ$
ô $
Ð õ ˜4 ¨eÐ5MÑNÔNÐNr-   rv   útorch.fx.GraphrF   c                ó$   — d„ | j         D ¦   «         S )Nc                óB   — g | ]}|j         d k    ¯t          |¦  «        ‘ŒS rk   )rm   rŠ   rn   s     r,   rq   z(get_placeholder_info.<locals>.<listcomp>ÿ   s4   € ð ð ð Ø&*¸T¼WÈÒ=UÐ=UÕ˜DÑ!Ô!Ð=UÐ=UÐ=Ur-   )rw   )rv   s    r,   Úget_placeholder_infor�   þ   s%   € ðð Ø.3¬kðñ ô ð r-   ÚreasonrB   c                ó   — d| › �S )Nzskipping cudagraphs due to r0   )r�   s    r,   Úformat_default_skip_messager’     s   € Ø1¨Ð1Ð1Ð1r-   rQ   rP   Úmutation_indicesú AbstractSet[int] | Sequence[int]c                óœ   — d}|D ]}| |         }t          |¦  «        x}r nŒt          dt          |¦  «        › d�¦  «        }|r|› d|› �S |S )NÚ zmutated inputs (r…   ú. Found from : 
 )rf   r’   rV   )rQ   r“   rE   rs   rl   r†   s         r,   Úget_mutation_stack_tracer˜     sŒ   € ð !€Kàð ð ˆØ" 3Ô'ˆÝ6°{ÑCÔCÐCˆ;ð 	ØˆEð	õ &Ø=�3Ð/Ñ0Ô0Ð=Ð=Ð=ñô €Cð ð 7ØÐ6Ð6¨Ð6Ð6Ð6à€Jr-   ÚfuncÚinputsúlist[InputType]Úis_cuda_graph_recorded_tensorúCallable[[torch.Tensor], bool]c                ó   ‡ ‡‡— t           j        j        j        j        rˆ ˆˆfd„‰ j        D ¦   «         }n‰ j        }t                               d‰ j        ¦  «         t                               d|¦  «         |rt          ‰ j
        |¦  «        nd S )Nc                óH   •— g | ]}|‰j         v ° ‰‰|         ¦  «        °|‘ŒS r0   )r   )ro   rs   r™   rš   rœ   s     €€€r,   rq   z&check_for_mutation.<locals>.<listcomp>$  sJ   ø€ ð +
ð +
ð +
àà�tÔ-Ð-Ð-Ø0Ð0°¸´Ñ=Ô=ð .ð ð .Ð-Ð-r-   z'check mutation static input indices: %szcheck mutation indices: %s)r\   Ú	_inductorÚconfigÚtritonÚcudagraph_treesrR   Ústatic_inputs_logÚdebugr   r˜   rQ   )r™   rš   rœ   r“   s   ``` r,   Úcheck_for_mutationr¦     s¾   øøø€ õ „ÔÔ$Ô4ð 3ð+
ð +
ð +
ð +
ð +
ð +
àÔ.ð+
ñ +
ô +
ÐÐð  Ô2Ðå×ÒØ1°4Ô3Iñô ð õ ×ÒÐ8Ð:JÑKÔKÐKð ð	Õ  Ô!2Ð4DÑEÔEÐEàðr-   rp   c                ó\   — | j         D ]#}|j                             dd ¦  «        x}r|c S Œ$d S )NrE   )rG   rY   rZ   )rp   ra   rE   s      r,   Ú_get_use_stack_tracer¨   ;  sF   € ØŒzð ð ˆØœ(Ÿ,š, }°dÑ;Ô;Ð;ˆ;ð 	ØÐÐÐð	àˆ4r-   Údevice_node_mappingú!dict[torch.device, torch.fx.Node]c                óˆ  — |                       t          j        d¦  «        d ¦  «         t          ¦   «         r(|                       t          j        d¦  «        d ¦  «         |                      t          j        d¦  «        ¦  «        x}r?d|j        › d�}t          |¦  «        x}rt          |› d|› �¦  «        S t          |¦  «        S t          | ¦  «        dk    r9t          t          |                      ¦   «         ¦  «        ¦  «        j        dk    rd S d„ | D ¦   «         }t          d	d
                     |¦  «        › �¦  «        S )NrY   Úcpuzcpu device (ú)r—   r   Úcudac              3  ó4   K  — | ]}t          |¦  «        V — Œd S re   )Úrepr)ro   Úkeys     r,   ú	<genexpr>z:check_multiple_devices_or_any_cpu_nodes.<locals>.<genexpr>Z  s(   è è € Ð:Ð:˜s•�c‘”Ð:Ð:Ð:Ð:Ð:Ð:r-   zmultiple devices: z, )Úpopr\   Údevicer   rZ   rC   r¨   r’   rV   rW   rX   ÚkeysÚtypeÚjoin)r©   Úcpu_noder†   rE   Ú	keys_reprs        r,   Ú'check_multiple_devices_or_any_cpu_nodesrº   B  sH  € ð ×Ò�EœL¨Ñ0Ô0°$Ñ7Ô7Ð7õ $Ñ%Ô%ð ;à×Ò¥¤¨UÑ 3Ô 3°TÑ:Ô:Ð:à&×*Ò*­5¬<¸Ñ+>Ô+>Ñ?Ô?Ð?€xð 0Ø-˜Xœ]Ð-Ð-Ð-ˆÝ.¨xÑ8Ô8Ð8ˆ;ð 	XÝ.°#Ð/VÐ/VÈÐ/VÐ/VÑWÔWÐWå*¨3Ñ/Ô/Ð/õ 	ÐÑ Ô  AÒ%Ð%Ý•Ð)×.Ò.Ñ0Ô0Ñ1Ô1Ñ2Ô2Ô7¸6ÒAÐAàˆtà:Ð:Ð&9Ð:Ñ:Ô:€IÝ&Ð'R¸D¿IºIÀiÑ<PÔ<PÐ'RÐ'RÑSÔSÐSr-   c                 óœ   — t           j                             ¦   «         r-t           j                             ¦   «         st          d¦  «        S dS )aÑ  Skip cudagraphs when the CUDA/HIP caching allocator is disabled
    (via ``torch.cuda.caching_allocator_enable(False)`` or the env-var
    bypass ``PYTORCH_NO_(CUDA|HIP)_MEMORY_CACHING``). Cudagraph capture
    pools allocations through the caching allocator; with it bypassed,
    capture appears to succeed but pool tracking diverges (see
    check_memory_pool in cudagraph_trees.py), surfacing as 'storage data
    ptrs not allocated in pool ...' at replay time.zOcudagraph capture requires the caching allocator; current allocator is uncachedN)r\   r®   Úis_availableÚ_CÚ%_cuda_cudaCachingAllocator_is_enabledr’   r0   r-   r,   Ú&check_caching_allocator_for_cudagraphsr¿   ^  sR   € õ 	Œ
×ÒÑ!Ô!ð
õ ”×>Ò>Ñ@Ô@ð
õ
 +ð,ñ
ô 
ð 	
ð ˆ4r-   c                ó<   — t          ¦   «         pt          | ¦  «        S re   )r¿   rº   )r©   s    r,   Ú check_lowering_disable_cudagraphrÁ   r  s$   € õ 	/Ñ0Ô0ð 	HÝ2Ð3FÑGÔGðr-   r†   ÚNonec                ó<  — t                                | ¦  «         t          d         dxx         dz  cc<   t          j        j        j        j        rt          | ¦  «        ‚t          ¦   «         }| 
                    ¦   «         r|                     d| d¬¦  «         d S d S )NÚinductorÚcudagraph_skipsr   Úcudagraph_skip_reasonT)Ú	overwrite)Úcudagraphs_logÚwarningr	   r\   r    r¡   r¢   Úcudagraph_or_errorÚRuntimeErrorr
   Úin_progressÚset)r†   Úmetrics_contexts     r,   Ú#log_cudagraph_skip_and_bump_counterrÏ   {  s§   € Ý×Ò˜3ÑÔÐÝˆZÔÐ*Ð+Ð+Ô+¨qÑ0Ð+Ð+Ñ+å„ÔÔ$Ô7ð  Ý˜3ÑÔÐå)Ñ+Ô+€OØ×"Ò"Ñ$Ô$ð JØ×ÒÐ3°SÀDÐÑIÔIÐIÐIÐIðJð Jr-   c                  ó"   — e Zd ZU ded<   dd„ZdS )	ÚBoxedDeviceIndexú
int | NoneÚvalueÚ
device_idxr'   rÂ   c                óF   — |�t          |t          ¦  «        sJ ‚|| _        d S re   )r{   r"   rÓ   )r+   rÔ   s     r,   rÍ   zBoxedDeviceIndex.set‹  s(   € ØÐ!¥Z°
½CÑ%@Ô%@Ð!Ð!Ð@ØˆŒ
ˆ
ˆ
r-   N)rÔ   rÒ   r'   rÂ   )r5   r6   r7   r?   rÍ   r0   r-   r,   rÑ   rÑ   ‡  s6   € € € € € € àÐÐÑð ð  ð  ð  ð  ð  r-   rÑ   Úmutated_inputsúOrderedSet[str]rR   rK   r   r    c                ó:  ‡— t          d¦  «        }t          j        j        j        j        rXt          |¦  «        Šˆfd„|D ¦   «         }t          |¦  «        dk    }|sd S t          | j	        ¦  «        }t          ||¦  «        S t          |¦  «        dk    }|sd n|S )Nzmutated inputsc                ó   •— g | ]}|‰v¯|‘Œ	S r0   r0   )ro   rs   Úunique_idxss     €r,   rq   zGcheck_for_mutation_ignore_cuda_graph_managed_tensor.<locals>.<listcomp>œ  s#   ø€ ÐXÐXÐX CÀÈKÐAWÐAW˜CÐAWÐAWÐAWr-   r   )r’   r\   r    r¡   r¢   r£   r   rV   r�   rv   r˜   )	rg   rÖ   rR   r   Údefault_msgr“   Úhas_mutationrQ   rÚ   s	           @r,   Ú3check_for_mutation_ignore_cuda_graph_managed_tensorrÝ   �  s´   ø€ õ .Ð.>Ñ?Ô?€Kõ „ÔÔ$Ô4ð 9Ý Ð!2Ñ3Ô3ˆàXÐXÐXÐXÐ+=ÐXÑXÔXÐÝÐ+Ñ,Ô,°Ò1ˆØð 	Ø�4Ý+¨B¬HÑ5Ô5ˆÝ'¨Ð6FÑGÔGÐGõ ˜>Ñ*Ô*¨aÒ/ˆØ'Ð8ˆtˆt¨[Ð8r-   rl   c                óV   — | j         r| j         S | j        D ]}|j         r	|j         c S ŒdS )zM
    Gets the first non-empty stack trace of a placeholder or its users.
    N)rE   rG   )rl   Úusers     r,   Úget_placeholder_stack_tracerà   ¨  sP   € ð Ôð 'ØÔ&Ð&àÔ!ð $ð $ˆØÔð 	$ØÔ#Ð#Ð#Ð#ð	$ð ˆ4r-   c                  ó&   — e Zd ZdZdZdZdZd	d„ZdS )
ÚCheckInvariantStatusr   é   é   é   r'   rB   c                ór   — | j         dk    rdS | j         dk    rdS | j         dk    rdS | j         › d| j        › �S )NÚCudagraphManagedIdxMismatchz-cudagraph managed tensor data pointer changedÚStaticInputIdxMismatchz!static input data pointer changedÚ&ExpectedDeadIndicesBeforeGraphMismatchz+expected dead indices before graph are livez: )rC   rÓ   )r+   s    r,   Ú__str__zCheckInvariantStatus.__str__Ã  sV   € ØŒ9Ð5Ò5Ð5ØBÐBØŒYÐ2Ò2Ð2Ø6Ð6ØŒYÐBÒBÐBØ@Ð@à”iÐ/Ð/ 4¤:Ð/Ð/Ð/r-   N©r'   rB   )r5   r6   r7   ÚSUCCESSrç   rè   ré   rê   r0   r-   r,   râ   râ   ¶  sE   € € € € € à€Gð #$Ðð Ðð ./Ð*ð0ð 0ð 0ð 0ð 0ð 0r-   râ   Úrecorded_data_ptrúSequence[int | None]Útarget_idxsÚmismatchc                ó  ‡‡— t          ‰¦  «        t          ‰¦  «        k    r t          ‰¦  «        t          | ¦  «        k    s
J d¦   «         ‚ˆfd„|D ¦   «         }ˆfd„|D ¦   «         }|› d�}t          t          ||¦  «        ¦  «        D ]�\  }\  }	}
t          |	t          j        ¦  «        sJ ‚||         }|	                     ¦   «         |
k    r=| |         }|› d|j        › d|
› d|	                     ¦   «         › dt          |¦  «        › d	�
}Œ‚|S )
z}
    Logs the mismatch between input data pointers and recorded data pointers.
    This checks only idxs in target_idxs.
    zClength mismatch between inputs, recorded_data_ptr, and placeholdersc                ó    •— g | ]
}‰|         ‘ŒS r0   r0   )ro   r‹   rš   s     €r,   rq   z)log_data_ptr_mismatch.<locals>.<listcomp>Ý  s   ø€ Ð0Ð0Ð0˜q�˜”Ð0Ð0Ð0r-   c                ó    •— g | ]
}‰|         ‘ŒS r0   r0   )ro   r‹   rí   s     €r,   rq   z)log_data_ptr_mismatch.<locals>.<listcomp>Þ  s   ø€ Ð=Ð=Ð=¨AÐ$ QÔ'Ð=Ð=Ð=r-   z.
zinput name: z. data pointer changed from z to z. input stack trace: ú
)	rV   rx   Úzipr{   r\   ÚTensorÚdata_ptrrC   rà   )rQ   rš   rí   rï   rð   Ú	t_tensorsÚt_data_ptrsÚ	error_msgr‹   Útensorr÷   Úindexrl   s    ``          r,   Úlog_data_ptr_mismatchrý   Î  sj  øø€ õ ˆv‰;Œ;�#Ð/Ñ0Ô0Ò0Ð0µS¸±[´[ÅCÈÑDUÔDUÒ5UÐ5UÐ5UØMñ 6VÔ5UÐUð 1Ð0Ð0Ð0 KÐ0Ñ0Ô0€IØ=Ð=Ð=Ð=°Ð=Ñ=Ô=€KØÐ Ð Ð €IÝ!*­3¨y¸+Ñ+FÔ+FÑ!GÔ!Gð 	ð 	ÑˆÑˆF�HÝ˜&¥%¤,Ñ/Ô/Ð/Ð/Ð/Ø˜A”ˆØ�?Š?ÑÔ Ò(Ð(Ø& uÔ-ˆKàð Sð S¨+Ô*:ð Sð SØ-5ðSð SØ;A¿?º?Ñ;LÔ;LðSð Så&AÀ+Ñ&NÔ&NðSð Sð Sð øð
 Ðr-   Úfn_cacheú)dict[tuple[int, ...], Callable[..., Any]]Únew_int_keyr   r$   c                ó  ‡— t          |                      ¦   «         ¦  «        dz   Šdˆfd„}t          j        j        j        j        rC‰t          j        j        j        j        k    r$t                                |¦   «         ¦  «         dS dS )Nr   r'   rB   c                 ó   •— d‰ › d�S )Nz¤CUDAGraph supports dynamic shapes by recording a new graph for each distinct input size. Recording too many CUDAGraphs may lead to extra overhead. We have observed a0   distinct sizes. Please consider the following options for better performance: a) padding inputs to a few fixed number of shapes; or b) set torch._inductor.config.triton.cudagraph_skip_dynamic_graphs=True. Set torch._inductor.config.triton.cudagraph_dynamic_shape_warn_limit=None to silence this warning.r0   )Únum_cudagraphss   €r,   Úwarn_msgz4maybe_warning_due_to_dynamic_shape.<locals>.warn_msgó  s   ø€ ð'à0>ð'ð 'ð 'ð		
r-   TFrë   )	rV   rµ   r\   r    r¡   r¢   Ú"cudagraph_dynamic_shape_warn_limitrÈ   rÉ   )rþ   r   r  r  s      @r,   Ú"maybe_warning_due_to_dynamic_shaper  í  s•   ø€ õ ˜Ÿš™œÑ)Ô)¨AÑ-€Nð

ð 

ð 

ð 

ð 

ð 

õ 	ŒÔÔ%ÔHðàÝ
Œ/Ô
 Ô
'Ô
JòKð Kõ 	×Ò˜x˜x™zœzÑ*Ô*Ð*Øˆtàˆ5r-   )r9   c                  ó2   — e Zd ZU dZded<   ded<   ded<   dS )	ÚCudagraphCachedInfoz'
    Info needed to realign inputs
    rP   rQ   úlist[str | None]Ústack_tracesz	list[str]Úcudagraph_fail_reasonsNr>   r0   r-   r,   r  r  
  sB   € € € € € € ðð ð ,Ð+Ð+Ñ+Ø"Ð"Ð"Ñ"Ø%Ð%Ð%Ñ%Ð%Ð%r-   r  c                  óF   — e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   dS )ÚCudagraphMetadataz.
    Metadata for recording a CUDA graph.
    rP   rQ   rK   r   rR   r	  r
  zdict[str, torch.Tensor]rO   Nr>   r0   r-   r,   r  r    sZ   € € € € € € ðð ð ,Ð+Ð+Ñ+Ø&Ð&Ð&Ñ&Ø'Ð'Ð'Ñ'Ø"Ð"Ð"Ñ"Ø&Ð&Ð&Ñ&Ð&Ð&r-   r  Úpartition_mapr   Úmetadatac                óF  ‡— g }t          ¦   «         }t          ¦   «         }t          | j        ¦  «        D ]„\  }}|‰j        v r|                     |¦  «         |‰j        v r|                     |¦  «         |�‰j        |         }nt          d| j        › d|› �dg d¬¦  «        }| 	                    |¦  «         Œ…g }| j
        D ]:}	|	�!| 	                    ‰j        |	         ¦  «         Œ%| 	                    d¦  «         Œ;ˆfd„| j        D ¦   «         }
t          |||||
¦  «        S )zÏ
    Convert the cudagraph metadata at the graph level to the graph partition level,
    given the graph partition info (i.e., mapping from partition input/output index
    to graph input/output index).
    NÚ
partition_Ú_placeholder_)rC   rE   rG   rH   c                ó,   •— i | ]}|‰j         |         “ŒS r0   )rO   )ro   rC   r  s     €r,   rt   z4get_partition_cudagraph_metadata.<locals>.<dictcomp>K  s0   ø€ ð ð ð Ø+/ˆˆhÔ  Ô&ðð ð r-   )r   rx   Úinput_index_mappingr   r~   rR   rQ   rA   r=   ÚappendÚoutput_index_mappingr
  Úconstant_namesr  )r  r  Úpartition_placeholdersÚpartition_static_input_idxsÚpartition_mutated_input_idxsÚpartition_input_idxÚgraph_input_idxrl   Úpartition_stack_tracesÚgraph_output_idxÚpartition_constantss    `         r,   Ú get_partition_cudagraph_metadatar   "  s•  ø€ ð  ÐÝ3=±<´<ÐÝ4>±L´LÐ Ý09ØÔ)ñ1ô 1ð 3ð 3Ñ,Ð˜_ð ˜hÔ8Ð8Ð8Ø'×+Ò+Ð,?Ñ@Ô@Ð@à˜hÔ9Ð9Ð9Ø(×,Ò,Ð-@ÑAÔAÐAàÐ&Ø"Ô/°Ô@ˆKˆKõ *ØV -Ô"2ÐVÐVÐATÐVÐVØ ØØ)-ð	ñ ô ˆKð 	×%Ò% kÑ2Ô2Ð2Ð2àÐØ)Ô>ð 0ð 0ÐØÐ'Ø"×)Ò)¨(Ô*?Ð@PÔ*QÑRÔRÐRÐRà"×)Ò)¨$Ñ/Ô/Ð/Ð/ðð ð ð Ø3@Ô3Oðñ ô Ðõ ØØ#Ø$ØØñô ð r-   ÚobjÚobjectc                ó�  — t          | t          j        ¦  «        st          ¦   «         S t          ¦   «         }t	          | g ¬¦  «        D ]}}t          |¦  «        t          j        urŒt          |¦  «        s|j        s|j        j        dk    rŒE	 | 	                    | 
                    ¦   «         ¦  «         Œn# t          $ r Y Œzw xY w|S )zODebug helper that collects the data pointers of all CUDA tensors in the object.)Úoutr®   )r{   r\   rö   r   r   r¶   r   Úis_metar´   r~   r÷   Ú	Exception)r!  ÚptrsÚbases      r,   Úcollect_cuda_data_ptrsr)  X  sË   € å�c�5œ<Ñ(Ô(ð Ý‰|Œ|Ðå&™LœL€DÝ! #¨2Ð.Ñ.Ô.ð ð ˆÝ�‰:Œ:�Uœ\Ð)Ð)ØÝ�4‰=Œ=ð 	˜DœLð 	¨D¬KÔ,<ÀÒ,FÐ,FØð	Ø�HŠH�T—]’]‘_”_Ñ%Ô%Ð%Ð%øÝð 	ð 	ð 	ØˆDð	øøøà€Ks   Â'B6Â6
CÃC)rS   rT   r'   rD   )rc   rA   r'   rD   )rg   rh   r'   rJ   )rƒ   rJ   r'   rD   )rS   rT   r'   rA   )rv   rŒ   r'   rF   )r�   rB   r'   rB   )rQ   rP   r“   r”   r'   rB   )r™   rN   rš   r›   rœ   r�   r'   rD   )rp   rT   r'   rD   )r©   rª   r'   rD   )r'   rD   )r†   rB   r'   rÂ   )
rg   rh   rÖ   r×   rR   rK   r   r    r'   rD   )rl   rA   r'   rD   )rQ   rP   rš   r›   rí   rî   rï   r    rð   râ   r'   rB   )rþ   rÿ   r   r   r'   r$   )r  r   r  r  r'   r  )r!  r"  r'   rK   )PÚ
__future__r   ÚdataclassesÚcollections.abcr   Úenumr   Útypingr   r   r   r\   Útorch._dynamo.utilsr	   r
   Útorch._inductor.utilsr   r   Útorch._subclasses.fake_tensorr   r   Útorch.utils._ordered_setr   Úutilsr   r   r   ÚAbstractSetÚtorch._inductor.output_coder   r   Ú_loggingÚgetArtifactLoggerr5   rÈ   r¤   Úlistr"   rö   Ú
OutputTypeÚ	ModelTyper]   r^   Úset_r`   Úsource_StorageÚsource_Storage_storage_offsetÚsource_TensorÚsource_Tensor_storage_offsetry   r   Ú	dataclassr<   rA   rJ   rN   rb   rf   r‚   r‡   rŠ   r�   r’   r˜   r¦   r¨   rº   r¿   rÁ   rÏ   rÑ   rÝ   rà   râ   rý   r  r  r  r   r)  r0   r-   r,   ú<module>rA     s¶  ðà "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø $Ð $Ð $Ð $Ð $Ð $Ø Ð Ð Ð Ð Ð Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ð .à €€€Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø >Ð >Ð >Ð >Ð >Ð >Ð >Ð >Ø DÐ DÐ DÐ DÐ DÐ DÐ DÐ DØ /Ð /Ð /Ð /Ð /Ð /à /Ð /Ð /Ð /Ð /Ð /ð ð 7Ø<Ð<Ð<Ð<Ð<Ð<Ð<Ð<à6Ð6Ð6Ð6Ð6Ð6à€gˆe˜<Ð(Ñ(Ô(€ð ”×1Ò1°(¸LÑIÔI€Ø”N×4Ò4ØÐ'ñô Ð ð
 �#˜œÑ$ tÑ+Ô,€
Ø�d˜9”oÐ&¨
Ð2Ô3€	ð 
„I„NÔÔØ	„I„NÔÔ&Ø	„I„NÔÔ5Ø	„I„NÔÔ%Ø	„I„NÔÔ4ð"Ð ðTð Tð Tð Tð Tñ Tô Tð Tðn €Ô˜d¨$Ð/Ñ/Ô/ðð ð ð ð ñ ô ñ 0Ô/ðð €Ô˜d¨$Ð/Ñ/Ô/ð)ð )ð )ð )ð )ñ )ô )ñ 0Ô/ð)ð €Ô˜d¨$Ð/Ñ/Ô/ðð ð ð ð ñ ô ñ 0Ô/ðð
 €Ô˜d¨$Ð/Ñ/Ô/ð&ð &ð &ð &ð &ñ &ô &ñ 0Ô/ð&ðð ð ð ð5ð 5ð 5ð 5ðNð Nð Nð Nð<ð ð ð ðOð Oð Oð Oðð ð ð ð2ð 2ð 2ð 2ðð ð ð ð(ð ð ð ð>ð ð ð ðTð Tð Tð Tð8ð ð ð ð(ð ð ð ð	Jð 	Jð 	Jð 	Jð Ôð ð  ð  ð  ð  ñ  ô  ñ Ôð ð9ð 9ð 9ð 9ð0ð ð ð ð0ð 0ð 0ð 0ð 0˜4ñ 0ô 0ð 0ð0ð ð ð ð>ð ð ð ð: €Ô˜dÐ#Ñ#Ô#ð&ð &ð &ð &ð &ñ &ô &ñ $Ô#ð&ð €Ô˜dÐ#Ñ#Ô#ð	'ð 	'ð 	'ð 	'ð 	'ñ 	'ô 	'ñ $Ô#ð	'ð3ð 3ð 3ð 3ðlð ð ð ð ð r-   