Ë
    g^(hØX  ã                   ó¬  — d dl Z d dlmZmZ d dlmZmZmZmZ d dl	Z	d dl
mZ d dl	mZ d dlmZ defd„Zdeeeef   eeeef      f   d	eeeef   eeeef      f   deeee   f   fd
„Zdej*                  dedeeeef      f   deegef   deeedf   eedf   eeee   f   f   fd„Zdej*                  deeedf   eedf   eeee   f   f   fd„Zdej*                  deeedf   eedf   eeee   f   f   fd„Z	 d3dej*                  dee   dee   deddf
d„Zdej*                  deeee   f   dee   dee   fd„Z	 d3dej*                  dee   dee   deddf
d„Z	 	 d4dej*                  dee   dee   dee   dee   dej*                  fd „Zdej*                  fd!„Zdej*                  fd"„Z G d#„ d$ej*                  «      Z  G d%„ d&ej*                  «      Z!	 d3dej*                  d'edee!eedf   f   fd(„Z"	 d3dej*                  d'edee eedf   eedf   f   fd)„Z#d*eeedf   df   deedf   fd+„Z$d,eej*                     dee eedf   eedf   f   fd-„Z%	 	 d5d.e&ej*                     d/eed   ee'   f   d0e	jP                  jR                  fd1„Z*	 	 d5d.e&ej*                     d/eed   ee'   f   d0e	jP                  jR                  fd2„Z+y)6é    N)ÚIterableÚSequence)ÚAnyÚCallableÚNoReturnÚUnion)ÚTensor)ÚNamedMemberAccessorÚreturnc                  ó   — t        d«      ‚)Na$  make_functional(module): we don't yet support models that do parameter tying (also sometimes known as weight sharing). Please try to rewrite your model by replacing all instances of the tied parameter with another and/or comment your support in https://github.com/pytorch/functorch/issues/446)ÚRuntimeError© ó    ú^/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/torch/_functorch/make_functional.pyÚraise_parameter_tying_errorr      s   € Ü
ð	:óð r   Únamed_paramsÚtied_named_paramsc                 ó–  — t        | «      } t        |«      }t        | j                  «       «      }t        |j                  «       «      }|j                  |«      sJ ‚i }| j	                  «       D ]  \  }}|g f||<   Œ |j	                  «       D ]"  \  }}||v sJ ‚||   d   j                  |«       Œ$ t        |j                  «       «      S )a[  
    named_params is a dictionary of tensors: {'A': A, 'B': B}
    tied_named_params is another dictionary of tensors {'A': A, 'B': B, 'B_tied': B}
    with potentially tied (or 'duplicated') tensors

    This function creates a mapping from the names in named_params to the
    names in tied_named_params: {'A': ['A'], 'B': ['B', 'B_tied']}.
    é   )ÚdictÚsetÚkeysÚissubsetÚitemsÚappendÚvalues)r   r   Útensors_dict_keysÚtied_tensors_dict_keysÚtensor_to_mappingÚkeyÚtensors          r   Úcreate_names_mapr"   !   sã   € ô ˜Ó%€LÜÐ.Ó/Ðä˜L×-Ñ-Ó/Ó0ÐÜ Ð!2×!7Ñ!7Ó!9Ó:ÐØ×%Ñ%Ð&<Ô=Ð=Ð=à=?ÐØ#×)Ñ)Ó+ò .‰ˆˆVØ%(¨" IÐ˜&Ò!ð.à(×.Ñ.Ó0ò 1‰ˆˆVØÐ*Ñ*Ð*Ð*Ø˜&Ñ! !Ñ$×+Ñ+¨CÕ0ð1ô Ð!×(Ñ(Ó*Ó+Ð+r   ÚmodÚnamed_members.Úsubclassc                 óN  — t         |d¬«      «      }t         |d¬«      «      }t        ||«      }i }t        | «      }|D ]@  \  }}	|	|vr  |t        j                  |	d¬«      «      ||	<   ||	   }
|j                  ||
«       ŒB t        |«      dk(  rd\  }}nt        |Ž \  }}|||fS )NF)Úremove_duplicateTÚmeta)Údevicer   ©r   r   )Útupler"   r
   ÚtorchÚ
empty_likeÚ
set_tensorÚlenÚzip)r#   r$   r%   Úall_named_membersÚunique_named_membersÚ	names_mapÚmemoÚaccessorÚnameÚpÚreplacementÚnamesÚparamss                r   Ú_extract_membersr;   =   sÆ   € ô
 ™m¸UÔCÓDÐÜ ¡ÀÔ!EÓFÐÜ Ð!5Ð7HÓI€Ið €DÜ" 3Ó'€HØ$ò /‰ˆˆaØ�D‰=Ùœu×/Ñ/°¸&ÔAÓBˆD�‰GØ˜1‘gˆØ×Ñ˜D +Õ.ð	/ô ÐÓ  AÒ%Ø‰ˆ‰väÐ1Ð2‰ˆˆvØ�5˜)Ð#Ð#r   c                 óL   — t        | | j                  t        j                  «      S )aZ  
    This function removes all the Parameters from the model and
    return them as a tuple as well as their original attribute names.
    The weights must be re-loaded with `load_weights` before the model
    can be used again.
    Note that this function modifies the model in place and after this
    call, mod.parameters() will be empty.
    )r;   Únamed_parametersÚnnÚ	Parameter©r#   s    r   Úextract_weightsrA   V   s   € ô ˜C ×!5Ñ!5´r·|±|ÓDÐDr   c                 ó2   — t        | | j                  d„ «      S )Nc                 ó   — | S ©Nr   )Úxs    r   ú<lambda>z!extract_buffers.<locals>.<lambda>g   s   € ¸a€ r   )r;   Únamed_buffersr@   s    r   Úextract_buffersrH   d   s   € ô ˜C ×!2Ñ!2±KÓ@Ð@r   r9   r:   Ú	as_paramsc                 ó�   — t        | «      }|r"|D �cg c]  }t        j                  |«      ‘Œ }}|j                  ||«       yc c}w )a	  
    Reload a set of weights so that `mod` can be used again to perform a forward pass.
    Note that the `params` are regular Tensors (that can have history) and so are left
    as Tensors. This means that mod.parameters() will still be empty after this call.
    N)r
   r>   r?   Úset_tensors)r#   r9   r:   rI   r5   r7   s         r   Úload_weightsrL   j   sA   € ô # 3Ó'€HÙØ+1Ö2 a”"—,‘,˜q•/Ð2ˆÐ2Ø×Ñ˜ Õ'ùò 3s   ’Ar3   Úelemsc                 ó  — g }t        | «      }t        |j                  «       |«      D ]T  \  \  }}}t        |«      D ]>  \  }}	|dk(  r"|j	                  |j                  |	|«      «       Œ-|j                  |	|«       Œ@ ŒV |S )Nr   )r
   r0   r   Ú	enumerater   Úswap_tensorr.   )
r#   r3   rM   Úresultr5   Ú_Ú
attr_namesÚelemÚiÚ	attr_names
             r   Ú_swap_staterW   {   sˆ   € ð €FÜ" 3Ó'€HÜ!$ Y§_¡_Ó%6¸Ó!>ò 5Ñ‰ˆˆJ˜Ü% jÓ1ò 	5‰LˆAˆyØ�AŠvØ—‘˜h×2Ñ2°9¸dÓCÕDà×#Ñ# I¨tÕ4ñ		5ð5ð €Mr   Úbuffersc                 ó>   — t        | «      }|j                  ||«       y rD   )r
   rK   )r#   r9   rX   rI   r5   s        r   Úload_buffersrZ   ‰   s   € ô # 3Ó'€HØ×Ñ˜ Õ(r   r   ÚmodelÚweightsÚweight_namesÚbuffer_namesc                 óº   — t        |«      t        |«      k(  sJ ‚t        | ||«       t        |«      dkD  r&t        |«      t        |«      k(  sJ ‚t        | ||«       | S )zæload_state(model, weights, weight_names, buffers=(), buffer_names=()) -> model

    load_state takes `weights` and `buffers` and assigns them to the model.
    This is the inverse operation of `make_functional_deprecated_v1`.
    r   )r/   rL   rZ   )r[   r\   r]   rX   r^   s        r   Ú
load_stater`   “   s[   € ô ˆ|Ó¤ G£Ò,Ð,Ð,Ü�˜ gÔ.Ü
ˆ7ƒ|�aÒÜ�<Ó ¤C¨£LÒ0Ð0Ð0Ü�U˜L¨'Ô2Ø€Lr   c                 óž   ‡ ‡— t        ‰ j                  «       «      }t        |«      dkD  rt        d«      ‚t	        ‰ «      \  }Š}ˆˆ fd„}||‰fS )a  make_functional_deprecated_v1(model) -> weights, func, weight_names

    Given an nn.Module, make_functional_deprecated_v1 extracts the state (weights)
    and returns a functional version of the model, `func`. This makes
    it so that it is possible use transforms over the parameters of
    `model`.

    `func` can be invoked as follows:
    ```
    x = torch.randn(4, 3)
    model = nn.Linear(3, 3)
    weights, func, _ = make_functional_deprecated_v1(model)
    func(weights, (x,))
    ```

    And here is an example of applying the grad transform:
    ```
    x = torch.randn(4, 3)
    model = nn.Linear(3, 3)
    weights, _, func = make_functional_deprecated_v1(model)
    grad_weights = grad(func)(weights, (x,))
    ```

    To put the state back into a model, use `load_state`.
    r   z€make_functional_deprecated_v1(model): `model` has buffers. Please use make_functional_with_buffers_deprecated_v1(model) instead.c                 óR   •— t        j                  ‰«      }t        |‰| «        ||Ž S rD   )ÚcopyÚdeepcopyrL   )r\   ÚdataÚmutable_modelÚdescriptorsr[   s      €€r   Úfunz*make_functional_deprecated_v1.<locals>.funÉ   s(   ø€ ÜŸ™ eÓ,ˆÜ�] K°Ô9Ù˜dÐ#Ð#r   )ÚlistrX   r/   r   rA   )r[   rX   r\   rR   rh   rg   s   `    @r   Úmake_functional_deprecated_v1rj   §   s[   ù€ ô4 �5—=‘=“?Ó#€GÜ
ˆ7ƒ|�aÒÜðIó
ð 	
ô .¨eÓ4Ñ€Gˆ[˜!õ$ð
 �C˜Ð$Ð$r   c                 ó`   ‡ ‡‡— t        ‰ «      \  }Š}t        ‰ «      \  }Š}ˆˆ ˆfd„}|||‰‰fS )a`  make_functional_with_buffers_deprecated_v1(model) -> weights, buffers, func, weight_names, buffer_names

    Given an nn.Module, make_functional_with_buffers_deprecated_v1 extracts the state (weights and buffers)
    and returns a functional version of the model, `func`.

    `func` can be invoked as follows:
    ```
    x = torch.randn(4, 3)
    model = nn.Linear(3, 3)
    weights, buffers, func, _, _ = make_functional_with_buffers_deprecated_v1(model)
    func(weights, buffers, (x,))
    ```

    And here is an example of applying the grad transform:
    ```
    x = torch.randn(4, 3)
    model = nn.Linear(3, 3)
    weights, buffers, func, _, _ = make_functional_with_buffers_deprecated_v1(model)
    func(weights, buffers, (x,))
    grad_weights = grad(func)(weights, buffers, (x,))
    ```

    To put the state back into a model, use `load_state`.
    c                 ól   •— t        j                  ‰«      }t        |‰| «       t        |‰|«        ||Ž S rD   )rc   rd   rL   rZ   )r\   rX   re   rf   Úbuf_descriptorsr[   Úweight_descriptorss       €€€r   rh   z7make_functional_with_buffers_deprecated_v1.<locals>.funí   s5   ø€ ÜŸ™ eÓ,ˆÜ�]Ð$6¸Ô@Ü�] O°WÔ=Ù˜dÐ#Ð#r   )rA   rH   )r[   r\   rR   rX   rh   rm   rn   s   `    @@r   Ú*make_functional_with_buffers_deprecated_v1ro   Ñ   sA   ú€ ô2 &5°UÓ%;Ñ"€GÐ Ü"1°%Ó"8Ñ€Gˆ_˜aö$ð �G˜SÐ"4°oÐEÐEr   c                   óú   ‡ — e Zd ZdZdej
                  deedf   deedf   deee	e   f   deee	e   f   dd	fˆ fd
„Z
e	 ddej
                  deded eedf   eedf   f   fd„«       Zdee   dee   defd„Zˆ xZS )ÚFunctionalModuleWithBufferszW
    This is the callable object returned by :func:`make_functional_with_buffers`.
    Ústateless_modelÚparam_names.r^   Úparam_names_mapÚbuffer_names_mapr   Nc                 ó¢   •— t         ‰| �  «        || _        || _        || _        t        |«      | _        | j                  j                  |«       y rD   )ÚsuperÚ__init__rr   rs   r^   r   Úall_names_mapÚupdate)Úselfrr   rs   r^   rt   ru   Ú	__class__s         €r   rx   z$FunctionalModuleWithBuffers.__init__û   sJ   ø€ ô 	‰ÑÔØ.ˆÔØ&ˆÔØ(ˆÔä! /Ó2ˆÔØ×Ñ×!Ñ!Ð"2Õ3r   r[   Údisable_autograd_trackingc                 óÀ   — t        j                  | «      }t        |«      \  }}}t        |«      \  }}}|r|D ]  }	|	j	                  d«       Œ t        |||||«      ||fS ©NF)rc   rd   rA   rH   Úrequires_grad_rq   )
r[   r}   Ú
model_copyr:   rs   rt   rX   r^   ru   Úparams
             r   Ú_create_fromz(FunctionalModuleWithBuffers._create_from  s}   € ô
 —]‘] 5Ó)ˆ
Ü/>¸zÓ/JÑ,ˆ�˜_Ü2AÀ*Ó2MÑ/ˆ�Ð/Ù$Øò ,�Ø×$Ñ$ UÕ+ð,ô (Ø˜K¨°ÐHXóð Øð
ð 	
r   r:   rX   c                 ó"  — t        | j                  | j                  t        |«      t        |«      z   «      }	  | j                  |i |¤Žt        | j                  | j                  |«       S # t        | j                  | j                  |«       w xY wrD   )rW   rr   ry   r+   )r{   r:   rX   ÚargsÚkwargsÚ	old_states         r   Úforwardz#FunctionalModuleWithBuffers.forward  s~   € ô  Ø× Ñ Ø×ÑÜ�&‹MœE '›NÑ*ó
ˆ	ð
	MØ'�4×'Ñ'¨Ð8°Ñ8ô ˜×,Ñ,¨d×.@Ñ.@À)ÕLøŒK˜×,Ñ,¨d×.@Ñ.@À)ÕLús   ¸A+ Á+#B©F©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r>   ÚModuler+   Ústrr   ri   rx   ÚstaticmethodÚboolr	   rƒ   r   r   rˆ   Ú__classcell__©r|   s   @r   rq   rq   ö   só   ø„ ñð4àŸ™ð4ð ˜3 ˜8‘_ð4ð ˜C ˜H‘oð	4ð
 ˜c 4¨¡9˜nÑ-ð4ð ˜s D¨¡I˜~Ñ.ð4ð 
õ4ð  à<Añ
Ø�y‰yð
Ø59ð
à	Ð,¨e°F¸C°KÑ.@À%ÈÐPSÈÑBTÐTÑ	Uò
ó ð
ð$MØ˜vÑ&ðMØ19¸&Ñ1AðMà	÷Mr   rq   c                   óÂ   ‡ — e Zd ZdZdej
                  deedf   deee	e   f   ddfˆ fd„Z
e	 dd	ej
                  d
eded eedf   f   fd„«       Zdee   defd„Zˆ xZS )ÚFunctionalModulezJ
    This is the callable object returned by :func:`make_functional`.
    rr   rs   .r3   r   Nc                 óL   •— t         ‰| �  «        || _        || _        || _        y rD   )rw   rx   rr   rs   r3   )r{   rr   rs   r3   r|   s       €r   rx   zFunctionalModule.__init__3  s'   ø€ ô 	‰ÑÔØ.ˆÔØ&ˆÔØ"ˆ�r   r[   r}   c                 óœ   — t        j                  | «      }t        |«      \  }}}|r|D ]  }|j                  d«       Œ t	        |||«      |fS r   )rc   rd   rA   r€   r–   )r[   r}   r�   r:   rs   r3   r‚   s          r   rƒ   zFunctionalModule._create_from>  sW   € ô
 —]‘] 5Ó)ˆ
Ü)8¸Ó)DÑ&ˆ�˜YÙ$Øò ,�Ø×$Ñ$ UÕ+ð,ä 
¨K¸ÓCÀVÐKÐKr   r:   c                 óø   — t        | j                  | j                  |«      }	  | j                  |i |¤Žt        | j                  | j                  |«       S # t        | j                  | j                  |«       w xY wrD   )rW   rr   r3   )r{   r:   r…   r†   r‡   s        r   rˆ   zFunctionalModule.forwardJ  sd   € ä × 4Ñ 4°d·n±nÀfÓMˆ	ð	IØ'�4×'Ñ'¨Ð8°Ñ8ô ˜×,Ñ,¨d¯n©n¸iÕHøŒK˜×,Ñ,¨d¯n©n¸iÕHús   £A Á#A9r‰   rŠ   r”   s   @r   r–   r–   .  s³   ø„ ñð	#àŸ™ð	#ð ˜3 ˜8‘_ð	#ð ˜˜T #™Y˜Ñ'ð		#ð
 
õ	#ð à<Añ	LØ�y‰yð	LØ59ð	Là	Ð! 5¨°¨Ñ#5Ð5Ñ	6ò	Ló ð	LðI˜h vÑ.ð IÀC÷ Ir   r–   r}   c                 ó”   — t        | j                  «       «      }t        |«      dkD  rt        d«      ‚t        j                  | |¬«      S )aÀ  make_functional(model, disable_autograd_tracking=False) -> func, params

    Given a ``torch.nn.Module``, :func:`make_functional` extracts the state
    (params) and returns a functional version of the model, ``func``. This
    makes it so that it is possible use transforms over the parameters of
    ``model``.

    ``func`` can be invoked as follows:

    .. code-block:: python

        import torch
        import torch.nn as nn
        from functorch import make_functional

        x = torch.randn(4, 3)
        model = nn.Linear(3, 3)
        func, params = make_functional(model)
        func(params, x)

    And here is an example of applying the grad transform over the parameters
    of a model.

    .. code-block:: python

        import torch
        import torch.nn as nn
        from functorch import make_functional, grad

        x = torch.randn(4, 3)
        t = torch.randn(4, 3)
        model = nn.Linear(3, 3)
        func, params = make_functional(model)

        def compute_loss(params, x, t):
            y = func(params, x)
            return nn.functional.mse_loss(y, t)

        grad_weights = grad(compute_loss)(params, x, t)

    If the model has any buffers, please use :func:`make_functional_with_buffers` instead.

    Args:
        model (torch.nn.Module): Input model.
        disable_autograd_tracking (bool): Flag to disable gradients tracking for output parameters.
            The returned params are unrelated to the set of params from the original model. If False (default),
            the params will have ``requires_grad=True`` on them (aka they will be trackable with regular
            PyTorch autograd), matching the requires_grad-ness of the params from the original model.
            Otherwise, the returned params will have ``requires_grad=False``. Default, False.
            If you plan on using regular PyTorch autograd (e.g., if you want to call ``.backward()`` or
            ``torch.autograd.grad()``, then set ``disable_autograd_tracking=False``.
            Otherwise, if you're only planning on using functorch's gradient transforms,
            then please set ``disable_autograd_tracking=True`` to avoid unnecessarily tracking
            history with PyTorch autograd.

    r   zdmake_functional(model): `model` has buffers. Please use make_functional_with_buffers(model) instead.©r}   )ri   rX   r/   r   r–   rƒ   )r[   r}   rX   s      r   Úmake_functionalrœ   T  sS   € ôv �5—=‘=“?Ó#€GÜ
ˆ7ƒ|�aÒÜð;ó
ð 	
ô ×(Ñ(ØÐ)Bð )ó ð r   c                 ó0   — t         j                  | |¬«      S )a¾  make_functional_with_buffers(model, disable_autograd_tracking=False) -> func, params, buffers

    Given a ``torch.nn.Module``, make_functional_with_buffers extracts the
    state (params and buffers) and returns a functional version of the model
    ``func`` that can be invoked like a function.

    ``func`` can be invoked as follows:

    .. code-block:: python

        import torch
        import torch.nn as nn
        from functorch import make_functional_with_buffers

        x = torch.randn(4, 3)
        model = nn.Linear(3, 3)
        func, params, buffers = make_functional_with_buffers(model)
        func(params, buffers, x)

    And here is an example of applying the grad transform over the parameters
    of a model:

    .. code-block:: python

        import torch
        import torch.nn as nn
        from functorch import make_functional_with_buffers, grad

        x = torch.randn(4, 3)
        t = torch.randn(4, 3)
        model = nn.Linear(3, 3)
        func, params, buffers = make_functional_with_buffers(model)

        def compute_loss(params, buffers, x, t):
            y = func(params, buffers, x)
            return nn.functional.mse_loss(y, t)

        grad_weights = grad(compute_loss)(params, buffers, x, t)

    Args:
        model (torch.nn.Module): Input model.
        disable_autograd_tracking (bool): Flag to disable gradients tracking for output parameters.
            The returned params are unrelated to the set of params from the original model. If False (default),
            the params will have ``requires_grad=True`` on them (aka they will be trackable with regular
            PyTorch autograd), matching the requires_grad-ness of the params from the original model.
            Otherwise, the returned params will have ``requires_grad=False``. Default, False.
            If you plan on using regular PyTorch autograd (e.g., if you want to call ``.backward()`` or
            ``torch.autograd.grad()``, then set ``disable_autograd_tracking=False``.
            Otherwise, if you're only planning on using functorch's gradient transforms,
            then please set ``disable_autograd_tracking=True`` to avoid unnecessarily tracking
            history with PyTorch autograd.

    r›   )rq   rƒ   )r[   r}   s     r   Úmake_functional_with_buffersrž   š  s#   € ôp '×3Ñ3ØÐ)Bð 4ó ð r   Útuple_of_tuple_of_tensorsc                 óL   — t        t        | Ž «      } t        d„ | D «       «      }|S )Nc              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrD   ©r,   ÚstackÚdetach©Ú.0Úshardss     r   ú	<genexpr>z"transpose_stack.<locals>.<genexpr>Û  s'   è ø€ ò Ø)/Œ�‰�FÓ×"Ñ"×$ñùó   ‚-/)r+   r0   )rŸ   Úresultss     r   Útranspose_stackr«   ×  s3   € ô !&¤cÐ+DÐ&EÓ FÐÜñ Ø3Lôó €Gð €Nr   Úmodelsc                 óz  ‡— t        | «      dk(  rt        d«      ‚t        d„ | D «       «      st        d„ | D «       «      st        d«      ‚t        | d   «      Št        ˆfd„| D «       «      st        d«      ‚t	        | D �cg c]  }t        |«      ‘Œ c}Ž \  }}}t        |«      }t        |«      }|d   ||fS c c}w )a(  combine_state_for_ensemble(models) -> func, params, buffers

    Prepares a list of torch.nn.Modules for ensembling with :func:`vmap`.

    Given a list of ``M`` ``nn.Modules`` of the same class, stacks all of their
    parameters and buffers together to make ``params`` and ``buffers``.
    Each parameter and buffer in the result will have an additional dimension
    of size ``M``.

    :func:`combine_state_for_ensemble` also returns ``func``, a functional
    version of one of the models in :attr:`models`. One cannot directly run
    ``func(params, buffers, *args, **kwargs)`` directly, you probably want to
    use ``vmap(func, ...)(params, buffers, *args, **kwargs)``

    Here's an example of how to ensemble over a very simple model:

    .. code-block:: python

        num_models = 5
        batch_size = 64
        in_features, out_features = 3, 3
        models = [torch.nn.Linear(in_features, out_features) for i in range(num_models)]
        data = torch.randn(batch_size, 3)

        fmodel, params, buffers = combine_state_for_ensemble(models)
        output = vmap(fmodel, (0, 0, None))(params, buffers, data)

        assert output.shape == (num_models, batch_size, out_features)

    .. warning::
        All of the modules being stacked together must be the same (except for
        the values of their parameters/buffers). For example, they should be in the
        same mode (training vs eval).

        This API is subject to change -- we're investigating better ways to
        create ensembles and would love your feedback how to improve this.
    r   z?combine_state_for_ensemble: Expected at least one model, got 0.c              3   ó4   K  — | ]  }|j                   –— Œ y ­wrD   ©Útraining©r¦   Úms     r   r¨   z-combine_state_for_ensemble.<locals>.<genexpr>  s   è ø€ Ò+˜q�—
•
Ñ+ùs   ‚c              3   ó6   K  — | ]  }|j                    –— Œ y ­wrD   r¯   r±   s     r   r¨   z-combine_state_for_ensemble.<locals>.<genexpr>  s   è ø€ Ò2RÀa°q·z±z´>Ñ2Rùs   ‚zTcombine_state_for_ensemble: Expected all models to have the same training/eval mode.c              3   ó:   •K  — | ]  }t        |«      ‰k(  –— Œ y ­wrD   )Útype)r¦   r²   Ú
model0_typs     €r   r¨   z-combine_state_for_ensemble.<locals>.<genexpr>  s   øè ø€ Ò5¨Œt�A‹w˜*Õ$Ñ5ùs   ƒzHcombine_state_for_ensemble: Expected all models to be of the same class.)r/   r   Úallrµ   r0   rž   r«   )r¬   r[   Úfuncsr:   rX   r¶   s        @r   Úcombine_state_for_ensembler¹   á  sÒ   ø€ ôP ˆ6ƒ{�aÒÜØMó
ð 	
ô Ñ+ FÔ+Ô+¬sÑ2RÈ6Ô2RÔ/RÜð0ó
ð 	
ô �f˜Q‘i“€JÜÓ5¨fÔ5Ô5ÜØVó
ð 	
ô !Ø;AÖ	B°%Ô
& uÕ
-Ò	BðÑ€Eˆ6�7ô ˜VÓ$€FÜ˜gÓ&€GØ�‰8�V˜WÐ$Ð$ùò	 
Cs   Â B8Úmodel_classÚensemble_shaper)   c                 ó   ‡ ‡‡— ˆˆˆ fd„}|S )Nc                  óª  •‡ ‡— t        ‰
«      dk\  rt        d«      ‚t        ‰
«      dk(  r" ‰‰ i ‰¤Žj                  ‰	«      }t        |«      S ‰
d   }|dk  rt        d|› d�«      ‚t	        ˆ ˆ	ˆˆfd„t        |«      D «       «      }t         ‰‰ i ‰¤Ž«      \  }}}t	        d„ |D «       «      }t	        t        |Ž «      }t	        d„ |D «       «      }|||fS )	Né   ú,NYI: ensemble_shape with more than 1 elementr   únum_models ú should be > 0c              3   óL   •K  — | ]  } ‰‰i ‰¤Žj                  ‰«      –— Œ y ­wrD   ©Úto©r¦   rR   r…   r)   r†   rº   s     €€€€r   r¨   z3functional_init.<locals>.wrapped.<locals>.<genexpr>.  ó+   øè ø€ ò 
Ø89‰K˜Ð( Ñ(×+Ñ+¨F×3ñ
ùó   ƒ!$c              3   ó8   K  — | ]  }t        |«      d    –— Œ y­w)r   N)rj   ©r¦   r[   s     r   r¨   z3functional_init.<locals>.wrapped.<locals>.<genexpr>2  s   è ø€ ÒTÀEÔ5°eÓ<¸QÕ?ÑTùó   ‚c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrD   r¢   r¥   s     r   r¨   z3functional_init.<locals>.wrapped.<locals>.<genexpr>4  ó"   è ø€ ÒK¸œŸ™ FÓ+×2Ñ2×4ÑKùr©   )r/   Ú
ValueErrorrÄ   rj   r+   Úranger0   )r…   r†   r[   Ú
num_modelsr¬   rR   Úfnr9   r\   r)   r»   rº   s   ``       €€€r   Úwrappedz functional_init.<locals>.wrapped$  sæ   ú€ Üˆ~Ó !Ò#ÜÐKÓLÐLÜˆ~Ó !Ò#Ù Ð0¨Ñ0×3Ñ3°FÓ;ˆEÜ0°Ó7Ð7Ø# AÑ&ˆ
Ø˜Š?Ü˜{¨:¨,°nÐEÓFÐFäö 
Ü=BÀ:Ó=Nô
ó 
ˆô 5±[À$Ð5QÈ&Ñ5QÓR‰ˆˆ2ˆuÜÑTÈVÔTÓTˆÜœ˜W˜Ó&ˆÜÑKÀ7ÔKÓKˆØ˜˜EÐ!Ð!r   r   ©rº   r»   r)   rÑ   s   ``` r   Úfunctional_initrÓ     s   ú€ ö
"ð& €Nr   c                 ó   ‡ ‡‡— ˆˆˆ fd„}|S )Nc                  ó
  •‡ ‡— t        ‰«      dk\  rt        d«      ‚t        ‰«      dk(  r" ‰‰ i ‰¤Žj                  ‰«      }t        |«      S ‰d   }|dk  rt        d|› d�«      ‚t	        ˆ ˆˆˆfd„t        |«      D «       «      }t         ‰‰ i ‰¤Ž«      \  }}}}}t        t	        d„ |D «       «      Ž \  }	}
t	        t        |	Ž «      }	t	        d„ |	D «       «      }	t	        t        |
Ž «      }
t	        d	„ |
D «       «      }
|	|
|||fS )
Nr¾   r¿   r   rÀ   rÁ   c              3   óL   •K  — | ]  } ‰‰i ‰¤Žj                  ‰«      –— Œ y ­wrD   rÃ   rÅ   s     €€€€r   r¨   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>I  rÆ   rÇ   c              3   ó8   K  — | ]  }t        |«      d d –— Œ y ­w)Nr¾   )ro   rÉ   s     r   r¨   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>T  s$   è ø€ ò àô ;¸5ÓAÀ"À1ÔEñùrÊ   c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrD   r¢   r¥   s     r   r¨   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>Z  rÌ   r©   c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrD   r¢   r¥   s     r   r¨   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>\  rÌ   r©   )r/   rÍ   rÄ   rj   r+   rÎ   ro   r0   )r…   r†   r[   rÏ   r¬   rR   rÐ   r]   r^   r\   rX   r)   r»   rº   s   ``         €€€r   rÑ   z-functional_init_with_buffers.<locals>.wrapped?  s*  ú€ Üˆ~Ó !Ò#ÜÐKÓLÐLÜˆ~Ó !Ò#Ù Ð0¨Ñ0×3Ñ3°FÓ;ˆEÜ0°Ó7Ð7Ø# AÑ&ˆ
Ø˜Š?Ü˜{¨:¨,°nÐEÓFÐFäö 
Ü=BÀ:Ó=Nô
ó 
ˆô 7±{ÀDÐ7SÈFÑ7SÓTñ	
ØØØØØäÜñ à#ôó ð
Ñˆ�ô œ˜W˜Ó&ˆÜÑKÀ7ÔKÓKˆÜœ˜W˜Ó&ˆÜÑKÀ7ÔKÓKˆØ˜  \°<Ð?Ð?r   r   rÒ   s   ``` r   Úfunctional_init_with_buffersrÚ   :  s   ú€ ö
@ð@ €Nr   r‰   r*   )r   Úcpu),rc   Úcollections.abcr   r   Útypingr   r   r   r   r,   Útorch.nnr>   r	   Ú%torch.nn.utils._named_member_accessorr
   r   r   r�   r+   ri   r"   r�   r;   rA   rH   r’   rL   rW   rZ   r`   rj   ro   rq   r–   rœ   rž   r«   r¹   rµ   ÚintÚtypesÚDevicerÓ   rÚ   r   r   r   ú<module>rã      sœ  ðó ß .ß 1Ó 1ã Ý Ý Ý Eð Xó ð,Ø˜˜S &˜[Ñ)¨8°E¸#¸v¸+Ñ4FÑ+GÐGÑHð,à˜T # v +Ñ.°¸¸sÀF¸{Ñ9KÑ0LÐLÑMð,ð 
ˆ#ˆt�C‰yˆ.Ñó,ð8$Ø	�‰ð$à˜C ¨%°°V°Ñ*<Ñ!=Ð=Ñ>ð$ð ˜�x Ð'Ñ(ð$ð ˆ5�˜�Ñ˜u S¨# X™°°S¸$¸s¹)°^Ñ0DÐDÑEó	$ð2EØ	�‰ðEà
ˆ5�˜�Ñ˜u S¨# X™°°S¸$¸s¹)°^Ñ0DÐDÑEóEðAØ	�‰ðAà
ˆ5�˜�Ñ˜u S¨# X™°°S¸$¸s¹)°^Ñ0DÐDÑEóAð ñ	(Ø	�‰ð(à�C‰=ð(ð �VÑð(ð ð	(ð
 
ó(ð"Ø	�‰ðØ# C¨¨c© NÑ3ðØ<DÀVÑ<Lðà	ˆ&�\óð$ ñ	)Ø	�‰ð)à�C‰=ð)ð �fÑð)ð ð	)ð
 
ó)ð !#Ø"$ñØ�9‰9ðà�fÑðð ˜3‘-ðð �fÑð	ð
 ˜3‘-ðð ‡Y�Yóð('%¨¯©ó '%ðT"F°b·i±ió "FôJ5M "§)¡)ô 5Môp#I�r—y‘yô #IðN 9>ñCØ�9‰9ðCØ15ðCà
Ð˜U 6¨3 ;Ñ/Ð/Ñ0óCðN 9>ñ:Ø�9‰9ð:Ø15ð:à
Ð&¨¨f°c¨kÑ(:¸EÀ&È#À+Ñ<NÐNÑOó:ðzØ$ U¨6°3¨;Ñ%7¸Ð%<Ñ=ðà
ˆ6�3ˆ;Ñóð;%Ø�R—Y‘YÑð;%à
Ð&¨¨f°c¨kÑ(:¸EÀ&È#À+Ñ<NÐNÑOó;%ð@ 46Ø!&ñØ�b—i‘i‘ðà˜% ™) U¨3¡ZÐ/Ñ0ðð �K‰K×Ñóð: 46Ø!&ñ%Ø�b—i‘i‘ð%à˜% ™) U¨3¡ZÐ/Ñ0ð%ð �K‰K×Ñô%r   