o
    ?e                     @   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w t | ddr$tj| ||d}tt| || dS )z$Support self.foo = trackable syntax.NZ_self_setattr_trackingT)Z	trackablevaluename)getattrAttributeErrorr   Zsticky_attribute_assignmentsuperr
   __setattr__selfr   r   	__class__ j/home/www/facesmatcher.com/pyenv/lib/python3.10/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   ZNoDependency)r   r   r   r   r   _no_dependencyL   s   
zAutoTrackable._no_dependencyc                    sr  |t jjkrtt| j|fi |S i }zRt }ttj	 t
| D ]<}z!t  td t| |d}W d   n1 s@w   Y  W n tyQ   d}Y nw t|tjtjfr_|||< q#W t| nt| w | D ]}t|tjr}|  qqi }| jD ].\}	}
t|
tjtjfrq|	|v r|
||	 urt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   SaveTypeZ
SAVEDMODELr   r
   _trackable_childrenr   Zget_verbosityZset_verbosityFATALdirwarningscatch_warningssimplefilterr   	Exception
isinstancer   FunctiondefunZConcreteFunctionvalues
core_typesZGenericFunctionZ._list_all_concrete_functions_for_serializationZ_checkpoint_dependencies
ValueErrorupdate)r   	save_typekwargsZ	functionsZlogging_verbosityZattribute_nameZattribute_valuefnchildrenr   childr   r   r   r   P   sh   




z!AutoTrackable._trackable_childrenc                 C   sP   |    || jv r$| j|= t| jD ]\}\}}||kr#| j|=  dS qdS dS )zRemoves the tracking of name.N)Z_maybe_initialize_trackableZ_unconditional_dependency_names	enumerateZ&_unconditional_checkpoint_dependencies)r   r   index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   r4   __classcell__r   r   r   r   r
      s    <r
   )r8   r    Zabslr   Ztensorflow.python.eagerr   r   r&   Ztensorflow.python.trackabler   r   Ztensorflow.python.typesr   r(   Z tensorflow.python.util.tf_exportr   Z	Trackabler
   r   r   r   r   <module>   s   
