Ë
    P/æjY  ã                   ó´  — d dl Z d dlmZmZmZmZmZmZ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	 d2d
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	 d2d
ej*                  dee   dee   deddf
d„Z	 	 d3d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!	 d2dej*                  d&ede	e!e	edf   f   fd'„Z"	 d2d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%	 	 d4d-e
ej*                     d.ee	d   e	e&   f   d/ejN                  jP                  fd0„Z)	 	 d4d-e
ej*                     d.ee	d   e	e&   f   d/ejN                  jP                  fd1„Z*y)5é    N)
ÚAnyÚCallableÚDictÚIterableÚListÚNoReturnÚSequenceÚTupleÚTypeÚ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© ó    úc/root/repos/pocs/video-evals/.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?   G   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_weightsrE   `   s   € ô ˜C ×!5Ñ!5´r·|±|ÓDÐDr   c                 ó2   — t        | | j                  d„ «      S )Nc                 ó   — | S ©Nr   )Úxs    r   ú<lambda>z!extract_buffers.<locals>.<lambda>q   s   € ¸a€ r   )r?   Únamed_buffersrD   s    r   Úextract_buffersrL   n   s   € ô ˜C ×!2Ñ!2±KÓ@Ð@r   r=   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   rB   rC   Úset_tensors)r'   r=   r>   rM   r9   r;   s         r   Úload_weightsrP   t   sA   € ô # 3Ó'€HÙØ+1Ö2 a”"—,‘,˜q•/Ð2ˆÐ2Ø×Ñ˜ Õ'ùò 3s   ’Ar7   Úelemsc                 ó  — g }t        | «      }t        |j                  «       |«      D ]T  \  \  }}}t        |«      D ]>  \  }}	|dk(  r"|j	                  |j                  |	|«      «       Œ-|j                  |	|«       Œ@ ŒV |S )Nr   )r   r4   r   Ú	enumerater   Úswap_tensorr2   )
r'   r7   rQ   Úresultr9   Ú_Ú
attr_namesÚelemÚiÚ	attr_names
             r   Ú_swap_stater[   …   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 rH   )r   rO   )r'   r=   r\   rM   r9   s        r   Úload_buffersr^   “   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   )r3   rP   r^   )r_   r`   ra   r\   rb   s        r   Ú
load_staterd   �   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 rH   )ÚcopyÚdeepcopyrP   )r`   ÚdataÚmutable_modelÚdescriptorsr_   s      €€r   Úfunz*make_functional_deprecated_v1.<locals>.funÓ   s(   ø€ ÜŸ™ eÓ,ˆÜ�] K°Ô9Ù˜dÐ#Ð#r   )Úlistr\   r3   r   rE   )r_   r\   r`   rV   rl   rk   s   `    @r   Úmake_functional_deprecated_v1rn   ±   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 rH   )rg   rh   rP   r^   )r`   r\   ri   rj   Úbuf_descriptorsr_   Úweight_descriptorss       €€€r   rl   z7make_functional_with_buffers_deprecated_v1.<locals>.fun÷   s5   ø€ ÜŸ™ eÓ,ˆÜ�]Ð$6¸Ô@Ü�] O°WÔ=Ù˜dÐ#Ð#r   )rE   rL   )r_   r`   rV   r\   rl   rq   rr   s   `    @@r   Ú*make_functional_with_buffers_deprecated_v1rs   Û   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.rb   Úparam_names_mapÚbuffer_names_mapr   Nc                 ó¢   •— t         ‰| �  «        || _        || _        || _        t        |«      | _        | j                  j                  |«       y rH   )ÚsuperÚ__init__rv   rw   rb   r   Úall_names_mapÚupdate)Úselfrv   rw   rb   rx   ry   Ú	__class__s         €r   r|   z$FunctionalModuleWithBuffers.__init__  sJ   ø€ ô 	‰ÑÔØ.ˆÔØ&ˆÔØ(ˆÔä! /Ó2ˆÔØ×Ñ×!Ñ!Ð"2Õ3r   r_   Údisable_autograd_trackingc                 óÀ   — t        j                  | «      }t        |«      \  }}}t        |«      \  }}}|r|D ]  }	|	j	                  d«       Œ t        |||||«      ||fS ©NF)rg   rh   rE   rL   Úrequires_grad_ru   )
r_   r�   Ú
model_copyr>   rw   rx   r\   rb   ry   Úparams
             r   Ú_create_fromz(FunctionalModuleWithBuffers._create_from  s}   € ô
 —]‘] 5Ó)ˆ
Ü/>¸zÓ/JÑ,ˆ�˜_Ü2AÀ*Ó2MÑ/ˆ�Ð/Ù$Øò ,�Ø×$Ñ$ UÕ+ð,ô (Ø˜K¨°ÐHXóð Øð
ð 	
r   r>   r\   c                 ó"  — t        | j                  | j                  t        |«      t        |«      z   «      }	  | j                  |i |¤Žt        | j                  | j                  |«       S # t        | j                  | j                  |«       w xY wrH   )r[   rv   r}   r/   )r   r>   r\   Ú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__rB   ÚModuler
   Ústrr   r   r|   ÚstaticmethodÚboolr   r‡   r   r   rŒ   Ú__classcell__©r€   s   @r   ru   ru      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   ru   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`.
    rv   rw   .r7   r   Nc                 óL   •— t         ‰| �  «        || _        || _        || _        y rH   )r{   r|   rv   rw   r7   )r   rv   rw   r7   r€   s       €r   r|   zFunctionalModule.__init__=  s'   ø€ ô 	‰ÑÔØ.ˆÔØ&ˆÔØ"ˆ�r   r_   r�   c                 óœ   — t        j                  | «      }t        |«      \  }}}|r|D ]  }|j                  d«       Œ t	        |||«      |fS rƒ   )rg   rh   rE   r„   rš   )r_   r�   r…   r>   rw   r7   r†   s          r   r‡   zFunctionalModule._create_fromH  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rH   )r[   rv   r7   )r   r>   r‰   rŠ   r‹   s        r   rŒ   zFunctionalModule.forwardT  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š   8  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�   )rm   r\   r3   r   rš   r‡   )r_   r�   r\   s      r   Úmake_functionalr    ^  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Ÿ   )ru   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rH   ©r0   ÚstackÚdetach©Ú.0Úshardss     r   ú	<genexpr>z"transpose_stack.<locals>.<genexpr>å  s'   è ø€ ò Ø)/Œ�‰�FÓ×"Ñ"×$ñùó   ‚-/)r/   r4   )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rH   ©Útraining©rª   Úms     r   r¬   z-combine_state_for_ensemble.<locals>.<genexpr>  s   è ø€ Ò+˜q�—
•
Ñ+ùs   ‚c              3   ó6   K  — | ]  }|j                    –— Œ y ­wrH   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rH   )Ú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.)r3   r   Úallr¹   r4   r¢   r¯   )r°   r_   Úfuncsr>   r\   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rH   ©Úto©rª   rV   r‰   r-   rŠ   r¾   s     €€€€r   r¬   z3functional_init.<locals>.wrapped.<locals>.<genexpr>8  ó+   øè ø€ ò 
Ø89‰K˜Ð( Ñ(×+Ñ+¨F×3ñ
ùó   ƒ!$c              3   ó8   K  — | ]  }t        |«      d    –— Œ y­w)r   N)rn   ©rª   r_   s     r   r¬   z3functional_init.<locals>.wrapped.<locals>.<genexpr><  s   è ø€ ÒTÀEÔ5°eÓ<¸QÕ?ÑTùó   ‚c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrH   r¦   r©   s     r   r¬   z3functional_init.<locals>.wrapped.<locals>.<genexpr>>  ó"   è ø€ ÒK¸œŸ™ FÓ+×2Ñ2×4ÑKùr­   )r3   Ú
ValueErrorrÈ   rn   r/   Úranger4   )r‰   rŠ   r_   Ú
num_modelsr°   rV   Úfnr=   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rH   rÇ   rÉ   s     €€€€r   r¬   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>S  rÊ   rË   c              3   ó8   K  — | ]  }t        |«      d d –— Œ y ­w)NrÂ   )rs   rÍ   s     r   r¬   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>^  s$   è ø€ ò àô ;¸5ÓAÀ"À1ÔEñùrÎ   c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrH   r¦   r©   s     r   r¬   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>d  rÐ   r­   c              3   ób   K  — | ]'  }t        j                  |«      j                  «       –— Œ) y ­wrH   r¦   r©   s     r   r¬   z@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>f  rÐ   r­   )r3   rÑ   rÈ   rn   r/   rÒ   rs   r4   )r‰   rŠ   r_   rÓ   r°   rV   rÔ   ra   rb   r`   r\   r-   r¿   r¾   s   ``         €€€r   rÕ   z-functional_init_with_buffers.<locals>.wrappedI  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Þ   D  s   ú€ ö
@ð@ €Nr   r�   r.   )r   Úcpu)+rg   Útypingr   r   r   r   r   r   r	   r
   r   r   r0   Útorch.nnrB   r   Ú%torch.nn.utils._named_member_accessorr   r   r”   r&   r“   r?   rE   rL   r–   rP   r[   r^   rd   rn   rs   ru   rš   r    r¢   r¯   r½   ÚintÚtypesÚDevicer×   rÞ   r   r   r   ú<module>ræ      s¤  ðó ÷÷ ÷ ó Ý Ý Ý 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   