
    bi                     X   d dl mZ d dlmZmZmZmZmZmZ d dl	Z
d dl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mZ dd
lmZmZ ddlmZmZmZmZ ddl m!Z! ddl"m#Z# ddl$m%Z%  e       rd dl&m'c m(Z) dZ*ndZ* ejV                  e,      Z-dZ.e G d de             Z/ G d de#      Z0y)    )	dataclass)AnyDictListOptionalTupleUnionN)Image)tqdm)CLIPTextModelCLIPTokenizer   )PipelineImageInput)AutoencoderKLUNet2DConditionModel)DDIMSchedulerLCMScheduler)
BaseOutputis_torch_xla_availableloggingreplace_example_docstring)randn_tensor   )DiffusionPipeline   )MarigoldImageProcessorTFa  
Examples:
```py
>>> import diffusers
>>> import torch

>>> pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained(
...     "prs-eth/marigold-iid-appearance-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")

>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> intrinsics = pipe(image)

>>> vis = pipe.image_processor.visualize_intrinsics(intrinsics.prediction, pipe.target_properties)
>>> vis[0]["albedo"].save("einstein_albedo.png")
>>> vis[0]["roughness"].save("einstein_roughness.png")
>>> vis[0]["metallicity"].save("einstein_metallicity.png")
```
```py
>>> import diffusers
>>> import torch

>>> pipe = diffusers.MarigoldIntrinsicsPipeline.from_pretrained(
...     "prs-eth/marigold-iid-lighting-v1-1", variant="fp16", torch_dtype=torch.float16
... ).to("cuda")

>>> image = diffusers.utils.load_image("https://marigoldmonodepth.github.io/images/einstein.jpg")
>>> intrinsics = pipe(image)

>>> vis = pipe.image_processor.visualize_intrinsics(intrinsics.prediction, pipe.target_properties)
>>> vis[0]["albedo"].save("einstein_albedo.png")
>>> vis[0]["shading"].save("einstein_shading.png")
>>> vis[0]["residual"].save("einstein_residual.png")
```
c                       e Zd ZU dZeej                  ej                  f   e	d<   edej                  ej                  f   e	d<   edej                  f   e	d<   y)MarigoldIntrinsicsOutputa  
    Output class for Marigold Intrinsic Image Decomposition pipeline.

    Args:
        prediction (`np.ndarray`, `torch.Tensor`):
            Predicted image intrinsics with values in the range [0, 1]. The shape is $(numimages * numtargets) 	imes 3
            	imes height 	imes width$ for `torch.Tensor` or $(numimages * numtargets) 	imes height 	imes width
            	imes 3$ for `np.ndarray`, where `numtargets` corresponds to the number of predicted target modalities of
            the intrinsic image decomposition.
        uncertainty (`None`, `np.ndarray`, `torch.Tensor`):
            Uncertainty maps computed from the ensemble, with values in the range [0, 1]. The shape is $(numimages *
            numtargets) 	imes 3 	imes height 	imes width$ for `torch.Tensor` or $(numimages * numtargets) 	imes
            height 	imes width 	imes 3$ for `np.ndarray`.
        latent (`None`, `torch.Tensor`):
            Latent features corresponding to the predictions, compatible with the `latents` argument of the pipeline.
            The shape is $(numimages * numensemble) 	imes (numtargets * 4) 	imes latentheight 	imes latentwidth$.
    
predictionNuncertaintylatent)
__name__
__module____qualname____doc__r	   npndarraytorchTensor__annotations__     t/home/cdr/jupyterlab/.venv/lib/python3.12/site-packages/diffusers/pipelines/marigold/pipeline_marigold_intrinsics.pyr   r   _   sO    $ bjj%,,.//tRZZ566$$%%r,   r   c            !           e Zd ZdZdZdZ	 	 	 	 d(dededee	e
f   deded	ee   d
eeeef      dee   dee   f fdZed        Zdedededededededeeeef      deej.                     deeej0                  eej0                     f      dededefdZej8                  j:                  d)d       Z ej>                          e e!      	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dedee   dedee   dededededeeeef      deeej.                  eej.                     f      deeej0                  eej0                     f      dededed efd!              Z"dej.                  deej.                     deej0                     dedede#ej.                  ej.                  f   fd"Z$d#ej.                  dej.                  fd$Z%e&	 	 d+d%ej.                  ded&ede#ej.                  eej.                     f   fd'       Z' xZ(S ),MarigoldIntrinsicsPipelinea	  
    Pipeline for Intrinsic Image Decomposition (IID) using the Marigold method:
    https://marigoldcomputervision.github.io.

    This model inherits from [`DiffusionPipeline`]. Check the superclass documentation for the generic methods the
    library implements for all the pipelines (such as downloading or saving, running on a particular device, etc.)

    Args:
        unet (`UNet2DConditionModel`):
            Conditional U-Net to denoise the targets latent, conditioned on image latent.
        vae (`AutoencoderKL`):
            Variational Auto-Encoder (VAE) Model to encode and decode images and predictions to and from latent
            representations.
        scheduler (`DDIMScheduler` or `LCMScheduler`):
            A scheduler to be used in combination with `unet` to denoise the encoded image latents.
        text_encoder (`CLIPTextModel`):
            Text-encoder, for empty text embedding.
        tokenizer (`CLIPTokenizer`):
            CLIP tokenizer.
        prediction_type (`str`, *optional*):
            Type of predictions made by the model.
        target_properties (`Dict[str, Any]`, *optional*):
            Properties of the predicted modalities, such as `target_names`, a `List[str]` used to define the number,
            order and names of the predicted modalities, and any other metadata that may be required to interpret the
            predictions.
        default_denoising_steps (`int`, *optional*):
            The minimum number of denoising diffusion steps that are required to produce a prediction of reasonable
            quality with the given model. This value must be set in the model config. When the pipeline is called
            without explicitly setting `num_inference_steps`, the default value is used. This is required to ensure
            reasonable results with various model flavors compatible with the pipeline, such as those relying on very
            short denoising schedules (`LCMScheduler`) and those with full diffusion schedules (`DDIMScheduler`).
        default_processing_resolution (`int`, *optional*):
            The recommended value of the `processing_resolution` parameter of the pipeline. This value must be set in
            the model config. When the pipeline is called without explicitly setting `processing_resolution`, the
            default value is used. This is required to ensure reasonable results with various model flavors trained
            with varying optimal processing resolution values.
    ztext_encoder->unet->vae)
intrinsicsunetvae	schedulertext_encoder	tokenizerprediction_typetarget_propertiesdefault_denoising_stepsdefault_processing_resolutionc
                    t         
|           || j                  vr&t        j	                  d| d| j                   d       | j                  |||||       | j                  ||||	       t        | dd       r/dt        | j                  j                  j                        dz
  z  nd	| _        || _        || _        |	| _        d | _        t#        | j                  
      | _        y )Nz*Potentially unsupported `prediction_type='z&'`; values supported by the pipeline: .)r1   r2   r3   r4   r5   )r6   r7   r8   r9   r2   r   r      )vae_scale_factor)super__init__supported_prediction_typesloggerwarningregister_modulesregister_to_configgetattrlenr2   configblock_out_channelsr=   r7   r8   r9   empty_text_embeddingr   image_processor)selfr1   r2   r3   r4   r5   r6   r7   r8   r9   	__class__s             r-   r?   z#MarigoldIntrinsicsPipeline.__init__   s     	$"A"AANN<_<MMs22316
 	% 	 	
 	+/$;*G	 	  	
 W^^bdikoVpc$((//*L*L&MPQ&Q Rvw!2'>$-J*$(!5tG\G\]r,   c                     | j                   j                  j                  | j                  j                  j                  z  S )N)r1   rG   out_channelsr2   latent_channels)rK   s    r-   	n_targetsz$MarigoldIntrinsicsPipeline.n_targets   s+    yy,,0O0OOOr,   imagenum_inference_stepsensemble_sizeprocessing_resolutionresample_method_inputresample_method_output
batch_sizeensembling_kwargslatents	generatoroutput_typeoutput_uncertaintyreturnc           
        
 dt        | j                  j                  j                        dz
  z  }|| j                  k7  rt        d| j                   d| d      |t        d      |dk  rt        d      |dk  rt        d      |dk(  rt        j                  d	       |dk(  r|rt        d
      |t        d      |dk  rt        d      || j                  z  dk7  rt        d| j                   d      |dvrt        d      |dvrt        d      |dk  rt        d      |dvrt        d      |	
t        d      |1t        |t              st        d      d|v r|d   dvrt        d      d}d\  }}t        |t              s|g}t        |      D ]  \  }}t        |t        j                        st        j                  |      r]|j                   dvrt        d| d|j"                   d      |j"                  dd  \  }}d}|j                   d k(  rW|j"                  d   }nGt        |t$        j$                        r|j&                  \  }}d}nt        d!| d"t)        |       d      |||}}n!||f||fk7  rt        d#| d$||f d%||f       ||z  }	 |	t        j                  |	      st        d&      |	j+                         d k7  rt        d'|	j"                   d      |dkD  r<t-        ||      }||z  |z  }||z  |z  }|dk(  s|dk(  rt        d(| d)| d*      ||}}|| j                  z   dz
  | j                  z  }|| j                  z   dz
  | j                  z  }||z  | j.                  j                  j0                  ||f}|	j"                  |k7  rt        d+|	j"                   d,| d      
t        
t              r=t        
      ||z  k7  rt        d-      t3        
fd.
D              st        d/      |S t        
t        j4                        st        d0t)        
       d      |S )1Nr   r   z/`vae_scale_factor` computed at initialization (z) differs from the actual one (z).zW`num_inference_steps` is not specified and could not be resolved from the model config.z'`num_inference_steps` must be positive.z!`ensemble_size` must be positive.zk`ensemble_size` == 2 results are similar to no ensembling (1); consider increasing the value to at least 3.zpComputing uncertainty by setting `output_uncertainty=True` also requires setting `ensemble_size` greater than 1.zY`processing_resolution` is not specified and could not be resolved from the model config.r   zx`processing_resolution` must be non-negative: 0 for native resolution, or any positive value for downsampled processing.z.`processing_resolution` must be a multiple of r;   )nearestznearest-exactbilinearbicubicareazy`resample_method_input` takes string values compatible with PIL library: nearest, nearest-exact, bilinear, bicubic, area.zz`resample_method_output` takes string values compatible with PIL library: nearest, nearest-exact, bilinear, bicubic, area.z`batch_size` must be positive.)ptr&   z*`output_type` must be one of `pt` or `np`.z2`latents` and `generator` cannot be used together.z)`ensembling_kwargs` must be a dictionary.	reductionmedianmeanzF`ensembling_kwargs['reduction']` can be either `'median'` or `'mean'`.)NN)r   r      z`image[z(]` has unsupported dimensions or shape: rh   zUnsupported `image[z	]` type: zInput `image[z]` has incompatible dimensions z with the previous images z!`latents` must be a torch.Tensor.z/`latents` has unsupported dimensions or shape: z*Extreme aspect ratio of the input image: [z x ]z`latents` has unexpected shape=z
 expected=z^The number of generators must match the total number of ensemble members for all input images.c              3   ~   K   | ]4  }|j                   j                  d    j                   j                  k(   6 yw)r   N)devicetype).0grZ   s     r-   	<genexpr>z:MarigoldIntrinsicsPipeline.check_inputs.<locals>.<genexpr>M  s.     X188==IaL,?,?,D,DDXs   :=z;`generator` device placement is not consistent in the list.zUnsupported generator type: )rF   r2   rG   rH   r=   
ValueErrorrA   rB   
isinstancedictlist	enumerater&   r'   r(   	is_tensorndimshaper
   sizerm   dimmaxr1   rN   all	Generator)rK   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   actual_vae_scale_factor
num_imagesWHiimgH_iW_iN_imax_orignew_Hnew_Wwhshape_expecteds             `                 r-   check_inputsz'MarigoldIntrinsicsPipeline.check_inputs   s"    #$DHHOO,N,N(ORS(S"T"d&;&;;A$BWBWAXXw  yP  xQ  QS  T  &vww"FGG1@AAANN? A"4"  !(k  !1$*  !4#8#88A=MdNcNcMddefgg (ccC  ")ddC  >=>>l*IJJ9#8QRR(/6 !LMM//4Ek4RZl4l !ijj 
1%&GE& 	FAs#rzz*eooc.B889,$wqc1YZ]ZcZcYdde%fgg99RS>S88q=))A,CC-88S #6qc49+Q!OPPyC1QC:% #A3&EsCj\Qkmnpqlrkst  #J'	, ??7+ !DEE{{}! #RSZS`S`Raab!cdd$q(q!911X=11X=A:!$'QRSQTTWXYWZZ[%\]]e1T***Q.43H3HHAT***Q.43H3HHA(=8$)):J:J:W:WYZ\]^N}}. #B7==/Q[\j[kkl!mnn  )T*y>Z-%??$x  XiXX$%bcc   	5??; #?Y?PPQ!RSSr,   c                 p   t        | d      si | _        n<t        | j                  t              s"t	        dt        | j                         d      t        di | j                  }|j                  d|      |d<   |j                  d|      |d<   |t        |fi |S |t        dd|i|S t	        d      )	N_progress_bar_configz=`self._progress_bar_config` should be of type `dict`, but is r;   descleavetotalz/Either `total` or `iterable` has to be defined.r+   )hasattrr   rr   rs   rq   rm   getr   )rK   iterabler   r   r   progress_bar_configs         r-   progress_barz'MarigoldIntrinsicsPipeline.progress_barT  s    t34(*D%D55t<OPTUYUnUnPoOppqr  #?T%>%>?&9&=&=fd&KF#':'>'>w'NG$8$788;e;':;;NOOr,   match_input_resolutionoutput_latentreturn_dictc                    | j                   }| j                  }|| j                  }|| j                  }| j	                  ||||||||	|
|||      }| j
                  `d}| j                  |d| j                  j                  dd      }|j                  j                  |      }| j                  |      d   | _        | j                  j                  |||||      \  }}}| j                  ||
|||      \  }}~| j
                  j                  ||      j                  |d	d	      }g }| j                  t!        d||z  |      dd
      D ]  }||||z    }||||z    }|j"                  d   }|d| } | j$                  j'                  ||       | j                  | j$                  j(                  dd      D ]w  }!t+        j,                  ||gd	      }"| j/                  |"|!| d      d   }#| j$                  j1                  |#|!||      j2                  }t4        sdt7        j8                          y |j;                  |        t+        j,                  |d      }~~~~~~ ~"~# |j<                  ||z  | j>                  z  | j@                  jB                  jD                  g|j"                  dd  }$t+        j,                  t!        d|$j"                  d   |      D cg c]  }| jG                  |$|||z           c}d      }%~$|sd}| j                  jI                  |%|      }%d}&|d	kD  r |%j<                  ||| j>                  g|%j"                  d	d  }%t!        |      D cg c]  } | jJ                  |%|   |fi |	xs i  }%}tM        |% \  }%}&t+        j,                  |%d      }%|rt+        j,                  |&d      }&nd}&|rB| j                  jO                  |%||d      }%|&!|r| j                  jO                  |&||d      }&|dk(  r:| j                  jQ                  |%      }%|&|r| j                  jQ                  |&      }&| jS                          |s|%|&|fS tU        |%|&|      S c c}w c c}w )aj  
        Function invoked when calling the pipeline.

        Args:
            image (`PIL.Image.Image`, `np.ndarray`, `torch.Tensor`, `List[PIL.Image.Image]`, `List[np.ndarray]`),
                `List[torch.Tensor]`: An input image or images used as an input for the intrinsic decomposition task.
                For arrays and tensors, the expected value range is between `[0, 1]`. Passing a batch of images is
                possible by providing a four-dimensional array or a tensor. Additionally, a list of images of two- or
                three-dimensional arrays or tensors can be passed. In the latter case, all list elements must have the
                same width and height.
            num_inference_steps (`int`, *optional*, defaults to `None`):
                Number of denoising diffusion steps during inference. The default value `None` results in automatic
                selection.
            ensemble_size (`int`, defaults to `1`):
                Number of ensemble predictions. Higher values result in measurable improvements and visual degradation.
            processing_resolution (`int`, *optional*, defaults to `None`):
                Effective processing resolution. When set to `0`, matches the larger input image dimension. This
                produces crisper predictions, but may also lead to the overall loss of global context. The default
                value `None` resolves to the optimal value from the model config.
            match_input_resolution (`bool`, *optional*, defaults to `True`):
                When enabled, the output prediction is resized to match the input dimensions. When disabled, the longer
                side of the output will equal to `processing_resolution`.
            resample_method_input (`str`, *optional*, defaults to `"bilinear"`):
                Resampling method used to resize input images to `processing_resolution`. The accepted values are:
                `"nearest"`, `"nearest-exact"`, `"bilinear"`, `"bicubic"`, or `"area"`.
            resample_method_output (`str`, *optional*, defaults to `"bilinear"`):
                Resampling method used to resize output predictions to match the input resolution. The accepted values
                are `"nearest"`, `"nearest-exact"`, `"bilinear"`, `"bicubic"`, or `"area"`.
            batch_size (`int`, *optional*, defaults to `1`):
                Batch size; only matters when setting `ensemble_size` or passing a tensor of images.
            ensembling_kwargs (`dict`, *optional*, defaults to `None`)
                Extra dictionary with arguments for precise ensembling control. The following options are available:
                - reduction (`str`, *optional*, defaults to `"median"`): Defines the ensembling function applied in
                  every pixel location, can be either `"median"` or `"mean"`.
            latents (`torch.Tensor`, *optional*, defaults to `None`):
                Latent noise tensors to replace the random initialization. These can be taken from the previous
                function call's output.
            generator (`torch.Generator`, or `List[torch.Generator]`, *optional*, defaults to `None`):
                Random number generator object to ensure reproducibility.
            output_type (`str`, *optional*, defaults to `"np"`):
                Preferred format of the output's `prediction` and the optional `uncertainty` fields. The accepted
                values are: `"np"` (numpy array) or `"pt"` (torch tensor).
            output_uncertainty (`bool`, *optional*, defaults to `False`):
                When enabled, the output's `uncertainty` field contains the predictive uncertainty map, provided that
                the `ensemble_size` argument is set to a value above 2.
            output_latent (`bool`, *optional*, defaults to `False`):
                When enabled, the output's `latent` field contains the latent codes corresponding to the predictions
                within the ensemble. These codes can be saved, modified, and used for subsequent calls with the
                `latents` argument.
            return_dict (`bool`, *optional*, defaults to `True`):
                Whether or not to return a [`~pipelines.marigold.MarigoldIntrinsicsOutput`] instead of a plain tuple.

        Examples:

        Returns:
            [`~pipelines.marigold.MarigoldIntrinsicsOutput`] or `tuple`:
                If `return_dict` is `True`, [`~pipelines.marigold.MarigoldIntrinsicsOutput`] is returned, otherwise a
                `tuple` is returned where the first element is the prediction, the second element is the uncertainty
                (or `None`), and the third is the latent (or `None`).
        N 
do_not_padTrc   )padding
max_length
truncationreturn_tensorsr   )rl   dtyper   zMarigold predictions...)r   r   )rl   FzDiffusion steps...rz   )encoder_hidden_statesr   )rZ   r   )is_aar&   )r   r    r!   )+_execution_devicer   r8   r9   r   rI   r5   model_max_length	input_idstor4   rJ   
preprocessprepare_latentsrepeatr   rangerx   r3   set_timesteps	timestepsr(   catr1   stepprev_sampleXLA_AVAILABLExm	mark_stepappendreshaperP   r2   rG   rO   decode_predictionunpad_imageensemble_intrinsicszipresize_antialiaspt_to_numpymaybe_free_model_hooksr   )'rK   rQ   rR   rS   rT   r   rU   rV   rW   rX   rY   rZ   r[   r\   r   r   rl   r   r   prompttext_inputstext_input_idsr   original_resolutionimage_latentpred_latentbatch_empty_text_embeddingpred_latentsr   batch_image_latentbatch_pred_latenteffective_batch_sizetexttbatch_latentnoisepred_latent_for_decodingr   r    s'                                          r-   __call__z#MarigoldIntrinsicsPipeline.__call__g  s<   d ''

 &"&">"> ($($F$F! &&!!"

" $$,F..$>>::# ) K )2255f=N(,(9(9.(I!(LD% /3.B.B.M.M(*?/
+w+ %)$8$87I}j%
!k %)%>%>%A%AW\%A%]%d%d1&
" ""!Z-/<DOh # 
 	3A ".a!j.!A +AJ ?#5#;#;A#> -.C/CDDNN(()<V(L&&t~~'?'?uSg&h #$yy*<>O)PVWX		,[`	abcd$(NN$7$71/9 %8 %+ " !LLN#  12'	3* ii!4 & $7;#6#6&79X9X$
[f[l[lmnmo[p$
  YY q":"@"@"CZP &&'?A
N'ST 

 %K ))55j'J
 1+++M4>><F<L<LQR<PJ
 z* )((A8JhO`OfdfhJ  '*:&6#J:15J!#ii;" "-->>/1Gu ? J &+="22CC!46LTY D 
 $--99*EJ&+="22>>{K 	##%[99'!#
 	
y0s   Q/%"Q4c                    d }t        j                  t        d|j                  d   |      D cg c])  } || j                  j                  ||||z                + c}d      }|| j                  j                  j                  z  }|j                  |d      }|j                  \  }	}
}}|}|4t        |	| j                  |
z  ||f||j                  |j                        }||fS c c}w )Nc                     t        | d      r| j                  j                         S t        | d      r| j                  S t	        d      )Nlatent_distrY   z3Could not access latents of provided encoder_output)r   r   moderY   AttributeError)encoder_outputs    r-   retrieve_latentszDMarigoldIntrinsicsPipeline.prepare_latents.<locals>.retrieve_latents{  sC    ~}5%1166883%---$%Z[[r,   r   r   )rZ   rl   r   )r(   r   r   rx   r2   encoderG   scaling_factorrepeat_interleaver   rP   rl   r   )rK   rQ   rY   rZ   rS   rW   r   r   r   N_ECr   r   r   s                 r-   r   z*MarigoldIntrinsicsPipeline.prepare_latentss  s    	\ yy q%++a.*= !q1z>1J!KL 
 $dhhoo&D&DD#55m5K#))Q1&dnnq(!Q/##**"((	K [(('s   .C)r   c                    |j                         dk7  s0|j                  d   | j                  j                  j                  k7  r:t        d| j                  j                  j                   d|j                   d      | j                  j                  || j                  j                  j                  z  d      d   }t        j                  |d	d
      }|d
z   dz  }|S )Nrh   r   z Expecting 4D tensor of shape [B,z,H,W]; got r;   F)r   r   g      g      ?g       @)
rz   rx   r2   rG   rO   rq   decoder   r(   clip)rK   r   r   s      r-   r   z,MarigoldIntrinsicsPipeline.decode_prediction  s    ??![%6%6q%9TXX__=\=\%\2488??3R3R2SS^_j_p_p^qqrs  XX__[488??3Q3Q%Q_d_efgh
ZZ
D#6
 3&#-
r,   targetsrd   c                 J   | j                         dk7  s| j                  d   dk7  rt        d| j                   d      |dvrt        d| d      | j                  \  }}}}}d}|d	k(  r4t        j                  | d
      }	|rt        j
                  | d
      }|	|fS |dk(  rrt        j                  | d
d      j                  }	|r9t        j                  | |	z
        }t        j                  |d
      j                  }|	j                  d
      }	|	|fS t        d| d      )a  
        Ensembles the intrinsic decomposition represented by the `targets` tensor with expected shape `(B, T, 3, H,
        W)`, where B is the number of ensemble members for a given prediction of size `(H x W)`, and T is the number of
        predicted targets.

        Args:
            targets (`torch.Tensor`):
                Input ensemble of intrinsic image decomposition maps.
            output_uncertainty (`bool`, *optional*, defaults to `False`):
                Whether to output uncertainty map.
            reduction (`str`, *optional*, defaults to `"mean"`):
                Reduction method used to ensemble aligned predictions. The accepted values are: `"median"` and
                `"mean"`.

        Returns:
            A tensor of aligned and ensembled intrinsic decomposition maps with shape `(T, 3, H, W)` and optionally a
            tensor of uncertainties of shape `(T, 3, H, W)`.
           r   r   z.Expecting 4D tensor of shape [B,T,3,H,W]; got r;   re   zUnrecognized reduction method: Nrg   r   r   rf   T)rz   keepdim)
rz   rx   rq   r(   rg   stdrf   valuesabssqueeze)
r   r\   rd   BT_r   r   r    r   s
             r-   r   z.MarigoldIntrinsicsPipeline.ensemble_intrinsics  s,   0 ;;=Aq!1Q!6Mgmm_\]^__..>ykKLL1aAG3J!#iiQ7 ;&& ("g1dCJJJ!#ii*(<=#ll;A>EE#++A.J ;&& >ykKLLr,   )NNNN)NNNT)Nr   NTr`   r`   r   NNNr&   FFT)Frf   ))r"   r#   r$   r%   model_cpu_offload_seqr@   r   r   r	   r   r   r   r   r   strr   r   intr?   propertyrP   r   r(   r)   r}   r   boolr   compilerdisabler   no_gradr   EXAMPLE_DOC_STRINGr   r   r   r   staticmethodr   __classcell__)rL   s   @r-   r/   r/   x   s   $L 6!0 *.6:157;*^"*^ *^ 45	*^
 $*^ !*^ "#*^ $DcN3*^ "*#*^ (0}*^X P P@!@ !@ 	@
  #@  #@ !$@ @ $DcN3@ %,,'@ E%//43H"HIJ@ @ !@ 
@D ^^P P$ U]]_12 .2/3'+%/&06:EIMQ#(# !H
!H
 &c]H
 	H

  (}H
 !%H
  #H
 !$H
 H
 $DcN3H
 %d5<<.@ @ABH
 E%//43H"HIJH
 H
 !H
 H
  !H
 3 H
T$)||$) %,,'$) EOO,	$)
 $) $) 
u||U\\)	*$)LU\\ ell   $)!*'*' *' *' 
u||Xell33	4	*' *'r,   r/   )1dataclassesr   typingr   r   r   r   r   r	   numpyr&   r(   PILr
   	tqdm.autor   transformersr   r   rJ   r   modelsr   r   
schedulersr   r   utilsr   r   r   r   utils.torch_utilsr   pipeline_utilsr   marigold_image_processingr   torch_xla.core.xla_modelcore	xla_modelr   r   
get_loggerr"   rA   r   r   r/   r+   r,   r-   <module>r     s   & " : :     5 1  . . = ))MM			H	%" J &z & &0Y	'!2 Y	'r,   