
    BVhN                     t    d 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 dd	lmZ d
 Zd Zy)zEUtilities for tracing save and restore functions for SaveableObjects.    )def_function)dtypes)tensor_spec)	type_spec)resource_variable_ops)saveable_object)saveable_object_util)nestc                     i }|D ]i  }|j                   }|j                  }t        j                  |       s t        j                  |      st	        |      sQt        ||       \  }}|sc||f||<   k |S )a  Traces all save and restore functions in the provided factory list.

  Args:
    obj: `Trackable` object.
    factory_data_list: List of `_CheckpointFactoryData`.

  Returns:
    Dict mapping atttribute names to tuples of concrete save/restore functions.
  )factorynamer   is_resource_variablecallable_trace_save_restore_functions)objfactory_data_listsaveable_fnsfactory_datasaveable_factoryattribute_nameconcrete_saveconcrete_restores           e/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/training/saving/trace_saveable_util.pytrace_save_restore_function_mapr      s     ,' El#++!&&N 	2237223CD%& 	&&6< $M#$13C#DL E  
    c                    
 t        j                         r j                  d    j                  d   fS g 
t        j                  t        j                  g t        j                        g       
fd       }|j                         }t        j                  
|      

syg }g 
D ]o  }g }j                  |       |j                  D ]K  }|j                  t        j                  |j                               |j                  |j                          M q t        j                  |      
fd       }|j                         }	||	fS )z"Traces save and restore functions.save_functionrestore_function)input_signaturec                      |       }t        |t        j                        r|g}|d d  g }D ]F  }|j                  D ]5  }|j	                  |j
                  |j                  |j                  d       7 H |S )N)r   )r   tensor
slice_spec)
isinstancer   SaveableObjectspecsappendr   r!   r"   )checkpoint_keymaybe_saveableretsaveablespecr   	saveabless        r   save_fnz._trace_save_restore_functions.<locals>.save_fnG   s     &>:N./"@"@A&'n!IaL C 4.. 4$

DII"&//3 	444 Jr   )NNc                      t        j                  |       }t        |      D ]  \  }} |j                  | d         y)N)restored_shapes   )r
   pack_sequence_asziprestore)restored_tensorsstructured_restored_tensorsr*   r,   tensor_structures      r   
restore_fnz1_trace_save_restore_functions.<locals>.restore_fnj   sS    "&"7"7*#,&))*E'G ?""'>? r   )r	   'is_factory_for_restored_saveable_objectkeywordsr   functionr   
TensorSpecr   stringget_concrete_function"validate_saveables_for_saved_modelr&   r%   r   type_spec_from_valuer!   r   )r   r   r-   r   restored_type_specsr*   saveable_tensor_structurer+   r7   r   r,   r6   s   `         @@r   r   r   ;   sX   AA 	!!/2!!"45 
 ) "--b&--@A //1- #EE)	  2h "56 2  !?!?!LM&&tyy122 )<= >  557	(	((r   N)__doc__tensorflow.python.eagerr   tensorflow.python.frameworkr   r   r   tensorflow.python.opsr   !tensorflow.python.training.savingr   r	   tensorflow.python.utilr
   r   r    r   r   <module>rI      s-    L 0 . 3 1 7 = B '>9)r   