§
    “©ºj
  ã                   ó¦   — d dl mZ d dlZd dlmZ d dl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dS )é    )Ú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        ¦  «        s4t          | ¦  «         t          dt          |¦  «        j        › d�¦  «        ‚d| j	        |j
        |j        |j        |j        |j        dœ|_        |  	                    |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     ús/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/pytorch_lightning/utilities/compile.pyÚfrom_compiledr&      sQ  € õ �e�_Ñ-Ô-ð vÝÐtÕTXÐY^ÑT_ÔT_ÔThÐtÐtÐtÑuÔuÐuà”/€Kå�k¥2Ô#5Ñ6Ô6ð 
Ý˜UÑ#Ô#Ð#ÝØsÍdÐS^ÑN_ÔN_ÔNhÐsÐsÐsñ
ô 
ð 	
ð
 ØÔ&Ø'Ô/Ø"-Ô";Ø$/Ô$?Ø)Ô3Ø!,Ô!9ð!ð !€KÔð  ×*Ò*¨;Ô+>Ñ?Ô?€KÔØ %× 0Ò 0°Ô1JÑ KÔ K€KÔØ"'×"2Ò"2°;Ô3NÑ"OÔ"O€KÔØ!×,Ò,¨[Ô-BÑCÔC€KÔØ$×/Ò/°Ô0HÑIÔI€KÔØÐó    )r   ztorch._dynamo.OptimizedModulec                 óâ  — t          | t          ¦  «        rF| j        }t          |t          j        ¦  «        s$t          dt          | ¦  «        j        › �¦  «        ‚nBt          | t          j        ¦  «        r| j        €t          d¦  «        ‚| }nt          d¦  «        ‚|j        }|�H|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  € õ �%�Ñ)Ô)ð eØ”?ˆÝ˜(¥BÔ$6Ñ7Ô7ð 	ÝØpÕZ^Ð_dÑZeÔZeÔZnÐpÐpñô ð ð	õ
 
�E�2Ô-Ñ	.Ô	.ð eØÔÐ&ÝØuñô ð ð ˆˆõ ÐcÑdÔ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   sw   € Ý�%�Ñ)Ô)ð $Ý˜UÑ#Ô#Ð#Ý�%�Ô+Ñ,Ô,ð ØˆÝ˜ÑÔÐÝ
ØsÕX\Ð]bÑXcÔXcÔXpÐsÐsÐsñô ð r'   Ústrategyc                 ó  — | j         �€t          t          t          f}t	          ||¦  «        rt	          |t
          ¦  «        rId                     d„ |D ¦   «         ¦  «        }t          dt          |¦  «        j	        › d|› d�¦  «        ‚d S d S )Nz, c              3   ó$   K  — | ]}|j         V — Œd S )N)r   )Ú.0Úss     r%   ú	<genexpr>z4_verify_strategy_supports_compile.<locals>.<genexpr>x   s$   è è € Ð0ZÐ0ZÀ°´Ð0ZÐ0ZÐ0ZÐ0ZÐ0ZÐ0Zr'   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Ô9ð 	½ZÈÕRcÑ=dÔ=dð 	Ø'+§y¢yÐ0ZÐ0ZÐEYÐ0ZÑ0ZÔ0ZÑ'ZÔ'ZÐ$ÝðBÕVZÐ[cÑVdÔVdÔVmð Bð BØ1ðBð Bð Bñô ð ð	 'Ð&ð	ð 	r'   )Útypingr   ÚtorchÚtorch._dynamor   Úpytorch_lightningr   Úpytorch_lightning.strategiesr   r   r   r   r	   Ú)pytorch_lightning.utilities.model_helpersr
   r&   r,   Úobjectr0   r;   © r'   r%   ú<module>rD      s"  ðð Ð Ð Ð Ð Ð à €€€Ø )Ð )Ð )Ð )Ð )Ð )à Ð Ð Ð Ø uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uÐ uØ JÐ JÐ JÐ JÐ JÐ Jð&˜ð &Ð-Að &ð &ð &ð &ðR%˜ÐTÔUð %ÐZnð %ð %ð %ð %ðP 6ð Ð.Bð ð ð ð ð	Ð-Að 	ÈXð 	ÐZ^ð 	ð 	ð 	ð 	ð 	ð 	r'   