Ë
    ÿÍ:j
  ã                   ó¢   — 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mZmZ d dlmZ deddfd	„Zded
   ddfd„Zdeddfd„Zdddeddfd„Zy)é    )ÚUnionN)ÚOptimizedModule)ÚDDPStrategyÚDeepSpeedStrategyÚFSDPStrategyÚSingleDeviceStrategyÚStrategy)Ú_check_mixed_importsÚmodelÚreturnúpl.LightningModulec                 óæ  — t        | t        «      s"t        dt        | «      j                  › d�«      ‚| j
                  }t        |t        j                  «      s-t        | «       t        dt        |«      j                  › d�«      ‚d| j                  |j                  |j                  |j                  |j                  |j                  dœ|_        | j                  |j                  «      |_
        | j                  |j                  «      |_        | j                  |j                  «      |_        | j                  |j                  «      |_        | j                  |j                  «      |_        |S )aZ  Returns an instance LightningModule from the output of ``torch.compile``.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    The ``torch.compile`` function returns a ``torch._dynamo.OptimizedModule``, which wraps the LightningModule
    passed in as an argument, but doesn't inherit from it. This means that the output of ``torch.compile`` behaves
    like a LightningModule, but it doesn't inherit from it (i.e. `isinstance` will fail).

    Use this method to obtain a LightningModule that still runs with all the optimizations from ``torch.compile``.

    z8`model` is required to be a `OptimizedModule`. Found a `z
` instead.z?`model` is expected to be a compiled LightningModule. Found a `z	` insteadÚdynamo)ÚcompilerÚ
dynamo_ctxÚoriginal_forwardÚoriginal_training_stepÚoriginal_validation_stepÚoriginal_test_stepÚoriginal_predict_step)Ú
isinstancer   Ú
ValueErrorÚtypeÚ__name__Ú	_orig_modÚplÚLightningModuler
   r   ÚforwardÚtraining_stepÚvalidation_stepÚ	test_stepÚpredict_stepÚ_compiler_ctx)r   Úorig_modules     úx/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/lightning/pytorch/utilities/compile.pyÚfrom_compiledr&      sD  € ô �eœ_Ô-ÜÐSÔTXÐY^ÓT_×ThÑThÐSiÐisÐtÓuÐuà—/‘/€Kä�k¤2×#5Ñ#5Ô6Ü˜UÔ#ÜØMÌdÐS^ÓN_×NhÑNhÐMiÐirÐsó
ð 	
ð
 Ø×&Ñ&Ø'×/Ñ/Ø"-×";Ñ";Ø$/×$?Ñ$?Ø)×3Ñ3Ø!,×!9Ñ!9ñ!€KÔð  ×*Ñ*¨;×+>Ñ+>Ó?€KÔØ %× 0Ñ 0°×1JÑ1JÓ K€KÔØ"'×"2Ñ"2°;×3NÑ3NÓ"O€KÔØ!×,Ñ,¨[×-BÑ-BÓC€KÔØ$×/Ñ/°×0HÑ0HÓI€KÔØÐó    )r   ztorch._dynamo.OptimizedModulec                 óÀ  — t        | t        «      rG| j                  }t        |t        j                  «      s`t        dt        | «      j                  › �«      ‚t        | t        j                  «      r| j                  €t        d«      ‚| }nt        d«      ‚|j                  }|�9|d   |_
        |d   |_        |d   |_        |d   |_        |d	   |_        d|_        |S )
a°  Returns an instance of LightningModule without any compilation optimizations from a compiled model.

    .. warning::  This is an :ref:`experimental <versioning:Experimental API>` feature.

    This takes either a ``torch._dynamo.OptimizedModule`` returned by ``torch.compile()`` or a ``LightningModule``
    returned by ``from_compiled``.

    Note: this method will in-place modify the ``LightningModule`` that is passed in.

    zGUnexpected error, the wrapped model should be a LightningModule, found Nzc`model` is required to be a compiled LightningModule. Found a non-compiled LightningModule instead.zH`model` must either be an instance of OptimizedModule or LightningModuler   r   r   r   r   )r   r   r   r   r   Ú	TypeErrorr   r   r#   r   r   r   r    r!   r"   )r   ÚoriginalÚctxs      r%   Úto_uncompiledr,   A   sò   € ô �%œÔ)Ø—?‘?ˆÜ˜(¤B×$6Ñ$6Ô7ÜØYÔZ^Ð_dÓZe×ZnÑZnÐYoÐpóð ô 
�Eœ2×-Ñ-Ô	.Ø×ÑÐ&ÜØuóð ð ‰ô ÐcÓdÐdà
×
 Ñ
 €CØ
€ØÐ1Ñ2ˆÔØ!$Ð%=Ñ!>ˆÔØ#&Ð'AÑ#BˆÔ Ø Ð!5Ñ6ˆÔØ #Ð$;Ñ <ˆÔØ!%ˆÔà€Or'   c                 óÊ   — t        | t        «      rt        | «      S t        | t        j                  «      r| S t        | «       t        dt        | «      j                  › d�«      ‚)NzM`model` must be a `LightningModule` or `torch._dynamo.OptimizedModule`, got `ú`)	r   r   r&   r   r   r
   r)   r   Ú__qualname__)r   s    r%   Ú_maybe_unwrap_optimizedr0   i   s\   € Ü�%œÔ)Ü˜UÓ#Ð#Ü�%œ×+Ñ+Ô,ØˆÜ˜ÔÜ
Ø
WÔX\Ð]bÓXc×XpÑXpÐWqÐqrÐsóð r'   Ústrategyc                 óò   — | j                   �kt        t        t        f}t	        ||«      rt	        |t
        «      r=dj                  d„ |D «       «      }t        dt        |«      j                  › d|› d�«      ‚y y )Nz, c              3   ó4   K  — | ]  }|j                   –— Œ y ­w)N)r   )Ú.0Úss     r%   ú	<genexpr>z4_verify_strategy_supports_compile.<locals>.<genexpr>x   s   è ø€ Ò0ZÀ°·µÑ0Zùs   ‚zCUsing a compiled model is incompatible with the current strategy: `z`. Only zj support compilation. Either switch to one of the supported strategies or avoid passing in compiled model.)
r#   r   r   r   r   r   ÚjoinÚRuntimeErrorr   r   )r   r1   Úsupported_strategiesÚsupported_strategy_namess       r%   Ú!_verify_strategy_supports_compiler;   t   s‹   € Ø×ÑÐ&Ü 4´kÄ<ÐPÐÜ˜(Ð$8Ô9¼ZÈÔRcÔ=dØ'+§y¡yÑ0ZÐEYÔ0ZÓ'ZÐ$ÜØUÔVZÐ[cÓVd×VmÑVmÐUnð oØ1Ð2ð 3BðBóð ð >eð 'r'   )Útypingr   ÚtorchÚtorch._dynamor   Úlightning.pytorchÚpytorchr   Úlightning.pytorch.strategiesr   r   r   r   r	   Ú)lightning.pytorch.utilities.model_helpersr
   r&   r,   Úobjectr0   r;   © r'   r%   ú<module>rE      s|   ðõ ã Ý )å ß uÕ uÝ Jð&˜ð &Ð-Aó &ðR%˜ÐTÑUð %ÐZnó %ðP 6ð Ð.Bó ð	Ð-Að 	ÈXð 	ÐZ^ô 	r'   