Ë
    ÄÓ^jsS  ã                  ó"  — 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>                  jA                  e!d«      Z"ej>                  jA                  e!d«      Z#e$e%ejL                  z  dz     Z'ee$e   ge'f   Z(ejR                  jT                  jV                  jX                  ejR                  jT                  jV                  jZ                  ejR                  jT                  jV                  j\                  ejR                  jT                  jV                  j^                  ejR                  jT                  jV                  j`                  fZ1 G d„ d«      Z2 ejf                  dd¬«       G d„ d«      «       Z4 ejf                  dd¬«       G d„ d«      «       Z5 ejf                  dd¬«       G d„ d«      «       Z6 ejf                  dd¬«       G d„ d«      «       Z7	 	 	 	 d<d„Z8d=d „Z9	 	 	 	 d>d!„Z:	 	 	 	 d?d"„Z;d@d#„Z<dAd$„Z=dBd%„Z>	 	 	 	 	 	 dCd&„Z?	 	 	 	 	 	 	 	 dDd'„Z@dEd(„ZA	 	 	 	 dFd)„ZBdGd*„ZC	 	 	 	 dFd+„ZDdHd,„ZEejf                   G d-„ d.«      «       ZF	 	 	 	 	 	 	 	 	 	 dId/„ZGdJd0„ZH G d1„ d2e«      ZI	 	 	 	 	 	 	 	 	 	 	 	 dKd3„ZJ	 	 	 	 	 	 dLd4„ZK ejf                  d¬5«       G d6„ d7«      «       ZL ejf                  d¬5«       G d8„ d9«      «       ZM	 	 	 	 	 	 dMd:„ZNdNd;„ZOy)Oé    )Ú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                  óH   — e Zd ZdZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zy)	Ú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(...)
    c               ó*   — 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)Údevice_indexÚis_backwardÚis_inference)Útorch._inductor.compile_fxr   )	ÚselfÚmodelÚexample_inputsÚstatic_input_idxsr   r   r   Úkwargsr   s	            új/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/torch/_inductor/cudagraph_utils.pyr   zCUDAGraphPolicy.cudagraphifyC   s4   € õ: 	<áØØð
ð &Ø#Ø%ñ
ð ñ
ð 	
ó    c                 ó   — y)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!   Úcompiled_graphs     r&   Úshould_wrapzCUDAGraphPolicy.should_wrapk   s   € ð r'   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).
        r)   )r!   Úoutput_codes     r&   Úwrap_outputzCUDAGraphPolicy.wrap_outputv   s
   € ð Ðr'   N)r"   úCallable[..., Any]r#   zSequence[InputType]r$   úSequence[int]r   Úintr   Úboolr   r2   r%   r   Úreturnr/   )r*   r   r3   r2   )r-   r   r3   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r+   r.   r)   r'   r&   r   r   -   se   „ ñð*&
à!ð&
ð ,ð&
ð )ð	&
ð ð&
ð ð&
ð ð&
ð ð&
ð 
ó&
óP	ôr'   r   T)ÚfrozenÚslotsc                  ó   — e Zd ZU dZded<   y)Ú
FunctionIDz9Unique counter of a function wrapped in cudagraphify_implr1   ÚidN©r4   r5   r6   r7   Ú__annotations__r)   r'   r&   r;   r;   „   s
   … á?à„Gr'   r;   c                  ó:   — e Zd ZU dZded<   ded<   ded<   ded<   y	)
Ú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=   r)   r'   r&   r@   r@   ‹   s    … ñð ƒIØÓà Ó Ø(Ô(r'   r@   c                  ó"   — e Zd ZU ded<   ded<   y)ÚInputStorageMutationInfoúOrderedSet[int]Ú
input_idxsrC   rD   N)r4   r5   r6   r>   r)   r'   r&   rI   rI   š   s   … àÓØÔr'   rI   c                  óN   — 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<   y)Ú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"   r0   r$   r;   r<   ztuple[torch.Tensor, ...]Ú	constantsúSequence[PlaceholderInfo]ÚplaceholdersÚmutated_input_idxsNr=   r)   r'   r&   rM   rM       s,   … ñð ÓØ$Ó$ØƒNØ'Ó'Ø+Ó+Ø%Ô%r'   rM   c                ó€  — t        | j                  «      dk(  r8t        t        | j                  «      «      j                  j                  dd «      S | j                  D ]_  }|j                  t        j                  j                  j                  j                  u sŒ>|j                  j                  dd «      x}sŒ]|c S  y )Nr   rD   )ÚlenrF   ÚnextÚiterÚmetaÚgetÚtargetÚtorchÚopsÚatenÚcopy_Údefault)Úplaceholder_nodeÚuserD   s      r&   Ú&get_mutating_use_stack_trace_from_noder`   °   sœ   € ô Ð×!Ñ!Ó" aÒ'Ü”DÐ)×/Ñ/Ó0Ó1×6Ñ6×:Ñ:¸=È$ÓOÐOà×%Ñ%ò #ˆØ�:‰:œŸ™Ÿ™×-Ñ-×5Ñ5Ò5Ø!Ÿh™hŸl™l¨=¸$Ó?Ð?ˆ{Ñ?Ø"Ò"ð#ð
 r'   c                ó   — | j                   S ©N)rG   )Úplaceholder_infos    r&   Úget_mutating_use_stack_tracerd   ¿   s   € Ø×4Ñ4Ð4r'   c                óX  — | j                   j                  D �cg c]  }|j                  dk(  sŒ|‘Œ }}t        |«      D ��ci c]  \  }}||“Œ
 }}}t	        «       }d }| j                   j                  D ]ž  }|j                  dk7  s|j
                  t        vrŒ%|j                  r|j                  d   nd }t        |t        j                  j                  «      sŒg||v sŒl|j                  ||   «       |�Œƒ|j                  j                  dd «      }Œ  t        ||«      S c c}w c c}}w )NÚplaceholderÚcall_functionr   rD   )ÚgraphÚnodesÚopÚ	enumerater   rX   ÚINPUT_STORAGE_MUTATION_TARGETSÚargsÚ
isinstancerY   ÚfxÚNodeÚaddrV   rW   rI   )ÚgmÚnoderP   ÚidxÚplaceholder_indicesÚstorage_mutation_input_idxsrD   Úmutated_args           r&   Úget_input_storage_mutation_inforx   Ã   s  € ð &(§X¡X§^¡^ÖP˜T°t·w±wÀ-Ó7O’DÐP€LÐPÜ6?ÀÓ6M×N©¨¨d˜4 ™9ÐNÐÑNÜ3=³<ÐØ"€Kà—‘—‘ò Aˆà�G‰G�Ò&Ø�{‰{Ô"@Ñ@àà&*§i¢i�d—i‘i ’l°Tˆô
 �{¤E§H¡H§M¡MÕ2ØÐ2Ò2à'×+Ñ+Ð,?ÀÑ,LÔMØÑ"Ø"Ÿi™iŸm™m¨M¸4Ó@‘ð#Aô& $Ð$?ÀÓMÐMùò1 QùÛNs   ™D!®D!ÁD&c                ó|   — | j                   }|sy dt        |«      › d�}| j                  r|› d| j                  › �S |S )Nzinput storage mutation (ú instances)z. Found from:
 )rK   rS   rD   )Ústorage_mutation_inforv   Úmsgs      r&   Ú!get_input_storage_mutation_reasonr}   á   sS   € ð #8×"BÑ"BÐÙ&Øà$¤SÐ)DÓ%EÐ$FÀkÐ
R€CØ×(Ò(Ø�Ð&Ð'<×'HÑ'HÐ&IÐJÐJà€Jr'   c                óø   — | j                   }| j                  j                  dd «      }g }d }| j                  dk(  r-| j                  D �cg c]  }t        |«      ‘Œ }}t        | «      }t        ||||«      S c c}w )NrD   rf   )rB   rV   rW   rj   rF   Úto_placeholder_infor`   r@   )r^   rB   rD   rF   rG   Úis         r&   r   r   ï   s…   € Ø× Ñ €DØ"×'Ñ'×+Ñ+¨M¸4Ó@€KØ€EØ#Ðà×Ñ˜mÒ+Ø1A×1GÑ1GÖH¨AÔ$ QÕ'ÐHˆÐHÜ#IØó$
Ð ô ˜4 ¨eÐ5MÓNÐNùò Is   Á
A7c                ór   — | j                   D �cg c]  }|j                  dk(  sŒt        |«      ‘Œ c}S c c}w )Nrf   )ri   rj   r   )rh   rs   s     r&   Úget_placeholder_infor‚   þ   s4   € à.3¯k©köØ&*¸T¿W¹WÈÓ=UÔ˜DÕ!òð ùò s   �4¤4c                ó   — d| › �S )Nzskipping cudagraphs due to r)   )Úreasons    r&   Úformat_default_skip_messager…     s   € Ø(¨¨Ð1Ð1r'   c                ó‚   — d}|D ]  }| |   }t        |«      x}sŒ n t        dt        |«      › d�«      }|r|› d|› �S |S )NÚ zmutated inputs (rz   ú. Found from : 
 )rd   r…   rS   )rP   Úmutation_indicesrD   rt   rf   r|   s         r&   Úget_mutation_stack_tracerŠ     sp   € ð !€Kàò ˆØ" 3Ñ'ˆÜ6°{ÓCÐCˆ;ÑCÙðô
 &Ø
œ3Ð/Ó0Ð1°Ð=ó€Cñ Ø�Ð(¨¨Ð6Ð6à€Jr'   c                ó†  — t         j                  j                  j                  j                  r3| j
                  D �cg c]  }|| j                  v s |||   «      s|‘Œ }}n| j
                  }t        j                  d| j                  «       t        j                  d|«       |rt        | j                  |«      S d S c c}w )Nz'check mutation static input indices: %szcheck mutation indices: %s)rY   Ú	_inductorÚconfigÚtritonÚcudagraph_treesrQ   r$   Ústatic_inputs_logÚdebugrŠ   rP   )ÚfuncÚinputsÚis_cuda_graph_recorded_tensorrt   r‰   s        r&   Úcheck_for_mutationr•     sÄ   € ô ‡�×Ñ×$Ñ$×4Ò4ð ×.Ñ.ö+
àà�t×-Ñ-Ñ-Ù0°¸±Ô=ò	 ð+
Ðñ +
ð  ×2Ñ2Ðä×ÑØ1°4×3IÑ3Iôô ×ÑÐ8Ð:JÔKñ ô 	! ×!2Ñ!2Ð4DÓEðð ðùò!+
s   ½"B>c                ój   — | j                   D ]$  }|j                  j                  dd «      x}sŒ"|c S  y )NrD   )rF   rV   rW   )rs   r_   rD   s      r&   Ú_get_use_stack_tracer—   ;  s:   € Ø�z‰zò ˆØŸ(™(Ÿ,™, }°dÓ;Ð;ˆ;Ñ;ØÒðð r'   c                ó.  — | j                  t        j                  d«      d «       t        «       r%| j                  t        j                  d«      d «       | j	                  t        j                  d«      «      x}r8d|j
                  › d�}t        |«      x}rt        |› d|› �«      S t        |«      S t        | «      dk(  r0t        t        | j                  «       «      «      j                  dk(  ry d„ | D «       }t        d	d
j                  |«      › �«      S )NrV   Úcpuzcpu device (ú)rˆ   r   Úcudac              3  ó2   K  — | ]  }t        |«      –— Œ y ­wrb   )Úrepr)Ú.0Úkeys     r&   ú	<genexpr>z:check_multiple_devices_or_any_cpu_nodes.<locals>.<genexpr>Z  s   è ø€ Ò:˜s”�c—Ñ:ùs   ‚zmultiple devices: z, )ÚpoprY   Údevicer   rW   rB   r—   r…   rS   rT   rU   ÚkeysÚtypeÚjoin)Údevice_node_mappingÚcpu_noder|   rD   Ú	keys_reprs        r&   Ú'check_multiple_devices_or_any_cpu_nodesr©   B  sþ   € ð ×ÑœEŸL™L¨Ó0°$Ô7ô $Ô%à×Ñ¤§¡¨UÓ 3°TÔ:à&×*Ñ*¬5¯<©<¸Ó+>Ó?Ð?€xÐ?Ø˜XŸ]™]˜O¨1Ð-ˆÜ.¨xÓ8Ð8ˆ;Ð8Ü.°#°Ð6HÈÈÐ/VÓWÐWä*¨3Ó/Ð/ô 	ÐÓ  AÒ%Ü”Ð)×.Ñ.Ó0Ó1Ó2×7Ñ7¸6ÒAàá:Ð&9Ô:€IÜ&Ð);¸D¿I¹IÀiÓ<PÐ;QÐ'RÓSÐSr'   c                 ó’   — t         j                  j                  «       r)t         j                  j	                  «       st        d«      S y)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)rY   r›   Úis_availableÚ_CÚ%_cuda_cudaCachingAllocator_is_enabledr…   r)   r'   r&   Ú&check_caching_allocator_for_cudagraphsr®   ^  s;   € ô 	�
‰
×ÑÔ!ä—‘×>Ñ>Ô@ä*ð,ó
ð 	
ð r'   c                ó0   — t        «       xs t        | «      S rb   )r®   r©   )r¦   s    r&   Ú check_lowering_disable_cudagraphr°   r  s   € ô 	/Ó0ò 	HÜ2Ð3FÓGðr'   c                ó&  — t         j                  | «       t        d   dxx   dz  cc<   t        j                  j
                  j                  j                  rt        | «      ‚t        «       }|j                  «       r|j                  d| d¬«       y y )NÚinductorÚcudagraph_skipsr   Úcudagraph_skip_reasonT)Ú	overwrite)Úcudagraphs_logÚwarningr	   rY   rŒ   r�   rŽ   Úcudagraph_or_errorÚRuntimeErrorr
   Úin_progressÚset)r|   Úmetrics_contexts     r&   Ú#log_cudagraph_skip_and_bump_counterr½   {  sy   € Ü×Ñ˜3ÔÜˆZÑÐ*Ó+¨qÑ0Ó+ä‡�×Ñ×$Ñ$×7Ò7Ü˜3ÓÐä)Ó+€OØ×"Ñ"Ô$Ø×ÑÐ3°SÀDÐÕIð %r'   c                  ó    — e Zd ZU ded<   dd„Zy)ÚBoxedDeviceIndexú
int | NoneÚvaluec                ó:   — |�t        |t        «      sJ ‚|| _        y rb   )rn   r1   rÁ   )r!   Ú
device_idxs     r&   r»   zBoxedDeviceIndex.set‹  s   € ØÐ!¤Z°
¼CÔ%@Ð@Ð@Øˆ�
r'   N)rÃ   rÀ   r3   ÚNone)r4   r5   r6   r>   r»   r)   r'   r&   r¿   r¿   ‡  s   … àÓô r'   r¿   c                óH  — t        d«      }t        j                  j                  j                  j
                  rQt        |«      }|D �cg c]	  }||vsŒ|‘Œ }}t        |«      dk7  }|sy t        | j                  «      }	t        |	|«      S t        |«      dk7  }|sd S |S c c}w )Nzmutated inputsr   )r…   rY   rŒ   r�   rŽ   r�   r   rS   r‚   rh   rŠ   )
rr   Úmutated_inputsrQ   r$   Údefault_msgÚunique_idxsrt   r‰   Úhas_mutationrP   s
             r&   Ú3check_for_mutation_ignore_cuda_graph_managed_tensorrÊ   �  s¦   € ô .Ð.>Ó?€Kô ‡�×Ñ×$Ñ$×4Ò4Ü Ð!2Ó3ˆà+=ÖX CÀÈKÒAWšCÐXÐÐXÜÐ+Ó,°Ñ1ˆÙØÜ+¨B¯H©HÓ5ˆÜ'¨Ð6FÓGÐGô ˜>Ó*¨aÑ/ˆÙ'ˆtÐ8¨[Ð8ùò Ys   Á		BÁBc                óŠ   — | j                   r| j                   S | j                  D ]  }|j                   sŒ|j                   c S  y)zM
    Gets the first non-empty stack trace of a placeholder or its users.
    N)rD   rF   )rf   Úusers     r&   Úget_placeholder_stack_tracerÍ   ¨  sH   € ð ×ÒØ×&Ñ&Ð&à×!Ñ!ò $ˆØ×ÓØ×#Ñ#Ò#ð$ð r'   c                  ó$   — e Zd ZdZdZdZdZdd„Zy)ÚCheckInvariantStatusr   é   é   é   c                ó˜   — | j                   dk(  ry| j                   dk(  ry| j                   dk(  ry| 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: )rB   rÁ   )r!   s    r&   Ú__str__zCheckInvariantStatus.__str__Ã  sK   € Ø�9‰9Ð5Ò5ØBØ�Y‰YÐ2Ò2Ø6Ø�Y‰YÐBÒBØ@à—i‘i�[  4§:¡: ,Ð/Ð/r'   N©r3   rA   )r4   r5   r6   ÚSUCCESSrÔ   rÕ   rÖ   r×   r)   r'   r&   rÏ   rÏ   ¶  s$   „ à€Gð #$Ðð Ðð ./Ð*ô0r'   rÏ   c                óî  — t        |«      t        |«      k(  rt        |«      t        | «      k(  sJ d«       ‚|D �cg c]  }||   ‘Œ	 }}|D �cg c]  }||   ‘Œ	 }}|› d�}t        t        ||«      «      D ]t  \  }\  }	}
t        |	t        j
                  «      sJ ‚||   }|	j                  «       |
k7  sŒ>| |   }|› d|j                  › d|
› d|	j                  «       › dt        |«      › d�
}Œv |S c c}w c c}w )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 placeholdersz.
zinput name: z. data pointer changed from z to z. input stack trace: ú
)	rS   rk   Úziprn   rY   ÚTensorÚdata_ptrrB   rÍ   )rP   r“   Úrecorded_data_ptrÚtarget_idxsÚmismatchr€   Ú	t_tensorsÚt_data_ptrsÚ	error_msgÚtensorrÞ   Úindexrf   s                r&   Úlog_data_ptr_mismatchrç   Î  s'  € ô ˆv‹;œ#Ð/Ó0Ò0´S¸³[ÄCÈÓDUÒ5Uð ØMóÐUð %0Ö0˜q�˜“Ð0€IÐ0Ø1<Ö=¨AÐ$ QÓ'Ð=€KÐ=Ø�*˜CÐ €IÜ!*¬3¨y¸+Ó+FÓ!Gò 	ÑˆÑˆF�HÜ˜&¤%§,¡,Ô/Ð/Ð/Ø˜A‘ˆØ�?‰?Ó Ó(Ø& uÑ-ˆKà�+˜\¨+×*:Ñ*:Ð);ð <-Ø-5¨J°d¸6¿?¹?Ó;LÐ:Mð N&Ü&AÀ+Ó&NÐ%OÈrðSñ ð	ð Ðùò 1ùÚ=s   ºC-ÁC2c                ó>  ‡— t        | j                  «       «      dz   Šdˆfd„}t        j                  j                  j
                  j                  rL‰t        j                  j                  j
                  j                  kD  rt        j                   |«       «       yy)Nr   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.r)   )Únum_cudagraphss   €r&   Úwarn_msgz4maybe_warning_due_to_dynamic_shape.<locals>.warn_msgó  s   ø€ ð0à0>Ð/?ð @'ð'ð		
r'   TFrØ   )	rS   r£   rY   rŒ   r�   rŽ   Ú"cudagraph_dynamic_shape_warn_limitr¶   r·   )Úfn_cacheÚnew_int_keyrë   rê   s      @r&   Ú"maybe_warning_due_to_dynamic_shaperï   í  st   ø€ ô ˜Ÿ™›Ó)¨AÑ-€Nõ

ô 	�‰×Ñ×%Ñ%×HÒHØÜ
�/‰/×
 Ñ
 ×
'Ñ
'×
JÑ
JòKô 	×Ñ™x›zÔ*Øàr'   )r8   c                  ó0   — e Zd ZU dZded<   ded<   ded<   y)	ÚCudagraphCachedInfoz'
    Info needed to realign inputs
    rO   rP   úlist[str | None]Ústack_tracesz	list[str]Úcudagraph_fail_reasonsNr=   r)   r'   r&   rñ   rñ   
  s   … ñð ,Ó+Ø"Ó"Ø%Ô%r'   rñ   c                  óD   — e Zd ZU dZded<   ded<   ded<   ded<   d	ed
<   y)ÚCudagraphMetadataz.
    Metadata for recording a CUDA graph.
    rO   rP   rJ   r$   rQ   rò   ró   zdict[str, torch.Tensor]rN   Nr=   r)   r'   r&   rö   rö     s'   … ñð ,Ó+Ø&Ó&Ø'Ó'Ø"Ó"Ø&Ô&r'   rö   c                óh  — g }t        «       }t        «       }t        | j                  «      D ]…  \  }}||j                  v r|j	                  |«       ||j
                  v r|j	                  |«       |�|j                  |   }nt        d| j                  › d|› �dg d¬«      }|j                  |«       Œ‡ g }| j                  D ]4  }	|	�|j                  |j                  |	   «       Œ$|j                  d«       Œ6 | j                  D �
ci c]  }
|
|j                  |
   “Œ }}
t        |||||«      S c c}
w )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_)rB   rD   rF   rG   )r   rk   Úinput_index_mappingr$   rq   rQ   rP   r@   r<   ÚappendÚoutput_index_mappingró   Úconstant_namesrN   rö   )Úpartition_mapÚmetadataÚpartition_placeholdersÚpartition_static_input_idxsÚpartition_mutated_input_idxsÚpartition_input_idxÚgraph_input_idxrf   Úpartition_stack_tracesÚgraph_output_idxrB   Úpartition_constantss               r&   Ú get_partition_cudagraph_metadatar  "  sp  € ð  ÐÜ3=³<ÐÜ4>³LÐ Ü09Ø×)Ñ)ó1ò 3Ñ,Ð˜_ð ˜h×8Ñ8Ñ8Ø'×+Ñ+Ð,?Ô@à˜h×9Ñ9Ñ9Ø(×,Ñ,Ð-@ÔAàÐ&Ø"×/Ñ/°Ñ@‰Kô *Ø! -×"2Ñ"2Ð!3°=ÐATÐ@UÐVØ ØØ)-ô	ˆKð 	×%Ñ% kÕ2ð'3ð*  ÐØ)×>Ñ>ò 0ÐØÐ'Ø"×)Ñ)¨(×*?Ñ*?Ð@PÑ*QÕRà"×)Ñ)¨$Õ/ð	0ð 4A×3OÑ3OöØ+/ˆˆh× Ñ  Ñ&Ñ&ðÐð ô ØØ#Ø$ØØóð ùò	s   ÄD/c                ó~  — t        | t        j                  «      s
t        «       S t        «       }t	        | g ¬«      D ]o  }t        |«      t        j                  urŒt        |«      s%|j                  s|j                  j
                  dk7  rŒP	 |j                  |j                  «       «       Œq |S # t        $ r Y Œw xY w)zODebug helper that collects the data pointers of all CUDA tensors in the object.)Úoutr›   )rn   rY   rÝ   r   r   r¤   r   Úis_metar¢   rq   rÞ   Ú	Exception)ÚobjÚptrsÚbases      r&   Úcollect_cuda_data_ptrsr  X  s›   € ä�cœ5Ÿ<™<Ô(Ü‹|Ðä&›L€DÜ! #¨2Ô.ò ˆÜ�‹:œUŸ\™\Ñ)ØÜ�4Œ=˜DŸLšL¨D¯K©K×,<Ñ,<ÀÒ,FØð	Ø�H‰H�T—]‘]“_Õ%ðð €Køô ò 	Ùð	ús   ÂB0Â0	B<Â;B<)r^   útorch.fx.Noder3   rC   )rc   r@   r3   rC   )rr   útorch.fx.GraphModuler3   rI   )r{   rI   r3   rC   )r^   r  r3   r@   )rh   ztorch.fx.Graphr3   rE   )r„   rA   r3   rA   )rP   rO   r‰   z AbstractSet[int] | Sequence[int]r3   rA   )r’   rM   r“   úlist[InputType]r”   zCallable[[torch.Tensor], bool]r3   rC   )rs   r  r3   rC   )r¦   z!dict[torch.device, torch.fx.Node]r3   rC   )r3   rC   )r|   rA   r3   rÄ   )
rr   r  rÆ   zOrderedSet[str]rQ   rJ   r$   r0   r3   rC   )rf   r@   r3   rC   )rP   rO   r“   r  rß   zSequence[int | None]rà   r0   rá   rÏ   r3   rA   )rí   z)dict[tuple[int, ...], Callable[..., Any]]rî   r   r3   r2   )rþ   r   rÿ   rö   r3   rö   )r  Úobjectr3   rJ   )PÚ
__future__r   ÚdataclassesÚcollections.abcr   Úenumr   Útypingr   r   r   rY   Ú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ÚgetArtifactLoggerr4   r¶   r�   Úlistr1   rÝ   Ú
OutputTypeÚ	ModelTyperZ   r[   Úset_r]   Úsource_StorageÚsource_Storage_storage_offsetÚsource_TensorÚsource_Tensor_storage_offsetrl   r   Ú	dataclassr;   r@   rI   rM   r`   rd   rx   r}   r   r‚   r…   rŠ   r•   r—   r©   r®   r°   r½   r¿   rÊ   rÍ   rÏ   rç   rï   rñ   rö   r  r  r)   r'   r&   ú<module>r,     sÚ  ðå "ã Ý $Ý ß .Ñ .ã ß =ß >ß DÝ /å /ñ ß<å6áˆe˜<Ô(€ð —‘×1Ñ1°(¸LÓI€Ø—N‘N×4Ñ4ØÐ'óÐ ð
 �#˜Ÿ™Ñ$ tÑ+Ñ,€
Ø�d˜9‘oÐ&¨
Ð2Ñ3€	ð 
‡I�I‡N�N×Ñ×ÑØ	‡I�I‡N�N×Ñ×&Ñ&Ø	‡I�I‡N�N×Ñ×5Ñ5Ø	‡I�I‡N�N×Ñ×%Ñ%Ø	‡I�I‡N�N×Ñ×4Ñ4ð"Ð ÷Tñ Tðn €×Ñ˜d¨$Ô/÷ð ó 0ðð €×Ñ˜d¨$Ô/÷)ð )ó 0ð)ð €×Ñ˜d¨$Ô/÷ð ó 0ðð
 €×Ñ˜d¨$Ô/÷&ð &ó 0ð&ðØ#ðàóó5ðNØðNàóNð<Ø3ðàóóOóó2ðØ+ðà6ðð 	óð(Ø
ðàðð $Bðð ó	ó>ðTØ:ðTàóTó8ð(Ø:ðàóó	Jð ×Ñ÷ ð  ó ð ð9Øð9à#ð9ð (ð9ð %ð	9ð
 ó9ó0ô0˜4ô 0ð0Ø+ðàðð ,ðð ð	ð
 #ðð 	óð>Ø7ðàðð 
óð: €×Ñ˜dÔ#÷&ð &ó $ð&ð €×Ñ˜dÔ#÷	'ð 	'ó $ð	'ð3Ø$ð3àð3ð ó3ôlr'   