a
    0Sic                     @   s   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ ed
g dG dd de	jZdS )z*Dependency tracking for trackable objects.    N)logging)def_function)function)base)data_structures)core)	tf_exportz#__internal__.tracking.AutoTrackable)v1c                       sX   e Zd ZdZ fddZ fddZdd Zejj	f fdd		Z
d
d Zdd Z  ZS )AutoTrackablea  Manages dependencies on other objects.

  `Trackable` objects may have dependencies: other `Trackable` objects
  which should be saved if the object declaring the dependency is saved. A
  correctly saveable program has a dependency graph such that if changing a
  global variable affects an object (e.g. changes the behavior of any of its
  methods) then there is a chain of dependencies from the influenced object to
  the variable.

  Dependency edges have names, and are created implicitly when a
  `Trackable` object is assigned to an attribute of another
  `Trackable` object. For example:

  ```
  obj = Trackable()
  obj.v = ResourceVariable(0.)
  ```

  The `Trackable` object `obj` now has a dependency named "v" on a
  variable.

  `Trackable` objects may specify `Tensor`s to be saved and restored
  directly (e.g. a `Variable` indicating how to save itself) rather than through
  dependencies on other objects. See
  `Trackable._gather_saveables_for_checkpoint` for details.
  c                    s^   zt | ||u rW dS W n ty*   Y n0 t | ddrHtj| ||d}tt| || dS )z$Support self.foo = trackable syntax.N_self_setattr_trackingT)	trackablevaluename)getattrAttributeErrorr   sticky_attribute_assignmentsuperr
   __setattr__selfr   r   	__class__ e/var/www/html/django/DPS/env/lib/python3.9/site-packages/tensorflow/python/trackable/autotrackable.pyr   :   s    
zAutoTrackable.__setattr__c                    s   |  | tt| | d S N)_delete_trackingr   r
   __delattr__)r   r   r   r   r   r   H   s    
zAutoTrackable.__delattr__c                 C   s
   t |S )z?Override to allow TrackableBase to disable dependency tracking.)r   NoDependency)r   r   r   r   r   _no_dependencyL   s    zAutoTrackable._no_dependencyc                    s|  |t jjkr$tt| j|fi |S i }zt }ttj	 t
| D ]x}zBt & td t| |d}W d   n1 s0    Y  W n ty   d}Y n0 t|tjtjfrF|||< qFW t| nt| 0 | D ]}t|tjr|  qi }| jD ]f\}	}
t|
tjtjfr&q|	|v rb|
||	 urbtd|  d|	 d|
 d||	  |
||	< q|| |S )z9Returns all children of a trackable, including functions.ignoreNzOCan't save object because it has multiple children with the same name. Object: z, attribute name: z, child 1: z, child 2: )r   SaveType
SAVEDMODELr   r
   _trackable_childrenr   get_verbosityset_verbosityFATALdirwarningscatch_warningssimplefilterr   	Exception
isinstancer   FunctiondefunConcreteFunctionvalues
core_typesGenericFunction._list_all_concrete_functions_for_serialization_checkpoint_dependencies
ValueErrorupdate)r   	save_typekwargs	functionsZlogging_verbosityattribute_nameZattribute_valuefnchildrenr   childr   r   r   r"   P   s\    


.


z!AutoTrackable._trackable_childrenc                 C   sJ   |    || jv rF| j|= t| jD ] \}\}}||kr$| j|=  qFq$dS )zRemoves the tracking of name.N)_maybe_initialize_trackable_unconditional_dependency_names	enumerate&_unconditional_checkpoint_dependencies)r   r   indexZdep_name_r   r   r   r      s    
zAutoTrackable._delete_trackingc                 C   s   |  || d S r   )r   r   r   r   r   _add_trackable_child   s    z"AutoTrackable._add_trackable_child)__name__
__module____qualname____doc__r   r   r   r   r    
CHECKPOINTr"   r   rC   __classcell__r   r   r   r   r
      s   <r
   )rG   r'   abslr   tensorflow.python.eagerr   r   r-   tensorflow.python.trackabler   r   tensorflow.python.typesr   r0    tensorflow.python.util.tf_exportr   	Trackabler
   r   r   r   r   <module>   s   
