
    &VfT                         d dl Z d dlZd dlmZ d dlmZ  ej                    a ej                    ad Z	ddZ
 eddg          dd
            ZdS )    N)backend)keras_exportc                 2    t          t          | |           d S N)setattrGLOBAL_STATE_TRACKER)namevalues     b/var/www/html/software/conda/lib/python3.11/site-packages/keras/src/backend/common/global_state.pyset_global_attributer      s     $.....    Fc                 b    t          t          | d           }|||}|rt          | |           |S r   )getattrr   r   )r	   defaultset_to_defaultattrs       r   get_global_attributer      s@    't44D|+ 	- t,,,Kr   zkeras.utils.clear_sessionzkeras.backend.clear_sessionTc                    t          j                    at          j                    at	          j                    dk    reddlm} |j        j        	                                 |
                                r,ddlm} |                                                                 n1t	          j                    dk    rddlm} |                                 | rt#          j                     dS dS )a4  Resets all state generated by Keras.

    Keras manages a global state, which it uses to implement the Functional
    model-building API and to uniquify autogenerated layer names.

    If you are creating many models in a loop, this global state will consume
    an increasing amount of memory over time, and you may want to clear it.
    Calling `clear_session()` releases the global state: this helps avoid
    clutter from old models and layers, especially when memory is limited.

    Args:
        free_memory: Whether to call Python garbage collection.
            It's usually a good practice to call it to make sure
            memory used by deleted objects is immediately freed.
            However, it may take a few seconds to execute, so
            when using `clear_session()` in a short loop,
            you may want to skip it.

    Example 1: calling `clear_session()` when creating models in a loop

    ```python
    for _ in range(100):
      # Without `clear_session()`, each iteration of this loop will
      # slightly increase the size of the global state managed by Keras
      model = keras.Sequential([
          keras.layers.Dense(10) for _ in range(10)])

    for _ in range(100):
      # With `clear_session()` called at the beginning,
      # Keras starts with a blank state at each iteration
      # and memory consumption is constant over time.
      keras.backend.clear_session()
      model = keras.Sequential([
          keras.layers.Dense(10) for _ in range(10)])
    ```

    Example 2: resetting the layer name generation counter

    >>> layers = [keras.layers.Dense(10) for _ in range(10)]
    >>> new_layer = keras.layers.Dense(10)
    >>> print(new_layer.name)
    dense_10
    >>> keras.backend.clear_session()
    >>> new_layer = keras.layers.Dense(10)
    >>> print(new_layer.name)
    dense
    
tensorflowr   )r   )contexttorchN)	threadinglocalr   GLOBAL_SETTINGS_TRACKERr   keras.src.utils.module_utilsr   compatv1reset_default_graphexecuting_eagerlytensorflow.python.eagerr   clear_kernel_cachetorch._dynamo_dynamoresetgccollect)free_memorytfr   dynamos       r   clear_sessionr*      s    h %?,,'o//L((AAAAAA
	((***!! 	3 877777OO00222			g	%	%&&&&&& 	 

 r   )NF)T)r%   r   	keras.srcr   keras.src.api_exportr   r   r   r   r   r   r*    r   r   <module>r.      s    				           - - - - - -&y(( ))/++ / / /    *,IJKKI I I LKI I Ir   