Ë
    2ÆVhS  ã                   óR   — d dl mZ d dlmZ  ed«       G d„ d«      «       Zd„ Zd„ Zy)	é    )Úkeras_export)Úglobal_statezkeras.StatelessScopec                   ó<   — e Zd ZdZ	 	 	 d	d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)
ÚStatelessScopea˜  Scope to prevent any update to Keras Variables.

    The values of variables to be used inside the scope
    should be passed via the `state_mapping` argument, a
    list of tuples `(k, v)` where `k` is a `Variable`
    and `v` is the intended value for this variable
    (a backend tensor).

    Updated values can be collected on scope exit via
    `value = scope.get_current_value(variable)`. No updates
    will be applied in-place to any variables for the duration
    of the scope.

    Example:

    ```python
    state_mapping = [(k, ops.ones(k.shape, k.dtype)) for k in model.weights]
    with keras.StatelessScope(state_mapping) as scope:
        outputs = model.some_function(inputs)

    # All model variables remain unchanged. Their new values can be
    # collected via:
    for k in model.weights:
        new_value = scope.get_current_value(k)
        print(f"New value for {k}: {new_value})
    ```
    Nc           
      óê  — ddl m} ddlm} || _        || _        g | _        i | _        |xs i }|D ]À  \  }}t        ||«      st        d|› «      ‚t        ||«      r(|j                  |j                  |j                  ¬«      }n|j                  ||j                  ¬«      }|j                  |j                  k7  rt        d|› d|› d|j                  › d	«      ‚|| j                  t        |«      <   ŒÂ y )
Nr   )Úbackend)ÚVariablez{Invalid reference variable in StatelessScope: all keys in argument `mapping` must be Variable instances. Received instead: )Údtypez¤Invalid variable value in StatelessScope: all values in argument `mapping` must be tensors with a shape that matches the corresponding variable shape. For variable z, received invalid value z with shape ú.)Ú	keras.srcr   Ú"keras.src.backend.common.variablesr	   Úcollect_lossesÚinitialize_variablesÚlossesÚstate_mappingÚ
isinstanceÚ
ValueErrorÚcastÚvaluer
   Úconvert_to_tensorÚshapeÚid)Úselfr   r   r   r   r	   ÚkÚvs           úX/home/dcms/DCMS/lib/python3.12/site-packages/keras/src/backend/common/stateless_scope.pyÚ__init__zStatelessScope.__init__#   s  € õ 	&Ý?à,ˆÔØ$8ˆÔ!ØˆŒØˆÔØ%Ò+¨ˆØ!ò 	*‰DˆAˆqÜ˜a Ô*Ü ð4à45°3ð8óð ô
 ˜!˜XÔ&Ø—L‘L §¡°·±LÓ8‘à×-Ñ-¨a°q·w±wÐ-Ó?Øw‰w˜!Ÿ'™'Ò!Ü ð$ð %& 3Ð&?À¸sÀ,Ø—w‘wi˜qð	"óð ð )*ˆD×Ñœr !›uÒ%ñ'	*ó    c                 óP   — t        «       | _        t        j                  d| «       | S ©NÚstateless_scope)Úget_stateless_scopeÚoriginal_scoper   Úset_global_attribute)r   s    r   Ú	__enter__zStatelessScope.__enter__F   s#   € Ü1Ó3ˆÔÜ×)Ñ)Ð*;¸TÔBØˆr   c                 ó:   — | j                   j                  |«       y ©N)r   Úappend)r   Úlosss     r   Úadd_losszStatelessScope.add_lossK   s   € Ø‰×Ñ˜4Õ r   c                 ó>   — |\  }}|| j                   t        |«      <   y r'   )r   r   )r   ÚupdateÚvariabler   s       r   Ú
add_updatezStatelessScope.add_updateN   s   € Ø ‰ˆ%Ø+0ˆ×Ñœ2˜h›<Ò(r   c                 óL   — | j                   j                  t        |«      d «      S r'   )r   Úgetr   )r   r-   s     r   Úget_current_valuez StatelessScope.get_current_valueR   s   € Ø×!Ñ!×%Ñ%¤b¨£l°DÓ9Ð9r   c                 ó’   — t        j                  d| j                  «       | j                  €| j                  rddlm}  |«        y y y )Nr!   r   )Úinitialize_all_variables)r   r$   r#   r   r   r3   )r   ÚargsÚkwargsr3   s       r   Ú__exit__zStatelessScope.__exit__U   sG   € Ü×)Ñ)Ø˜t×2Ñ2ô	
ð ×ÑÐ&¨4×+DÒ+Dõñ %Õ&ð ,EÐ&r   )NFT)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r%   r*   r.   r1   r6   © r   r   r   r      s1   „ ñð< ØØ!ó	!*òFò
!ò1ò:ó'r   r   c                  ó0   — t        j                  d«      d uS r    ©r   Úget_global_attributer;   r   r   Úin_stateless_scoper?   d   s   € Ü×,Ñ,Ð->Ó?ÀtÐKÐKr   c                  ó,   — t        j                  d«      S r    r=   r;   r   r   r"   r"   h   s   € Ü×,Ñ,Ð->Ó?Ð?r   N)Úkeras.src.api_exportr   Úkeras.src.backend.commonr   r   r?   r"   r;   r   r   ú<module>rC      s:   ðÝ -Ý 1ñ Ð$Ó%÷['ð ['ó &ð['ò|Ló@r   