Ë
    ›¾jŠ‰  ã                   óT  — U d dl Z d dl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
mZmZ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mZmZmZmZ ddlmZ ddl m!Z! dd	l"m#Z# dd
l$m%Z%m&Z&m'Z'm(Z(m)Z)  ed«      Z* ed«      Z+ edd¬«      Z, edi ¬«      Z-ee.   e/d<   d$d„Z0 G d„ dee*e+f   «      Z1ejd                  de	de	de3de1de4f
d„«       Z5ejd                  de	de	de3de1de	f
d„«       Z6 ede1¬«      Z7de7dee3ee3e	f   f   de7fd„Z8dgfde7de9de7fd „Z:de1d!e
e1ge7f   de7fd"„Z;g d#¢Z<y)%é    N)Ú
ContextVar)ÚPath)ÚAnyÚCallableÚDictÚGenericÚIterableÚIteratorÚListÚOptionalÚSequenceÚSetÚTupleÚTypeVarÚUnionÚcasté   )ÚCupyOpsÚNumpyOpsÚOpsÚParamServerÚget_current_ops)Ú	Optimizer)ÚShim)ÚFloatsXd)ÚDATA_VALIDATIONÚconvert_recursiveÚis_xp_arrayÚpartialÚvalidate_fwd_input_outputÚInTÚOutTÚSelfTÚModel)ÚboundÚcontext_operators)ÚdefaultÚmodelÚreturnc                 ó   — | S ©N© )r(   ÚargsÚkwargss      úU/home/spazio/kingdom_calls/work5/transenv/lib/python3.12/site-packages/thinc/model.pyÚ
empty_initr0   -   s   € Ø€Ló    c                   ó¨  — e Zd ZU dZdZeed<    ej                  «       Z	ej                  ed<   e
Zeed<   eed<   eed<   eed<   eed	<   eed
<   eeee   f   ed<   ed    ed<   ee   ed<   eeef   ed<   eeee   f   ed<   g d¢Zdi i g g i i ddœdeded	ee   deeee   f   deeee   f   ded    dee   deeef   deeed    f   deeeef      fd„Zeded    fd„«       Zedee   fd„«       Zedeeef   fd„«       Z ede!edf   fd „«       Z"ede!edf   fd!„«       Z#ede!edf   fd"„«       Z$ede!edf   fd#„«       Z%e&e'jP                  d$eeef   fd%„«       «       Z)dedee   fd&„Z*dedefd'„Z+d(d)œded*ed+eddfd,„Z,dedee   fd-„Z-dedee   fd.„Z.dedefd/„Z/dedee   fd0„Z0ded*ee   ddfd1„Z1dedefd2„Z2dedefd3„Z3ded*eddfd4„Z4dedee   fd5„Z5ded*eddfd6„Z6dedee   fd7„Z7dedd fd8„Z8deded    fd9„Z9ded*ed    ddfd:„Z:d;e;d<ede!e<ef   fd=„Z=dyd;ee;   d>ee<   dd fd?„Z>d;e;de!e<ee<ge;f   f   fd@„Z?d;e;de<fdA„Z@dBeAddfdC„ZBe'jP                  dee!eef   ef   fdD„«       ZCdEdFœdGedeDd    fdH„ZEdeDd    fdI„ZFdzdJedeDd    fdK„ZGd{dL„ZHddMœded	ee   ddfdN„ZIdOd dPd defdQ„ZJdee!eef   e!eef   f   fdR„ZKdSeLdeLfdT„ZM	 d|dSeLdUeeeed ef   f      deLfdV„ZNdWeddfdX„ZOd}dY„ZPdeddfdZ„ZQdeRfd[„ZSd\eeTef   ddfd]„ZUdefd^„ZVd_eRdd fd`„ZWd\eeTef   dd fda„ZXdbedd fdc„ZYdddeœd\eeTef   dfedefdg„ZZdddeœd_eRdfedefdh„Z[dddeœdbedfedefdi„Z\djedd fdk„Z]djedd fdl„Z^djedd fdm„Z_djedd fdn„Z`djedd fdo„Zadjedd fdp„Zbdjedd fdq„Zcdjedd fdr„Zddjedd fds„Zedjedd fdt„Zfdjedd fdu„Zgdjedd fdv„Zhdjedd fdw„Zidjedd fdx„Zjy)~r$   z/Class for implementing Thinc models and layers.r   Ú	global_idÚglobal_id_lockÚnameÚopsÚidÚ_funcÚinitÚ_paramsÚ_dimsÚ_layersÚ_shimsÚ_attrsÚ_has_params)r5   r7   r6   r8   r9   r:   r;   r>   Ú_refsr<   r=   r?   N)r9   ÚdimsÚparamsÚlayersÚshimsÚattrsÚrefsr6   ÚforwardrA   rB   rC   rD   rE   rF   c                óz  — || _         |€t        t        | «      }t        | d|«       t        | d|«       |
�|
n	t	        «       | _        t        «       | _        t        |«      | _	        t        |«      | _
        t        |	«      | _        t        |«      | _        t        |«      | _        t        j                   5  t        xj"                  dz  c_        t        j"                  | _        ddd«       i | _        |j)                  «       D ])  \  }}d| j&                  |<   |€Œ| j+                  ||«       Œ+ y# 1 sw Y   ŒMxY w)zInitialize a new model.Nr8   r9   r   )r5   r   r0   Úsetattrr   r6   r   r:   Údictr;   r>   r@   Úlistr<   r=   r$   r4   r3   r7   r?   ÚitemsÚ	set_param)Úselfr5   rG   r9   rA   rB   rC   rD   rE   rF   r6   Úvalues               r/   Ú__init__zModel.__init__U   s  € ð ˆŒ	Øˆ<Üœ: tÓ,ˆDä��g˜wÔ'Ü��f˜dÔ#Ø˜/‘3¬Ó/@ˆŒÜ"“}ˆŒÜ˜$“ZˆŒ
Ü˜5“kˆŒÜ˜$“ZˆŒ
Ü˜F“|ˆŒÜ˜5“kˆŒô ×!Ñ!ñ 	&Ü�OŠO˜qÑ �OÜ—o‘oˆDŒG÷	&ð ˆÔØ!Ÿ<™<›>ò 	,‰KˆD�%Ø%)ˆD×Ñ˜TÑ"ØÑ Ø—‘˜t UÕ+ñ	,÷		&ð 	&ús   Â6/D1Ä1D:r)   c                 ó   — | j                   S )zmA list of child layers of the model. You can append to it to add
        layers but not reassign it.
        )r<   ©rN   s    r/   rC   zModel.layers|   s   € ð
 �|‰|Ðr1   c                 ó   — | j                   S r+   )r=   rR   s    r/   rD   zModel.shimsƒ   s   € à�{‰{Ðr1   c                 ó   — | j                   S )zfA dict of the model's attrs. You can write to it to update attrs but
        not reassign it.
        )r>   rR   s    r/   rE   zModel.attrs‡   s   € ð
 �{‰{Ðr1   .c                 óH   — t        | j                  j                  «       «      S )z8Get the names of registered parameter (including unset).)Útupler?   ÚkeysrR   s    r/   Úparam_nameszModel.param_namesŽ   s   € ô �T×%Ñ%×*Ñ*Ó,Ó-Ð-r1   c                 óv   — t        | j                  D �cg c]  }| j                  |«      sŒ|‘Œ c}«      S c c}w )zHGet the names of parameters with registered gradients (including unset).)rV   rX   Úhas_grad©rN   r5   s     r/   Ú
grad_nameszModel.grad_names“   s.   € ô  t×'7Ñ'7ÖO˜t¸4¿=¹=ÈÕ;N’dÒOÓPÐPùÒOs   ”6«6c                 óH   — t        | j                  j                  «       «      S )z9Get the names of registered dimensions (including unset).)rV   r;   rW   rR   s    r/   Ú	dim_nameszModel.dim_names˜   ó   € ô �T—Z‘Z—_‘_Ó&Ó'Ð'r1   c                 óH   — t        | j                  j                  «       «      S )z>Get the names of registered node references (including unset).)rV   r@   rW   rR   s    r/   Ú	ref_nameszModel.ref_names�   r_   r1   Ú	operatorsc              #   ó’   K  — | j                   j                  t        |«      «      }d–— | j                   j                  |«       y­w)a  Bind arbitrary binary functions to Python operators, for use in any
        `Model` instance. Can (and should) be used as a contextmanager.

        EXAMPLE:
            with Model.define_operators({">>": chain}):
                model = Relu(512) >> Relu(512) >> Softmax()
        N)Ú_context_operatorsÚsetrJ   Úreset)Úclsrb   Útokens      r/   Údefine_operatorszModel.define_operators¢   s9   è ø€ ð ×&Ñ&×*Ñ*¬4°	«?Ó;ˆÛØ×Ñ×$Ñ$ UÕ+ùs   ‚AAc                 óB   — || j                   vry| j                   |   �yy)zŽCheck whether the model has a dimension of a given name. If the
        dimension is registered but the value is unset, returns None.
        FNT)r;   r[   s     r/   Úhas_dimzModel.has_dim°   ó(   € ð �t—z‘zÑ!ØØ�Z‰Z˜ÑÐ)Øàr1   c                 ó¸   — || j                   vrt        d|› d| j                  › d�«      ‚| j                   |   }|€d|› d| j                  › d�}t        |«      ‚|S )z4Retrieve the value of a dimension of the given name.zCannot get dimension 'ú' for model 'ú'z': value unset)r;   ÚKeyErrorr5   Ú
ValueError©rN   r5   rO   Úerrs       r/   Úget_dimzModel.get_dim»   sh   € à�t—z‘zÑ!ÜÐ3°D°6¸ÀtÇyÁyÀkÐQRÐSÓTÐTØ—
‘
˜4Ñ ˆØˆ=Ø*¨4¨&°¸d¿i¹i¸[ÈÐWˆCÜ˜S“/Ð!àˆLr1   F)ÚforcerO   ru   c                ób  — || j                   vrt        d|› d| j                  › d�«      ‚| j                   |   }t        d„ | j                  j                  «       D «       «      }|duxr ||k7  xr | xs |xr |}|r#d|› d| j                  › d|› d|› �}t        |«      ‚|| j                   |<   y)	zSet a value for a dimension.zCannot set unknown dimension 'rn   ú'.c              3   ó8   K  — | ]  \  }}t        |«      –— Œ y ­wr+   )Úbool)Ú.0ÚxÚys      r/   ú	<genexpr>z Model.set_dim.<locals>.<genexpr>Í   s   è ø€ ÒF¡T Q¨œ˜aŸÑFùs   ‚NzAttempt to change dimension 'z' from z to )r;   rp   r5   Úanyr?   rL   rq   )rN   r5   rO   ru   Ú	old_valueÚ
has_paramsÚinvalid_changers   s           r/   Úset_dimzModel.set_dimÆ   sÏ   € à�t—z‘zÑ!ÜØ0°°°mÀDÇIÁIÀ;ÈbÐQóð ð —J‘J˜tÑ$ˆ	ÜÑF¨T×-=Ñ-=×-CÑ-CÓ-EÔFÓFˆ
Ø#¨4Ð/ÒF°IÀÑ4Fò 
ØˆIÒ-˜Ò- :ð 	ñ Ø1°$°°}ÀTÇYÁYÀKÈwÐW`ÐVaÐaeÐfkÐelÐmˆCÜ˜S“/Ð!Ø ˆ�
‰
�4Òr1   c                 óJ   — | j                  |«      r| j                  |«      S dS )z=Retrieve the value of a dimension of the given name, or None.N)rk   rt   r[   s     r/   Úmaybe_get_dimzModel.maybe_get_dimÖ   ó!   € à%)§\¡\°$Ô%7ˆt�|‰|˜DÓ!ÐA¸TÐAr1   c                 óB   — || j                   vry| j                   |   �yy)z•Check whether the model has a weights parameter of the given name.

        Returns None if the parameter is registered but currently unset.
        FNT)r?   r[   s     r/   Ú	has_paramzModel.has_paramÚ   s,   € ð
 �t×'Ñ'Ñ'ØØ×Ñ˜dÑ#Ð/Øàr1   c                 ó&  — || j                   vrt        d|› d| j                  › d�«      ‚| j                  j	                  | j
                  |«      st        d|› d| j                  › d�«      ‚| j                  j                  | j
                  |«      S )z%Retrieve a weights parameter by name.zUnknown param: 'rn   rw   zParameter 'z' has not been allocated yet.)r?   rp   r5   r:   r‡   r7   Ú	get_paramr[   s     r/   r‰   zModel.get_paramæ   sˆ   € à�t×'Ñ'Ñ'ÜÐ-¨d¨V°=ÀÇÁÀÈ2ÐNÓOÐOØ�|‰|×%Ñ% d§g¡g¨tÔ4ÜØ˜d˜V =°·±°Ð;XÐYóð ð �|‰|×%Ñ% d§g¡g¨tÓ4Ð4r1   c                 óJ   — | j                  |«      r| j                  |«      S dS )z.Retrieve a weights parameter by name, or None.N)r‡   r‰   r[   s     r/   Úmaybe_get_paramzModel.maybe_get_paramð   s!   € à'+§~¡~°dÔ';ˆt�~‰~˜dÓ#ÐEÀÐEr1   c                 ó”   — |€d| j                   |<   y| j                  j                  | j                  ||«       d| j                   |<   y)z Set a weights parameter's value.NT)r?   r:   rM   r7   ©rN   r5   rO   s      r/   rM   zModel.set_paramô   sA   € àˆ=Ø%)ˆD×Ñ˜TÒ"à�L‰L×"Ñ" 4§7¡7¨D°%Ô8Ø%)ˆD×Ñ˜TÒ"r1   c                 óN   — | j                   j                  | j                  |«      S )z@Check whether the model has a non-zero gradient for a parameter.)r:   rZ   r7   r[   s     r/   rZ   zModel.has_gradü   ó   € à�|‰|×$Ñ$ T§W¡W¨dÓ3Ð3r1   c                 óN   — | j                   j                  | j                  |«      S )zGet a gradient from the model.)r:   Úget_gradr7   r[   s     r/   r‘   zModel.get_grad   r�   r1   c                 óR   — | j                   j                  | j                  ||«       y)z#Set a gradient value for the model.N)r:   Úset_gradr7   r�   s      r/   r“   zModel.set_grad  ó   € à�‰×Ñ˜dŸg™g t¨UÕ3r1   c                 óJ   — | j                  |«      r| j                  |«      S dS )z%Retrieve a gradient by name, or None.N)rZ   r‘   r[   s     r/   Úmaybe_get_gradzModel.maybe_get_grad  s!   € à&*§m¡m°DÔ&9ˆt�}‰}˜TÓ"ÐC¸tÐCr1   c                 óR   — | j                   j                  | j                  ||«       y)z1Increment the gradient of a parameter by a value.N)r:   Úinc_gradr7   r�   s      r/   r˜   zModel.inc_grad  r”   r1   c                 óB   — || j                   vry| j                   |   �yy)zŽCheck whether the model has a reference of a given name. If the
        reference is registered but the value is unset, returns None.
        FNT)r@   r[   s     r/   Úhas_refzModel.has_ref  rl   r1   c                 ó¸   — || j                   vrt        d|› d| j                  › d�«      ‚| j                   |   }|€d|› d| j                  › d�}t        |«      ‚|S )z4Retrieve the value of a reference of the given name.zCannot get reference 'rn   rw   z': value unset.)r@   rp   r5   rq   rr   s       r/   Úget_refzModel.get_ref  sh   € à�t—z‘zÑ!ÜÐ3°D°6¸ÀtÇyÁyÀkÐQSÐTÓUÐUØ—
‘
˜4Ñ ˆØˆ=Ø*¨4¨&°¸d¿i¹i¸[ÈÐXˆCÜ˜S“/Ð!àˆLr1   c                 óJ   — | j                  |«      r| j                  |«      S dS )z8Retrieve the value of a reference if it exists, or None.N)rš   rœ   r[   s     r/   Úmaybe_get_refzModel.maybe_get_ref&  r…   r1   c                 ó€   — |€|| j                   |<   y|| j                  «       v r|| j                   |<   yt        d«      ‚)zSet a value for a reference.Nz)Cannot add reference to node not in tree.)r@   Úwalkrq   r�   s      r/   Úset_refzModel.set_ref*  s=   € àˆ=Ø$ˆD�J‰J�tÒØ�d—i‘i“kÑ!Ø$ˆD�J‰J�tÒäÐHÓIÐIr1   ÚXÚis_trainc                 ó*   — | j                  | ||¬«      S )z~Call the model's `forward` function, returning the output and a
        callback to compute the gradients via backpropagation.©r£   ©r8   )rN   r¢   r£   s      r/   Ú__call__zModel.__call__3  s   € ð �z‰z˜$ ¨HˆzÓ5Ð5r1   ÚYc                 ó²   — t        j                  «       r"t        | j                  | j                  ||«       | j
                  �| j                  | ||¬«       | S )z…Finish initialization of the model, optionally providing a batch of
        example input and output data to perform shape inference.)r¢   r¨   )r   Úgetr    r5   r8   r9   )rN   r¢   r¨   s      r/   Ú
initializezModel.initialize8  sG   € ô ×ÑÔ Ü% d§i¡i°·±¸QÀÔBØ�9‰9Ð Ø�I‰I�d˜a 1ˆIÔ%Øˆr1   c                 ó*   — | j                  | |d¬«      S )ap  Run the model over a batch of data, returning the output and a
        callback to complete the backward pass. A tuple (Y, finish_update),
        where Y is a batch of output data, and finish_update is a callback that
        takes the gradient with respect to the output and an optimizer function,
        and returns the gradient with respect to the input.
        Tr¥   r¦   ©rN   r¢   s     r/   Úbegin_updatezModel.begin_updateA  s   € ð �z‰z˜$ ¨DˆzÓ1Ð1r1   c                 ó0   — | j                  | |d¬«      d   S )z’Call the model's `forward` function with `is_train=False`, and return
        only the output, instead of the `(output, callback)` tuple.
        Fr¥   r   r¦   r­   s     r/   ÚpredictzModel.predictJ  s   € ð �z‰z˜$ ¨EˆzÓ2°1Ñ5Ð5r1   Ú	optimizerc           	      ót  — | j                  «       D ]$  }|j                  D ]  }|j                  |«       Œ Œ& | j                  «       D ]n  }|j                  D ]]  }|j	                  |«      sŒ ||j
                  |f|j                  |«      |j                  |«      «      \  }}|j                  ||«       Œ_ Œp y)z�Update parameters with current gradients. The optimizer is called
        with each parameter and gradient of the model.
        N)	r    rD   Úfinish_updaterX   rZ   r7   r‰   r‘   rM   )rN   r±   ÚnodeÚshimr5   ÚparamÚgrads          r/   r³   zModel.finish_updateP  s±   € ð —I‘I“Kò 	.ˆDØŸ
™
ò .�Ø×"Ñ" 9Õ-ñ.ð	.ð —I‘I“Kò 	0ˆDØ×(Ñ(ò 0�Ø—=‘= Õ&Ù"+ØŸ™ $˜¨¯©¸Ó)=¸t¿}¹}ÈTÓ?Ró#‘K�E˜4ð —N‘N 4¨Õ/ñ0ñ	0r1   c              #   ó"  K  — i }| j                   D ]>  }| j                  |f}||v sŒ| j                  |«      ||<   | j                  |||   «       Œ@ t	        j
                  «       5 }| j                  D ]"  }|j                  |j                  |«      «       Œ$ | j                  D ]"  }|j                  |j                  |«      «       Œ$ d–— ddd«       |r+|j                  «       D ]  \  }}| j                  ||«       Œ yy# 1 sw Y   Œ7xY w­w)zÁContext manager to temporarily set the model's parameters to
        specified values. The params are a dictionary keyed by model IDs, whose
        values are arrays of weight values.
        N)rX   r7   r‰   rM   Ú
contextlibÚ	ExitStackrC   Úenter_contextÚ
use_paramsrD   rL   )	rN   rB   Úbackupr5   ÚkeyÚstackÚlayerrµ   r¶   s	            r/   r¼   zModel.use_params_  s  è ø€ ð ˆØ×$Ñ$ò 	2ˆDØ—7‘7˜D�/ˆCØ�fŠ}Ø#Ÿ~™~¨dÓ3��t‘Ø—‘˜t V¨C¡[Õ1ð		2ô ×!Ñ!Ó#ð 	 uØŸ™ò >�Ø×#Ñ# E×$4Ñ$4°VÓ$<Õ=ð>àŸ
™
ò =�Ø×#Ñ# D§O¡O°FÓ$;Õ<ð=ã÷	ñ Ø%Ÿ|™|›~ò ,‘��eØ—‘˜t UÕ+ñ,ð ÷	ð 	üs#   ‚$D§?DÁ&A'DÃ6DÄDÄDÚbfs©ÚorderrÃ   c                óž   — |dk(  r| j                  «       S |dk(  r| j                  d¬«      S |dk(  r| j                  d¬«      S t        d«      ‚)zæIterate out layers of the model.

        Nodes are returned in breadth-first order by default. Other possible
        orders are "dfs_pre" (depth-first search in preorder) and "dfs_post"
        (depth-first search in postorder).rÁ   Údfs_preF)Ú
post_orderÚdfs_postTz5Invalid order, must be one of: bfs, dfs_pre, dfs_post)Ú	_walk_bfsÚ	_walk_dfsrq   )rN   rÃ   s     r/   r    z
Model.walkv  sV   € ð �EŠ>Ø—>‘>Ó#Ð#Ø�iÒØ—>‘>¨U�>Ó3Ð3Ø�jÒ Ø—>‘>¨T�>Ó2Ð2äÐTÓUÐUr1   c              #   óÂ   K  — | g}t        «       }|D ]I  }t        |«      |v rŒ|j                  t        |«      «       |–— |j                  |j                  «       ŒK y­w)z/Iterate out layers of the model, breadth-first.N)re   r7   ÚaddÚextendrC   )rN   ÚqueueÚseenr´   s       r/   rÈ   zModel._walk_bfs…  sW   è ø€ à�ˆÜ›ˆØò 	&ˆDÜ�$‹x˜4ÑØØ�H‰H”R˜“XÔØŠJØ�L‰L˜Ÿ™Õ%ñ	&ùs   ‚AArÆ   c              #   ó�  K  — t        «       }| g}t        | j                  «      |t        | «      <   |s| –— |rd	 t	        |t        |d   «         «      }t        |«      |vr8|s|–— |j                  |«       t        |j                  «      |t        |«      <   |rŒcyy# t        $ r |r|d   –— |j                  «        Y Œ)w xY w­w)z-Iterate out layers of the model, depth-first.éÿÿÿÿN)rJ   ÚiterrC   r7   ÚnextÚappendÚStopIterationÚpop)rN   rÆ   rÎ   r¿   Ú
next_childs        r/   rÉ   zModel._walk_dfs�  sµ   è ø€ ä-1«VˆØ�ˆÜ˜dŸk™kÓ*ˆŒR�‹X‰ÙØŠJáðÜ! $¤r¨%°©)£}Ñ"5Ó6�
Ü˜*“~¨Ñ-Ù%Ø(Ò(à—L‘L Ô,Ü+/°
×0AÑ0AÓ+B�Dœ˜J›Ñ(ô øô !ò ÙØ ™)’OØ—	‘	–ðüs/   ‚7CºAB ÂCÂCÂ"CÃ CÃCÃCc                 ój  — t        | j                  «       «      D ];  }||j                  v sŒ|j                  j                  |«       ||j                  v rŒ*Œ= t	        | j                  «       «      }|D ]>  }|j
                  D ]-  }|j                  |«      }|€Œ||vsŒ|j                  |d«       Œ/ Œ@ y)a]  Remove a node from all layers lists, and then update references.
        References that no longer point to a node within the tree will be set
        to `None`. For instance, let's say a node has its grandchild as a reference.
        If the child is removed, the grandchild reference will be left dangling,
        so will be set to None.
        N)rK   r    rC   Úremovere   ra   rœ   r¡   )rN   r´   ÚchildÚtreer5   Úrefs         r/   Úremove_nodezModel.remove_node¦  s¥   € ô ˜$Ÿ)™)›+Ó&ò 	*ˆEØ˜%Ÿ,™,Ò&Ø—‘×#Ñ# DÔ)ð ˜%Ÿ,™,Ó&ð	*ô �4—9‘9“;ÓˆØò 	-ˆDØŸ™ò -�Ø—l‘l 4Ó(�Ø‘? s°$¢Ø—L‘L  tÕ,ñ-ñ	-r1   )r9   c                ó8   — t        | d|«       t        | d|«       y )Nr8   r9   )rI   )rN   rG   r9   s      r/   Úreplace_callbackszModel.replace_callbacks·  s   € ô 	��g˜wÔ'Ü��f˜dÕ#r1   ÚoldÚnewc                 ó  — d}t        | j                  d¬«      «      D ]e  }||u rd}Œ
|j                  D �cg c]
  }||u r|n|‘Œ c}|_        |j                  D ](  }|j	                  |«      |u sŒ|j                  ||«       Œ* Œg |S c c}w )zzReplace a node anywhere it occurs within the model. Returns a boolean
        indicating whether the replacement was made.FrÇ   rÂ   T)rK   r    r<   ra   rœ   r¡   )rN   rß   rà   rÎ   r´   rÀ   r5   s          r/   Úreplace_nodezModel.replace_node½  s    € ð ˆô
 ˜Ÿ™¨˜Ó4Ó5ò 		0ˆDØ�s‰{Ø‘ð AEÇÁö Ø7<˜5 C™<‘C¨UÑ2ò �”ð !ŸN™Nò 0�DØ—|‘| DÓ)¨SÒ0ØŸ™ T¨3Õ/ñ0ð		0ð ˆùò s   ¶Bc                 óÀ   — i }| j                  «       D ]H  }|j                  D ]7  }|j                  |«      }|j                  |«      }||f||j                  |f<   Œ9 ŒJ |S )z™Get non-zero gradients of the model's parameters, as a dictionary
        keyed by the parameter ID. The values are (weights, gradients) tuples.
        )r    r\   r‰   r‘   r7   )rN   Ú	gradientsr´   r5   r¶   r·   s         r/   Úget_gradientszModel.get_gradientsÒ  sk   € ð ˆ	Ø—I‘I“Kò 	;ˆDØŸ™ò ;�ØŸ™ tÓ,�Ø—}‘} TÓ*�Ø.3°T¨]�	˜4Ÿ7™7 D˜/Ò*ñ;ð	;ð
 Ðr1   rN   c                 ó"   — | j                  «       S )z¿
        Create a copy of the model, its attributes, and its parameters. Any child
        layers will also be deep-copied. The copy will receive a distinct `model.id`
        value.
        )Ú_copyrR   s    r/   Úcopyz
Model.copyÞ  s   € ð �z‰z‹|Ðr1   rÎ   c           
      ó  — |€i }i }| j                   D ])  }| j                  |«      r| j                  |«      nd ||<   Œ+ g }| j                  D ]k  }t	        |«      |v r,|j                  t        t        |t	        |«         «      «       Œ<|j                  |«      }||t	        |«      <   |j                  |«       Œm g }| j                  D ]j  }t	        |«      |v r,|j                  t        t        |t	        |«         «      «       Œ<|j                  «       }	|	|t	        |«      <   |j                  |	«       Œl t        | j                  | j                  | j                  t        j                  |«      t        j                  | j                   «      t        j                  | j"                  «      ||¬«      }
| j$                  D ]1  }|
j'                  || j)                  |«      j                  «       «       Œ3 t        t*        |
«      S )N)r9   rB   rA   rE   rC   rD   )rX   r‡   r‰   rC   r7   rÓ   r   r$   rç   rD   r   rè   r5   r8   r9   Údeepcopyr;   r>   r\   r“   r‘   r#   )rN   rÎ   rB   r5   Úcopied_layersrÀ   Úcopied_layerÚcopied_shimsrµ   Úcopied_shimÚcopieds              r/   rç   zModel._copyæ  s³  € ð ˆ<ØˆDØˆØ×$Ñ$ò 	RˆDØ37·>±>À$Ô3G˜4Ÿ>™>¨$Ô/ÈTˆF�4ŠLð	Rð &(ˆØ—[‘[ò 	3ˆEÜ�%‹y˜DÑ Ø×$Ñ$¤T¬%°´b¸³i±Ó%AÕBà$Ÿ{™{¨4Ó0�Ø".�”R˜“Y‘Ø×$Ñ$ \Õ2ð	3ð ˆØ—J‘Jò 	1ˆDÜ�$‹x˜4ÑØ×#Ñ#¤D¬¨t´B°t³H©~Ó$>Õ?à"Ÿi™i›k�Ø!,�”R˜“X‘Ø×#Ñ# KÕ0ð	1ô $)Ø�I‰IØ�J‰JØ—‘Ü—=‘= Ó(Ü—‘˜tŸz™zÓ*Ü—-‘- §¡Ó,Ø Øô	$
ˆð —O‘Oò 	>ˆDØ�O‰O˜D $§-¡-°Ó"5×":Ñ":Ó"<Õ=ð	>ä”E˜6Ó"Ð"r1   Úgpu_idc                 ó²   — ddl }|j                  j                  j                  |«      5  | j	                  t        «       «       ddd«       y# 1 sw Y   yxY w)z)Transfer the model to a given GPU device.r   N)Úcupy.cuda.deviceÚcudaÚdeviceÚDeviceÚ_to_opsr   )rN   rð   Úcupys      r/   Úto_gpuzModel.to_gpu  s@   € ãà�Y‰Y×Ñ×$Ñ$ VÓ,ñ 	$Ø�L‰Lœ›Ô#÷	$÷ 	$ñ 	$ús   ªAÁAc                 ó6   — | j                  t        «       «       y)zTransfer the model to CPU.N)rö   r   rR   s    r/   Úto_cpuzModel.to_cpu  s   € à�‰”X“ZÕ r1   c           
      óÒ  — | j                  «       D ]Ô  }||_        |j                  D ]…  }|j                  |«      r0|j	                  ||j                  |j                  |«      «      «       |j                  |«      sŒV|j                  ||j                  |j                  |«      «      «       Œ‡ |j                  D ](  }|j                  |j                  |j                  «       Œ* ŒÖ y)z Common method for to_cpu/to_gpu.N)r    r6   rX   r‡   rM   Ú	asarray_fr‰   rZ   r“   r‘   rD   Ú	to_deviceÚdevice_typeÚ	device_id)rN   r6   r´   r5   rµ   s        r/   rö   zModel._to_ops  s¸   € à—I‘I“Kò 	?ˆDØˆDŒHØ×(Ñ(ò L�Ø—>‘> $Ô'Ø—N‘N 4¨¯©°t·~±~ÀdÓ7KÓ)LÔMØ—=‘= Õ&Ø—M‘M $¨¯©°d·m±mÀDÓ6IÓ(JÕKð	Lð
 Ÿ
™
ò ?�Ø—‘˜sŸ™°·±Õ>ñ?ñ	?r1   c                 ó°   — | j                  «       }t        | j                  j                  d¬«      }t	        t
        ||«      }t        j                  |«      S )aa  Serialize the model to a bytes representation. Models are usually
        serialized using msgpack, so you should be able to call msgpack.loads()
        on the data and get back a dictionary with the contents.

        Serialization should round-trip identically, i.e. the same bytes should
        result from loading and serializing a model.
        ú<)Ú
byte_order)Úto_dictr   r6   Úto_numpyr   r   ÚsrslyÚmsgpack_dumps)rN   ÚmsgÚto_numpy_les      r/   Úto_byteszModel.to_bytes&  sD   € ð �l‰l‹nˆÜ˜dŸh™h×/Ñ/¸CÔ@ˆÜ¤¨[¸#Ó>ˆÜ×"Ñ" 3Ó'Ð'r1   Úpathc                 óÈ   — t        |t        «      rt        |«      n|}|j                  d«      5 }|j	                  | j                  «       «       ddd«       y# 1 sw Y   yxY w)z—Serialize the model to disk. Most models will serialize to a single
        file, which should just be the bytes contents of model.to_bytes().
        ÚwbN)Ú
isinstanceÚstrr   ÚopenÚwriter	  )rN   r
  Úfile_s      r/   Úto_diskzModel.to_disk3  sL   € ô (¨¬cÔ2Œt�DŒz¸ˆØ�Y‰Y�t‹_ð 	) Ø�K‰K˜Ÿ™›Ô(÷	)÷ 	)ñ 	)ús   ¯ AÁA!c                 ó¨  — g g g g dœ}t        | j                  «       «      }t        |«      D ��ci c]  \  }}|j                  |“Œ }}}t        |«      D ]á  \  }}i }g }|j                  D ]\  }|j                  |«      sd||<   Œ|j                  |«      }	|	j                  |v r||	j                     ||<   ŒL|j                  |«       Œ^ |rt        d|› �«      ‚i }
|j                  D ])  }|j                  |«      r|j                  |«      nd|
|<   Œ+ |d   j                  ||j                  |
|dœ«       Œã |D ]L  }i }|j                  j                  «       D ]  \  }}	 t        ||||«      ||<   Œ |d   j                  |«       ŒN |D ]<  }|d   j                  |j"                  D �cg c]  }|j%                  «       ‘Œ c}«       Œ> |D ]i  }i }|j&                  D ]B  }|j)                  |«      r*t+        t,        t.           |j1                  |«      «      ||<   Œ>d||<   ŒD |d   j                  |«       Œk |S c c}}w # t         $ r Y Œòw xY wc c}w )	z»Serialize the model to a dict representation.

        Serialization should round-trip identically, i.e. the same dict should
        result from loading and serializing a model.
        )ÚnodesrE   rB   rD   NzCannot get references: r  )Úindexr5   rA   rF   rE   rD   rB   )rK   r    Ú	enumerater7   ra   rš   rœ   rÓ   rq   r^   rk   rt   r5   rE   rL   Úserialize_attrÚ	TypeErrorrD   r	  rX   r‡   r   r   r   r‰   )rN   r  r  Úir´   Ú	node_to_irF   Úinvalid_refsr5   rÛ   rA   ÚdimrE   rO   rµ   rB   s                   r/   r  zModel.to_dict;  st  € ð *,°bÀBÐQSÑTˆÜ�T—Y‘Y“[Ó!ˆô
 09¸Ó/?×@¡G A t�T—W‘W˜a‘ZÐ@ˆ	Ñ@Ü  Ó'ò 	‰GˆAˆtØ-/ˆDØ&(ˆLØŸ™ò 2�Ø—|‘| DÔ)Ø!%�D˜’JàŸ,™, tÓ,�CØ—v‘v Ñ*Ø%.¨s¯v©vÑ%6˜˜Tš
à$×+Ñ+¨DÕ1ð2ñ Ü Ð#:¸<¸.Ð!IÓJÐJØˆDØ—~‘~ò M�Ø15·±¸cÔ1B˜DŸL™L¨Ô-È��S’	ðMà�‰L×ÑØ T§Y¡Y¸ÀdÑKõð#	ð( ò 	'ˆDØˆEØ#Ÿz™z×/Ñ/Ó1ò ‘��eðÜ"0°¸¸tÀTÓ"J�E˜$’Kðð
 �‰L×Ñ Õ&ð	'ð ò 	JˆDØ�‰L×Ñ¸T¿Z¹ZÖ H°T §¡¥Ò HÕIð	Jàò 	)ˆDØ46ˆFØ×(Ñ(ò (�Ø—>‘> $Ô'Ü#'¬´Ñ(:¸D¿N¹NÈ4Ó<PÓ#Q�F˜4’Là#'�F˜4’Lð	(ð
 �‰M× Ñ  Õ(ð	)ð ˆ
ùóO Aøô4 !ò Ùðüò !Is   ¯H:Å I Æ*I
É 	IÉIÚ
bytes_datac                 ó˜   — t        j                  |«      }t        t        | j                  j
                  |«      }| j                  |«      S )ae  Deserialize the model from a bytes representation. Models are usually
        serialized using msgpack, so you should be able to call msgpack.loads()
        on the data and get back a dictionary with the contents.

        Serialization should round-trip identically, i.e. the same bytes should
        result from loading and serializing a model.
        )r  Úmsgpack_loadsr   r   r6   ÚasarrayÚ	from_dict)rN   r  r  s      r/   Ú
from_byteszModel.from_bytest  s;   € ô ×!Ñ! *Ó-ˆÜ¤¨T¯X©X×-=Ñ-=¸sÓCˆØ�~‰~˜cÓ"Ð"r1   c                 óÊ   — t        |t        «      rt        |«      n|}|j                  d«      5 }|j	                  «       }ddd«       | j                  «      S # 1 sw Y   ŒxY w)a¾  Deserialize the model from disk. Most models will serialize to a single
        file, which should just be the bytes contents of model.to_bytes().

        The model instance must have the same architecture (layers, dimensions)
        as the model that was serialized. For example, if a chain(Relu(10),
        Relu(1), Logistic()) model was saved, load it into a model created with
        the same chain(...) call, not a bare Model().
        ÚrbN)r  r  r   r  Úreadr"  )rN   r
  r  r  s       r/   Ú	from_diskzModel.from_disk€  sT   € ô (¨¬cÔ2Œt�DŒz¸ˆØ�Y‰Y�t‹_ð 	& ØŸ™›ˆJ÷	&à�‰˜zÓ*Ð*÷	&ð 	&ús   ¯AÁA"r  c                 óÈ  — d|j                  «       vrd}t        |«      ‚t        | j                  «       «      }t	        |d   «      t	        |«      k7  rt        d«      ‚t        |«      D �]u  \  }}|d   |   }|d   |_        |d   j                  «       D ]  \  }}|€Œ	|j                  ||«       Œ |d   j                  «       D ]/  \  }	}
|
€|j                  |	d «       Œ|j                  |	||
   «       Œ1 |d   |   j                  «       D ]=  \  }}|j                  j                  |«      }t        ||||«      }||j                  |<   Œ? |d   |   j                  «       D ]B  \  }}|�)|j                  j                  |«      j                  «       }|j!                  ||«       ŒD t        |d	   |   «      D ]#  \  }}|j"                  |   j%                  |«       Œ% �Œx | S )
Nr  zMTrying to read a Model that was created with an incompatible version of Thincz.Cannot deserialize model: mismatched structurer5   rA   rF   rE   rB   rD   )rW   rq   rK   r    Úlenr  r5   rL   r‚   r¡   rE   rª   Údeserialize_attrr6   r   rè   rM   rD   r"  )rN   r  rs   r  r  r´   Úinfor  rO   rÛ   Ú	ref_indexÚattrÚdefault_valueÚloaded_valueÚ
param_nameÚ
shim_bytess                   r/   r!  zModel.from_dictŽ  së  € Ø˜#Ÿ(™(›*Ñ$ØaˆCÜ˜S“/Ð!Ü�T—Y‘Y“[Ó!ˆÜˆs�7‰|Ó¤ E£
Ò*ÜÐMÓNÐNÜ  Ó'ó 	5‰GˆAˆtØ�w‘< ‘?ˆDØ˜V™ˆDŒIØ" 6™l×0Ñ0Ó2ò -‘
��UØÑ$Ø—L‘L  eÕ,ð-ð #' v¡,×"4Ñ"4Ó"6ò 8‘��YØÐ$Ø—L‘L  dÕ+à—L‘L  e¨IÑ&6Õ7ð	8ð
  # 7™|¨A™×4Ñ4Ó6ò 0‘��eØ $§
¡
§¡¨tÓ 4�Ü/°¸uÀdÈDÓQ�Ø#/�—
‘
˜4Ò ð0ð &)¨¡]°1Ñ%5×%;Ñ%;Ó%=ò 2Ñ!�
˜EØÐ$Ø ŸH™H×,Ñ,¨UÓ3×8Ñ8Ó:�EØ—‘˜z¨5Õ1ð2ô "+¨3¨w©<¸©?Ó!;ò 5‘��:Ø—
‘
˜1‘×(Ñ(¨Õ4ò5ð'	5ð* ˆr1   T©Ústrictr2  c                ó  — t        |t        «      rt        |«      n|}|j                  «       s|j	                  «       sy|j                  d«      5 }|j                  «       }ddd«       | j                  |¬«      S # 1 sw Y   ŒxY w)zÈCheck whether serialized data on disk is compatible with the model.
        If 'strict', the function returns False if the model has an attribute
        already loaded that would be changed.
        Fr$  Nr1  )r  r  r   Úis_dirÚexistsr  r%  Úcan_from_bytes)rN   r
  r2  r  r  s        r/   Úcan_from_diskzModel.can_from_disk¬  so   € ô
 (¨¬cÔ2Œt�DŒz¸ˆØ�;‰;Œ= §¡¤ØØ�Y‰Y�t‹_ð 	& ØŸ™›ˆJ÷	&à×"Ñ" :°fÐ"Ó=Ð=÷	&ð 	&ús   ÁA<Á<Bc                ór   — 	 t        j                  |«      }| j                  ||¬«      S # t        $ r Y yw xY w)z¿Check whether the bytes data is compatible with the model. If 'strict',
        the function returns False if the model has an attribute already loaded
        that would be changed.
        Fr1  )r  r  rq   Úcan_from_dict)rN   r  r2  r  s       r/   r6  zModel.can_from_bytes¸  sC   € ð
	Ü×%Ñ% jÓ1ˆCð ×!Ñ! #¨fÐ!Ó5Ð5øô ò 	Ùð	ús   ‚* ª	6µ6c                ó˜  — d|j                  «       vryt        | j                  «       «      }t        |d   «      t        |«      k7  ryt	        |«      D �]e  \  }}|d   |   }|r|d   |j
                  k7  r yt        |d   |   «      t        |j                  «      k7  r y|d   j                  «       D ]7  \  }}|j                  |«      }	|	du r  y|	sŒ!|j                  |«      |k7  sŒ6  y |d   |   j                  «       D ]P  \  }
}|j                  |
«      }|du r  y|sŒ!|€Œ$|j                  |
«      }|j                  |j                  k7  sŒO  y |s�Œ|d   |   j                  «       D ]E  \  }}||j                  v sŒ	 t        |j                  |   |j                  |   ||«      }||k7  sŒD  y �Œh y# t        $ r Y ŒWw xY w)	z½Check whether a dictionary is compatible with the model.
        If 'strict', the function returns False if the model has an attribute
        already loaded that would be changed.
        r  Fr5   rD   rA   rB   rE   T)rW   rK   r    r(  r  r5   rD   rL   rk   rt   r‡   r‰   ÚshaperE   r  r  )rN   r  r2  r  r  r´   r*  r  rO   rk   r/  r‡   r¶   r,  Ú
serializeds                  r/   r9  zModel.can_from_dictÃ  sØ  € ð
 ˜#Ÿ(™(›*Ñ$ØÜ�T—Y‘Y“[Ó!ˆÜˆs�7‰|Ó¤ E£
Ò*Øä  Ó'ó !	)‰GˆAˆtØ�w‘< ‘?ˆDÙ˜$˜v™,¨$¯)©)Ò3ÙÜ�3�w‘< ‘?Ó#¤s¨4¯:©:£Ò6ñ Ø" 6™l×0Ñ0Ó2ò !‘
��UØŸ,™, sÓ+�Ø˜eÑ#Ú Ú §¡¨cÓ!2°eÓ!;Ú ð!ð &)¨¡]°1Ñ%5×%;Ñ%;Ó%=ò %Ñ!�
˜EØ ŸN™N¨:Ó6�	Ø Ñ%Ú Ú 5Ñ#4Ø ŸN™N¨:Ó6�EØ—{‘{ e§k¡kÓ1Ú$ð%ó Ø#& w¡<°¡?×#8Ñ#8Ó#:ò 
)‘K�D˜%Ø˜tŸz™zÒ)ð%ä)7Ø $§
¡
¨4Ñ 0°$·*±*¸TÑ2BÀDÈ$ó*˜Jð
 &¨Ó.Ú#(ò
)ð/!	)ðD øô	  )ò %Ù$ð%ús   Æ(F=Æ=	G	ÇG	Úotherc                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '+' operator.ú+zUndefined operator: +©rd   rª   r  ©rN   r=  s     r/   Ú__add__zModel.__add__ò  óH   € à�d×-Ñ-×1Ñ1Ó3Ñ3ÜÐ3Ó4Ð4Ø1ˆt×&Ñ&×*Ñ*Ó,¨SÑ1°$¸Ó>Ð>r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '-' operator.ú-zUndefined operator: -r@  rA  s     r/   Ú__sub__zModel.__sub__ø  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '*' operator.Ú*zUndefined operator: *r@  rA  s     r/   Ú__mul__zModel.__mul__þ  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '@' operator.ú@zUndefined operator: @r@  rA  s     r/   Ú
__matmul__zModel.__matmul__  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S ©z-Apply the function bound to the '/' operator.ú/zUndefined operator: /r@  rA  s     r/   Ú__div__zModel.__div__
  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S rN  r@  rA  s     r/   Ú__truediv__zModel.__truediv__  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z.Apply the function bound to the '//' operator.z//zUndefined operator: //r@  rA  s     r/   Ú__floordiv__zModel.__floordiv__  óH   € à�t×.Ñ.×2Ñ2Ó4Ñ4ÜÐ4Ó5Ð5Ø2ˆt×&Ñ&×*Ñ*Ó,¨TÑ2°4¸Ó?Ð?r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '%' operator.ú%zUndefined operator: %r@  rA  s     r/   Ú__mod__zModel.__mod__  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z.Apply the function bound to the '**' operator.z**zUndefined operator: **r@  )rN   r=  r.   s      r/   Ú__pow__zModel.__pow__"  rU  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z.Apply the function bound to the '<<' operator.z<<zUndefined operator: <<r@  rA  s     r/   Ú
__lshift__zModel.__lshift__(  rU  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z.Apply the function bound to the '>>' operator.z>>zUndefined operator: >>r@  rA  s     r/   Ú
__rshift__zModel.__rshift__.  rU  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '&' operator.ú&zUndefined operator: &r@  rA  s     r/   Ú__and__zModel.__and__4  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '^' operator.ú^zUndefined operator: ^r@  rA  s     r/   Ú__xor__zModel.__xor__:  rC  r1   c                 ó˜   — d| j                   j                  «       vrt        d«      ‚ | j                   j                  «       d   | |«      S )z-Apply the function bound to the '|' operator.ú|zUndefined operator: |r@  rA  s     r/   Ú__or__zModel.__or__@  rC  r1   )NN)F)r´   r$   r)   Nr+   )r)   N)kÚ__name__Ú
__module__Ú__qualname__Ú__doc__r3   ÚintÚ__annotations__Ú	threadingÚLockr4   r&   rd   r  r   r   r   r   r   r   r   r   ry   Ú	__slots__r   r   r   r   r   rP   ÚpropertyrC   rD   rE   r   rX   r\   r^   ra   Úclassmethodr¹   Úcontextmanagerri   rk   rt   r‚   r„   r‡   r‰   r‹   rM   rZ   r‘   r“   r–   r˜   rš   rœ   rž   r¡   r!   r"   r§   r«   r®   r°   r   r³   r¼   r	   r    rÈ   rÉ   rÜ   rÞ   râ   rå   r#   rè   rç   rø   rú   rö   Úbytesr	  r   r  r  r"  r&  r!  r7  r6  r9  rB  rF  rI  rL  rP  rR  rT  rX  rZ  r\  r^  ra  rd  rg  r,   r1   r/   r$   r$   1   s/  … Ù9à€IˆsÓØ%3 Y§^¡^Ó%5€N�I—N‘NÓ5Ø*Ðà
ƒIØ	ƒHØƒGØƒOØ
ƒNØÓØ��X˜c‘]Ð"Ñ#Ó#Ø�'‰]ÓØ�‰JÓØ��c�‰NÓØ�c˜8 D™>Ð)Ñ*Ó*ò€Ið( $(Ø)+Ø02Ø$&ØØ "Ø-/Ø26ò%,àð%,ð ð%,ð
 �xÑ ð%,ð �3˜ ™Ð%Ñ&ð%,ð �S˜( 8Ñ,Ð,Ñ-ð%,ð ˜Ñ!ð%,ð �D‰zð%,ð �C˜�H‰~ð%,ð �3˜ Ñ)Ð)Ñ*ð%,ð �e˜H gÐ-Ñ.Ñ/ó%,ðN ð˜˜W™ò ó ðð ð�t˜D‘zò ó ðð ð�t˜C ˜H‘~ò ó ðð ð.˜U 3¨ 8™_ò .ó ð.ð ðQ˜E # s (™Oò Qó ðQð ð(˜5  c ™?ò (ó ð(ð ð(˜5  c ™?ò (ó ð(ð Ø×Ñð
,¨¨c°8¨mÑ)<ò 
,ó ó ð
,ð	˜Cð 	 H¨T¡Nó 	ð	˜Cð 	 Có 	ð ?Dò !˜Cð !¨ð !°tð !Èó !ð B #ð B¨(°3©-ó Bð
˜cð 
 h¨t¡nó 
ð5˜cð 5 hó 5ðF Cð F¨H°XÑ,>ó Fð*˜cð *¨(°8Ñ*<ð *Àó *ð4˜Sð 4 Tó 4ð4˜Sð 4 Xó 4ð4˜Sð 4¨ð 4°dó 4ðD 3ð D¨8°HÑ+=ó Dð4˜Sð 4¨ð 4°dó 4ð	˜Cð 	 H¨T¡Nó 	ð	˜Cð 	 Gó 	ðB #ð B¨(°7Ñ*;ó BðJ˜Cð J¨°Ñ(9ð J¸dó Jð6˜#ð 6¨ð 6°%¸¸h¸Ñ2Gó 6ñ
˜H S™Mð °X¸d±^ð Èwó ð2˜cð 2 e¨D°(¸D¸6À3¸;Ñ2GÐ,GÑ&Hó 2ð6˜ð 6 ó 6ð0 yð 0°Tó 0ð ×Ñð,  e¨C°¨H¡o°xÐ&?Ñ!@ò ,ó ð,ð, $)ò V˜Sð V¨X°gÑ->ó Vð	&˜8 GÑ,ó 	&ñ Dð °X¸gÑ5Fó ó,-ð$ @Dò$Øð$Ø*2°8Ñ*<ð$à	ó$ð ð ¨gð ¸$ó ð*
˜t E¨#¨s¨(¡O°U¸8ÀXÐ;MÑ5NÐ$NÑOó 
ð�5ð ˜Uó ð HLñ'#Øð'#Ø# D¨¨e°G¸T°MÑ.BÐ)BÑ$CÑDð'#à	ó'#ðR$˜Sð $ Tó $ó!ð
?˜3ð 
? 4ó 
?ð(˜%ó (ð)˜E $¨ )Ñ,ð )°ó )ð7˜ó 7ðr
# Uð 
#¨wó 
#ð+˜e D¨# IÑ.ð +°7ó +ð˜Tð  gó ð< GKò 
> %¨¨c¨	Ñ"2ð 
>¸tð 
>Ètó 
>ð CGò 	6¨ð 	6¸4ð 	6È4ó 	6ð :>ò - ð -°$ð -À$ó -ð^?˜Sð ? Wó ?ð?˜Sð ? Wó ?ð?˜Sð ? Wó ?ð? ð ?¨ó ?ð?˜Sð ? Wó ?ð? ð ?¨ó ?ð@ #ð @¨'ó @ð?˜Sð ? Wó ?ð@˜Sð @¨wó @ð@ ð @¨ó @ð@ ð @¨ó @ð?˜Sð ? Wó ?ð?˜Sð ? Wó ?ð?˜Cð ? Gô ?r1   Ú_rO   r5   c                 ó,   — t        j                  |«      S )zÝSerialize an attribute value (defaults to msgpack). You can register
    custom serializers using the @serialize_attr.register decorator with the
    type to serialize, e.g.: @serialize_attr.register(MyCustomObject).
    )r  r  ©ru  rO   r5   r(   s       r/   r  r  G  ó   € ô ×Ñ˜uÓ%Ð%r1   c                 ó,   — t        j                  |«      S )zçDeserialize an attribute value (defaults to msgpack). You can register
    custom deserializers using the @deserialize_attr.register decorator with the
    type to deserialize, e.g.: @deserialize_attr.register(MyCustomObject).
    )r  r  rw  s       r/   r)  r)  P  rx  r1   Ú_ModelTÚmappingc                 óØ   — | j                  «       D ]V  }|j                  |v sŒ||j                     }|j                  «       D ]#  \  }}||j                  v sŒ||j                  |<   Œ% ŒX | S )z–Walk over the model's nodes, changing the value of attributes using the
    provided mapping, which maps node names to attr names to attr values.
    )r    r5   rL   rE   )r(   r{  r´   rE   r,  rO   s         r/   Úchange_attr_valuesr}  \  sm   € ð —
‘
“ò -ˆØ�9‰9˜ÒØ˜DŸI™IÑ&ˆEØ$Ÿ{™{›}ò -‘��eØ˜4Ÿ:™:Ò%Ø',�D—J‘J˜tÒ$ñ-ð-ð €Lr1   Údropout_rateÚdropc                 óz   — | j                  «       D ]'  }|D ]   }||j                  v sŒ||j                  |<   Œ" Œ) | S )z–Walk over the model's nodes, setting the dropout rate. You can specify
    one or more attribute names, by default it looks for ["dropout_rate"].
    )r    rE   )r(   r  rE   r´   r,  s        r/   Úset_dropout_rater�  i  sI   € ð —
‘
“ò (ˆØò 	(ˆDØ�t—z‘zÒ!Ø#'�—
‘
˜4Ò ñ	(ð(ð €Lr1   Úwrapperc                 ó~   — t        | j                  «       «      D ]  }| j                  | ||«      «       Œ  || «      S )zORecursively wrap a model and its submodules. The model is updated
    in-place.)rK   r    râ   )r(   r‚  r´   s      r/   Úwrap_model_recursiver„  t  s>   € ô �U—Z‘Z“\Ó"ò 0ˆØ×Ñ˜4¡¨£Õ/ð0ñ �5‹>Ðr1   )r$   r  r)  r}  r�  r„  )r(   r$   r)   r$   )=r¹   rè   Ú	functoolsrn  Úcontextvarsr   Úpathlibr   Útypingr   r   r   r   r	   r
   r   r   r   r   r   r   r   r   r  Úbackendsr   r   r   r   r   Ú
optimizersr   rD   r   Útypesr   Úutilr   r   r   r   r    r!   r"   r#   r&   rJ   rm  r0   r$   Úsingledispatchr  rt  r  r)  rz  r}  Úfloatr�  r„  Ú__all__r,   r1   r/   ú<module>r�     s¢  ðÜ Û Û Û Ý "Ý ÷÷ ÷ ÷ ó" ç JÕ JÝ !Ý Ý ÷õ ñ ˆeƒn€Ùˆvƒ€Ù�˜wÔ'€á&0Ð1DÈbÔ&QÐ �:˜dÑ#Ó QóôS?ˆG�C˜�IÑô S?ðl ×Ñð&�cð & #ð &¨Sð &¸ð &À5ò &ó ð&ð ×Ñð&˜ð & Cð &¨sð &¸5ð &ÀSò &ó ð&ñ �) 5Ô
)€ð
˜gð 
°°S¸$¸sÀC¸x¹.Ð5HÑ0Ið 
Ègó 
ð :HÐ8Hñ ˜Gð ¨5ð ÈWó ð ð °¸%¸À'Ð9IÑ0Jð Èwó ò�r1   