ó
    Eñi¬_  ã                  ón  • S SK Jr  S SKrS SKJrJrJr  S SKrS SKJ	r	  S SKJ
r
  S SKJr  \(       a
  S SKJrJrJr  SS jr      SS jr        SS	 jr    SS
 jr    SS jr S          S!S jjr        S"S jr S          S#S jjr  S$           S%S jjr    S&S jr    S'S jr " S S\	R8                  5      r " S S\	R8                  5      r S      S(S jjr S      S)S jjr     S*S jr!    S+S jr"  S,       S-S jjr#  S,       S.S jjr$g)/é    )ÚannotationsN)ÚAnyÚNoReturnÚTYPE_CHECKING)ÚTensor)ÚNamedMemberAccessor)ÚCallableÚIterableÚSequencec                 ó   • [        S5      e)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© ó    Ú]/home/mande/repo/quber/.venv/lib/python3.13/site-packages/torch/_functorch/make_functional.pyÚraise_parameter_tying_errorr      s   € Ü
ð	:óð r   c                óÚ  • [        U 5      n[        U5      n[        UR                  5       5      n[        UR                  5       5      nUR                  U5      (       d  [	        SU SU 35      e0 nUR                  5        H  u  pxU/ 4Xh'   M     UR                  5        H/  u  pxX†;  a  [	        SU S35      eXh   S   R                  U5        M1     [        UR                  5       5      $ )aC  
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']}.
ztensors_dict_keys z+ is not a subset of tied_tensors_dict_keys ztensor for key 'z ' not found in tensor_to_mappingé   )ÚdictÚsetÚkeysÚissubsetÚAssertionErrorÚitemsÚappendÚvalues)	Únamed_paramsÚtied_named_paramsÚnamed_params_dictÚtied_named_params_dictÚtensors_dict_keysÚtied_tensors_dict_keysÚtensor_to_mappingÚkeyÚtensors	            r   Úcreate_names_mapr%   $   s  € ô ˜\Ó*ÐÜ!Ð"3Ó4ÐäÐ-×2Ñ2Ó4Ó5ÐÜ Ð!7×!<Ñ!<Ó!>Ó?ÐØ×%Ñ%Ð&<×=Ñ=ÜØ Ð!2Ð 3ð 4&Ø&<Ð%=ð?ó
ð 	
ð
 >@ÐØ(×.Ñ.Ö0‰ˆØ%(¨" IÐÓ!ñ 1à-×3Ñ3Ö5‰ˆØÓ*Ü Ø" 3 %Ð'GÐHóð ð 	Ñ! !Ñ$×+Ñ+¨CÖ0ñ 6ô Ð!×(Ñ(Ó*Ó+Ð+r   c                ó6  • [        U" SS95      n[        U" SS95      n[        XC5      n0 n[        U 5      nU H<  u  p‰X–;  a  U" [        R                  " U	SS95      Xi'   Xi   n
UR                  XŠ5        M>     [        U5      S:X  a  Su  p¼O
[        U6 u  p¼XËU4$ )NF)Úremove_duplicateTÚmeta)Údevicer   ©r   r   )Útupler%   r   ÚtorchÚ
empty_likeÚ
set_tensorÚlenÚzip)ÚmodÚnamed_membersÚsubclassÚ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ÓI€Ið €DÜ" 3Ó'€HÛ$‰ˆØ‹=Ùœu×/Ò/°¸&ÑAÓBˆD‰GØ‘gˆØ×Ñ˜DÖ.ñ	 %ô ÐÓ  AÓ%Ø‰ˆˆväÐ1Ð2‰ˆØ˜)Ð#Ð#r   c                óJ   • [        X R                  [        R                  5      $ )a>  
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©r1   s    r   Úextract_weightsrD   a   s   € ô ˜C×!5Ñ!5´r·|±|ÓDÐDr   c                ó0   • [        X R                  S 5      $ )Nc                ó   • U $ ©Nr   )Úxs    r   Ú<lambda>Ú!extract_buffers.<locals>.<lambda>r   s   € ¹ar   )r>   Únamed_buffersrC   s    r   Úextract_buffersrL   o   s   € ô ˜C×!2Ñ!2±KÓ@Ð@r   c                ó    • [        U 5      nU(       a&  U Vs/ s H  n[        R                  " U5      PM     nnUR                  X5        gs  snf )zù
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   rA   rB   Úset_tensors)r1   r<   r=   Ú	as_paramsr8   r:   s         r   Úload_weightsrP   u   s@   € ô # 3Ó'€HÞÙ+1Ó2ª6 a”"—,’,˜q–/©6ˆÐ2Ø×Ñ˜Õ'ùò 3s   — Ac                ó  • / n[        U 5      n[        UR                  5       U5       HU  u  u  pVn[        U5       H>  u  p‰US:X  a"  UR	                  UR                  X—5      5        M-  UR                  X—5        M@     MW     U$ )Nr   )r   r0   r   Ú	enumerater   Úswap_tensorr.   )
r1   r6   ÚelemsÚresultr8   Ú_Ú
attr_namesÚelemÚiÚ	attr_names
             r   Ú_swap_stater[   †   sv   € ð €FÜ" 3Ó'€HÜ!$ Y§_¡_Ó%6¸Ö!>Ñ‰ˆ˜Ü% jÖ1‰LˆAØ�A‹vØ—‘˜h×2Ñ2°9ÓCÖDà×#Ñ# IÖ4ó	 2ñ "?ð €Mr   c                ó<   • [        U 5      nUR                  X5        g rG   )r   rN   )r1   r<   ÚbuffersrO   r8   s        r   Úload_buffersr^   ”   s   € ô # 3Ó'€HØ×Ñ˜Õ(r   c                ó@  • [        U5      [        U5      :w  a#  [        S[        U5       S[        U5       35      e[        XU5        [        U5      S:”  aG  [        U5      [        U5      :w  a#  [        S[        U5       S[        U5       35      e[        XU5        U $ )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`.
zlen(weight_names)=z != len(weights)=r   zlen(buffer_names)=z != len(buffers)=)r/   r   rP   r^   )ÚmodelÚweightsÚweight_namesr]   Úbuffer_namess        r   Ú
load_staterd   ž   sŸ   € ô ˆ<ÓœC ›LÓ(ÜØ ¤ \Ó!2Ð 3Ð3DÄSÈÃ\ÀNÐSó
ð 	
ô � gÔ.Ü
ˆ7ƒ|�aÓÜˆ|Ó¤ G£Ó,Ü Ø$¤S¨Ó%6Ð$7Ð7HÌÈWËÈÐWóð ô 	�U¨'Ô2Ø€Lr   c                ó¤   ^ ^• [        T R                  5       5      n[        U5      S:”  a  [        S5      e[	        T 5      u  nmnSUU 4S jjnX$T4$ )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                óT   >• [         R                  " T5      n[        UTU 5        U" U6 $ rG   )ÚcopyÚdeepcopyrP   )ra   ÚdataÚmutable_modelÚdescriptorsr`   s      €€r   ÚfunÚ*make_functional_deprecated_v1.<locals>.funÜ   s(   ø€ ÜŸš eÓ,ˆÜ�] K°Ô9Ù˜dÐ#Ð#r   )ra   útuple[Tensor, ...]ri   útuple[Any, ...]Úreturnr   )Úlistr]   r/   r   rD   )r`   r]   ra   rV   rl   rk   s   `    @r   Úmake_functional_deprecated_v1rr   ¸   s^   ù€ ô8 �5—=‘=“?Ó#€GÜ
ˆ7ƒ|�aÓÜðIó
ð 	
ô .¨eÓ4Ñ€Gˆ[˜!÷$ð $ð
 ˜Ð$Ð$r   c                ót   ^ ^^• [        T 5      u  nmn[        T 5      u  nmn        SUU U4S jjnXUTT4$ )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                ón   >• [         R                  " T5      n[        UTU 5        [        UTU5        U" U6 $ rG   )rg   rh   rP   r^   )ra   r]   ri   rj   Úbuf_descriptorsr`   Úweight_descriptorss       €€€r   rl   Ú7make_functional_with_buffers_deprecated_v1.<locals>.fun  s7   ø€ ô
 Ÿš eÓ,ˆÜ�]Ð$6¸Ô@Ü�] O°WÔ=Ù˜dÐ#Ð#r   )ra   rn   r]   rn   ri   ro   rp   r   )rD   rL   )r`   ra   rV   r]   rl   ru   rv   s   `    @@r   Ú*make_functional_with_buffers_deprecated_v1rx   ä   si   ú€ ôB &5°UÓ%;Ñ"€GÐ Ü"1°%Ó"8Ñ€Gˆ_˜að$Ø#ð$à#ð$ð ð$ð 
÷	$ñ $ð ˜SÐ"4°oÐEÐEr   c                  óŠ   ^ • \ rS rSrSr            SU 4S jjr\ S     S	S jj5       r          S
S jrSr	U =r
$ )ÚFunctionalModuleWithBuffersi  zO
This is the callable object returned by :func:`make_functional_with_buffers`.
c                óœ   >• [         TU ]  5         Xl        X l        X0l        [        U5      U l        U R                  R                  U5        g rG   )ÚsuperÚ__init__Ústateless_modelÚparam_namesrc   r   Úall_names_mapÚupdate)Úselfr~   r   rc   Úparam_names_mapÚbuffer_names_mapÚ	__class__s         €r   r}   Ú$FunctionalModuleWithBuffers.__init__  sD   ø€ ô 	‰ÑÔØ.ÔØ&ÔØ(Ôä! /Ó2ˆÔØ×Ñ×!Ñ!Ð"2Õ3r   c                óÈ   • [         R                  " U 5      n[        U5      u  p4n[        U5      u  pgnU(       a  U H  n	U	R	                  S5        M     [        X$XuU5      UU4$ ©NF)rg   rh   rD   rL   Úrequires_grad_rz   )
r`   Údisable_autograd_trackingÚ
model_copyr=   r   rƒ   r]   rc   r„   Úparams
             r   Ú_create_fromÚ(FunctionalModuleWithBuffers._create_from*  sp   € ô
 —]’] 5Ó)ˆ
Ü/>¸zÓ/JÑ,ˆ˜_Ü2AÀ*Ó2MÑ/ˆÐ/Þ$Û�Ø×$Ñ$ UÖ+ñ  ô (Ø¨ÐHXóð Øð
ð 	
r   c                ó"  • [        U R                  U R                  [        U5      [        U5      -   5      n U R                  " U0 UD6[        U R                  U R                  U5        $ ! [        U R                  U R                  U5        f = frG   )r[   r~   r€   r+   )r‚   r=   r]   ÚargsÚkwargsÚ	old_states         r   ÚforwardÚ#FunctionalModuleWithBuffers.forward=  s|   € ô  Ø× Ñ Ø×ÑÜ�&‹MœE '›NÑ*ó
ˆ	ð
	MØ×'Ò'¨Ð8°Ñ8ô ˜×,Ñ,¨d×.@Ñ.@À)ÕLøŒK˜×,Ñ,¨d×.@Ñ.@À)ÕLús   ¸A+ Á+#B)r€   rc   r   r~   )r~   ú	nn.Moduler   útuple[str, ...]rc   r–   rƒ   údict[str, list[str]]r„   r—   rp   ÚNone©F©r`   r•   rŠ   Úboolrp   úJtuple[FunctionalModuleWithBuffers, tuple[Tensor, ...], tuple[Tensor, ...]])
r=   úIterable[Tensor]r]   r�   r�   r   r‘   r   rp   r   ©Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r}   Ústaticmethodr�   r“   Ú__static_attributes__Ú__classcell__©r…   s   @r   rz   rz     s·   ø† ñð4à"ð4ð %ð4ð &ð	4ð
 .ð4ð /ð4ð 
÷4ð  à<Að
Øð
Ø59ð
à	Sô
ó ð
ð$Mà ðMð "ðMð ð	Mð
 ðMð 
÷Mò Mr   rz   c                  ón   ^ • \ rS rSrSr        SU 4S jjr\ S     S	S jj5       rS
S jrSr	U =r
$ )ÚFunctionalModuleiQ  zB
This is the callable object returned by :func:`make_functional`.
c                óF   >• [         TU ]  5         Xl        X l        X0l        g rG   )r|   r}   r~   r   r6   )r‚   r~   r   r6   r…   s       €r   r}   ÚFunctionalModule.__init__V  s!   ø€ ô 	‰ÑÔØ.ÔØ&ÔØ"�r   c                ó¨   • [         R                  " U 5      n[        U5      u  p4nU(       a  U H  nUR                  S5        M     [	        X$U5      U4$ rˆ   )rg   rh   rD   r‰   r©   )r`   rŠ   r‹   r=   r   r6   rŒ   s          r   r�   ÚFunctionalModule._create_froma  sN   € ô
 —]’] 5Ó)ˆ
Ü)8¸Ó)DÑ&ˆ˜YÞ$Û�Ø×$Ñ$ UÖ+ñ  ä 
¸ÓCÀVÐKÐKr   c                óø   • [        U R                  U R                  U5      n U R                  " U0 UD6[        U R                  U R                  U5        $ ! [        U R                  U R                  U5        f = frG   )r[   r~   r6   )r‚   r=   r�   r‘   r’   s        r   r“   ÚFunctionalModule.forwardm  sb   € ä × 4Ñ 4°d·n±nÀfÓMˆ	ð	IØ×'Ò'¨Ð8°Ñ8ô ˜×,Ñ,¨d¯n©n¸iÕHøŒK˜×,Ñ,¨d¯n©n¸iÕHús   £A Á#A9)r6   r   r~   )r~   r•   r   r–   r6   r—   rp   r˜   r™   ©r`   r•   rŠ   r›   rp   z+tuple[FunctionalModule, tuple[Tensor, ...]])r=   r�   r�   r   r‘   r   rp   r   rž   r§   s   @r   r©   r©   Q  ss   ø† ñð	#à"ð	#ð %ð	#ð (ð		#ð
 
÷	#ð à<Að	LØð	LØ59ð	Là	4ô	Ló ð	L÷Iò Ir   r©   c                óŽ   • [        U R                  5       5      n[        U5      S:”  a  [        S5      e[        R                  XS9$ )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Š   )rq   r]   r/   r   r©   r�   )r`   rŠ   r]   s      r   Úmake_functionalr³   w  sP   € ôz �5—=‘=“?Ó#€GÜ
ˆ7ƒ|�aÓÜð;ó
ð 	
ô ×(Ñ(Øð )ð ð r   c                ó(   • [         R                  XS9$ )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²   )rz   r�   )r`   rŠ   s     r   Úmake_functional_with_buffersrµ   ¿  s    € ôt '×3Ñ3Øð 4ð ð r   c                óL   • [        [        U 6 5      n [        S U  5       5      nU$ )Nc              3  ój   #   • U  H)  n[         R                  " U5      R                  5       v •  M+     g 7frG   ©r,   ÚstackÚdetach©Ú.0Úshardss     r   Ú	<genexpr>Ú"transpose_stack.<locals>.<genexpr>  s)   é € ð Ú3L¨Œ�Š�FÓ×"Ñ"×$Ð$Ò3Lùó   ‚13)r+   r0   )Útuple_of_tuple_of_tensorsÚresultss     r   Útranspose_stackrÃ   þ  s3   € ô !&¤cÐ+DÐ&EÓ FÐÜñ Ù3Lóó €Gð €Nr   c                óž  ^• [        U 5      S:X  a  [        S5      e[        S U  5       5      (       d"  [        S U  5       5      (       d  [        S5      e[        U S   5      m[        U4S jU  5       5      (       d  [        S5      e[	        U  Vs/ s H  n[        U5      PM     sn6 u  p#n[        U5      n[        U5      nUS   X44$ s  snf )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  ó8   #   • U  H  oR                   v •  M     g 7frG   ©Útraining©r¼   Úms     r   r¾   Ú-combine_state_for_ensemble.<locals>.<genexpr>4  s   é € Ð+¢F˜q—
–
¢Fùs   ‚c              3  óB   #   • U  H  oR                   (       + v •  M     g 7frG   rÆ   rÈ   s     r   r¾   rÊ   4  s   é € Ð2RÊ6Àa·z±z·>±>Ê6ùs   ‚zTcombine_state_for_ensemble: Expected all models to have the same training/eval mode.c              3  ó>   >#   • U  H  n[        U5      TL v •  M     g 7frG   )Útype)r¼   rÉ   Ú
model0_typs     €r   r¾   rÊ   :  s   øé € Ð5ªf¨Œt�A‹w˜*Õ$ªfùs   ƒzHcombine_state_for_ensemble: Expected all models to be of the same class.)r/   r   ÚallrÍ   r0   rµ   rÃ   )Úmodelsr`   Úfuncsr=   r]   rÎ   s        @r   Úcombine_state_for_ensemblerÒ     sÛ   ø€ ôP ˆ6ƒ{�aÓÜØMó
ð 	
ô Ñ+¡FÓ+×+Ñ+¬sÑ2RÉ6Ó2R×/RÑ/RÜð0ó
ð 	
ô �f˜Q‘i“€JÜÔ5©fÓ5×5Ñ5ÜØVó
ð 	
ô !Ù;AÓ	Bº6°%Ô
& uÖ
-¹6Ñ	BðÑ€E�7ô ˜VÓ$€FÜ˜gÓ&€GØ�‰8�VÐ$Ð$ùò	 
Cs   ÂC
c                ó,   ^ ^^•       SUUU 4S jjnU$ )Nc                 ó®  >^ ^• [        T
5      S:¼  a  [        S5      e[        T
5      S:X  a"  T" T 0 TD6R                  T	5      n[        U5      $ T
S   nUS::  a  [        SU S35      e[	        U U	UU4S j[        U5       5       5      n[        T" T 0 TD65      u  pVn[	        S U 5       5      n[	        [        U6 5      n[	        S U 5       5      nX†U4$ )	Né   ú,NYI: ensemble_shape with more than 1 elementr   únum_models ú should be > 0c              3  óR   >#   • U  H  nT" T0 TD6R                  T5      v •  M     g 7frG   ©Úto©r¼   rV   r�   r)   r‘   Úmodel_classs     €€€€r   r¾   Ú3functional_init.<locals>.wrapped.<locals>.<genexpr>W  ó-   øé € ð 
Ú=N¸‰K˜Ð( Ñ(×+Ñ+¨F×3Ð3Ò=Nùó   ƒ$'c              3  ó>   #   • U  H  n[        U5      S    v •  M     g7f)r   N)rr   ©r¼   r`   s     r   r¾   rÞ   [  s   é € ÐTÊVÀEÔ5°eÓ<¸QÖ?ÊVùó   ‚c              3  ój   #   • U  H)  n[         R                  " U5      R                  5       v •  M+     g 7frG   r¸   r»   s     r   r¾   rÞ   ]  ó%   é € ÐKÂ7¸œŸš FÓ+×2Ñ2×4Ð4Â7ùrÀ   )r/   Ú
ValueErrorrÛ   rr   r+   Úranger0   )r�   r‘   r`   Ú
num_modelsrÐ   rV   Úfnr<   ra   r)   Úensemble_shaperÝ   s   ``       €€€r   ÚwrappedÚ functional_init.<locals>.wrappedK  sä   ú€ ô ˆ~Ó !Ó#ÜÐKÓLÐLÜˆ~Ó !Ó#Ù Ð0¨Ñ0×3Ñ3°FÓ;ˆEÜ0°Ó7Ð7Ø# AÑ&ˆ
Ø˜‹?Ü˜{¨:¨,°nÐEÓFÐFä÷ 
Ü=BÀ:Ô=Nó
ó 
ˆô 5±[À$Ð5QÈ&Ñ5QÓR‰ˆˆuÜÑTÉVÓTÓTˆÜœ˜W˜Ó&ˆÜÑKÁ7ÓKÓKˆØ˜EÐ!Ð!r   )r�   r   r‘   r   rp   ú>tuple[tuple[Tensor, ...], Callable[..., Any], tuple[str, ...]]r   ©rÝ   rê   r)   rë   s   ``` r   Úfunctional_initrï   F  s,   ú€ ð
"Øð"Ø!ð"à	G÷"ñ "ð* €Nr   c                ó,   ^ ^^•       SUUU 4S jjnU$ )Nc                 ó  >^ ^• [        T5      S:¼  a  [        S5      e[        T5      S:X  a"  T" T 0 TD6R                  T5      n[        U5      $ TS   nUS::  a  [        SU S35      e[	        U UUU4S j[        U5       5       5      n[        T" T 0 TD65      u  nnnnn[        [	        S U 5       5      6 u  pš[	        [        U	6 5      n	[	        S U	 5       5      n	[	        [        U
6 5      n
[	        S	 U
 5       5      n
XšXgU4$ )
NrÕ   rÖ   r   r×   rØ   c              3  óR   >#   • U  H  nT" T0 TD6R                  T5      v •  M     g 7frG   rÚ   rÜ   s     €€€€r   r¾   Ú@functional_init_with_buffers.<locals>.wrapped.<locals>.<genexpr>‡  rß   rà   c              3  ó>   #   • U  H  n[        U5      S S v •  M     g 7f)NrÕ   )rx   râ   s     r   r¾   ró   ’  s#   é € ð â#�Eô ;¸5ÓAÀ"À1ÕEÚ#ùrã   c              3  ój   #   • U  H)  n[         R                  " U5      R                  5       v •  M+     g 7frG   r¸   r»   s     r   r¾   ró   ˜  rå   rÀ   c              3  ój   #   • U  H)  n[         R                  " U5      R                  5       v •  M+     g 7frG   r¸   r»   s     r   r¾   ró   š  rå   rÀ   )r/   ræ   rÛ   rr   r+   rç   rx   r0   )r�   r‘   r`   rè   rÐ   rV   ré   rb   rc   ra   r]   r)   rê   rÝ   s   ``         €€€r   rë   Ú-functional_init_with_buffers.<locals>.wrappedr  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   r‘   r   rp   z¤tuple[tuple[Tensor, ...], tuple[Tensor, ...], Callable[..., Any], tuple[str, ...], tuple[str, ...]] | tuple[tuple[Tensor, ...], Callable[..., Any], tuple[str, ...]]r   rî   s   ``` r   Úfunctional_init_with_buffersrø   c  s5   ú€ ð)@Øð)@Ø!ð)@ð	I÷)@ñ )@ðV €Nr   )rp   r   )r   ú0dict[str, Tensor] | Iterable[tuple[str, Tensor]]r   rù   rp   r—   )r1   r•   r2   z+Callable[..., Iterable[tuple[str, Tensor]]]r3   zCallable[[Tensor], Tensor]rp   ú@tuple[tuple[Tensor, ...], tuple[str, ...], dict[str, list[str]]])r1   r•   rp   rú   r™   )
r1   r•   r<   úSequence[str]r=   úSequence[Tensor]rO   r›   rp   r˜   )r1   r•   r6   r—   rT   r�   rp   zlist[Tensor])
r1   r•   r<   rû   r]   rü   rO   r›   rp   r˜   r*   )r`   r•   ra   rü   rb   rû   r]   rü   rc   rû   rp   r•   )r`   r•   rp   rí   )r`   r•   rp   zctuple[tuple[Tensor, ...], tuple[Tensor, ...], Callable[..., Any], tuple[str, ...], tuple[str, ...]]r°   rš   )rÁ   ztuple[tuple[Tensor, ...], ...]rp   rn   )rÐ   zSequence[nn.Module]rp   rœ   )r   Úcpu)rÝ   útype[nn.Module]rê   útuple[()] | tuple[int, ...]r)   útorch.types.Devicerp   zMCallable[..., tuple[tuple[Tensor, ...], Callable[..., Any], tuple[str, ...]]])rÝ   rþ   rê   rÿ   r)   r   rp   z³Callable[..., tuple[tuple[Tensor, ...], tuple[Tensor, ...], Callable[..., Any], tuple[str, ...], tuple[str, ...]] | tuple[tuple[Tensor, ...], Callable[..., Any], tuple[str, ...]]])%Ú
__future__r   rg   Útypingr   r   r   r,   Útorch.nnrA   r   Ú%torch.nn.utils._named_member_accessorr   Úcollections.abcr	   r
   r   r   r%   r>   rD   rL   rP   r[   r^   rd   rr   rx   ÚModulerz   r©   r³   rµ   rÃ   rÒ   rï   rø   r   r   r   Ú<module>r     s²  ðõ #ã ß /Ñ /ã Ý Ý Ý Eö ß<Ñ<ôð ,ØBð ,àGð ,ð ô ,ðF$Ø	ð$à>ð$ð )ð$ð Fô	$ð4EØ	ðEàEôEðAØ	ðAàEôAð ð	(Ø	ð(àð(ð ð(ð ð	(ð
 
õ(ð"Ø	ðØ3ðØ<Lðàôð$ ð	)Ø	ð)àð)ð ð)ð ð	)ð
 
õ)ð !#Ø"$ðØðàðð  ðð ð	ð
  ðð õð4)%Øð)%àCô)%ðX.FØð.Fðô.Fôb9M "§)¡)ô 9Môx#I�r—y‘yô #IðN 9>ðEØðEØ15ðEà0õEðR 9>ð<Øð<Ø15ð<àOõ<ð~Ø=ðàôð;%Øð;%àOô;%ð@ 35Ø!&ðØ ðà/ðð ðð Sõ	ð> 35Ø!&ð:Ø ð:à/ð:ð ð:ð
ö	:r   