
    BVh                     @    d Z dZd Zd Zdad
dZd Z G d de      Zy	)zCheckpoint compatibility functions with SaveableObject.

Compatibility methods to ensure that checkpoints are saved with the same
metadata attributes before/after the SaveableObject deprecation.
_LEGACY_SAVEABLE_NAMEc                       fd}|S )aD  Decorator to set the local name to use in the Checkpoint.

  Needed for migrating certain Trackables (see next paragraph) from the legacy
  `_gather_saveables_for_checkpoint` to the new `_serialize_to_tensors`
  function.

  This decorator should be used if the SaveableObject generates tensors with
  different names from the name that is passed to the factory.

  Example migration:

  *Before*

  ```
  class MyTrackable(Trackable):
    def _gather_saveables_for_checkpoint(self):
      return {"key": _MySaveable}

  class _MySaveable(SaveableObject):
    def __init__(self, name):
      specs = [
          SaveSpec(tensor1, "", name + "-1")
          SaveSpec(tensor2, "", name + "-2")
      ]
      super().__init__(None, specs, name)
  ```

  *After*

  ```
  @legacy_saveable_name("key")
  class MyTrackable(Trackable):

    def _serialize_to_tensors(self):
      return {"key-1": tensor1, "key-2": tensor2}
  ```

  Args:
    name: String name of the SaveableObject factory (the key returned in the
       `_gather_saveables_for_checkpoint` function)

  Returns:
    A decorator.
  c                 *    t        | t               | S N)setattrr   )
cls_or_objnames    \/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/checkpoint/saveable_compat.py	decoratorz'legacy_saveable_name.<locals>.decoratorE   s    J-t4     )r   r
   s   ` r	   legacy_saveable_namer      s    Z 
r   c                 $    t        | t        d       S r   )getattrr   )r   s    r	   get_saveable_namer   K   s    	2D	99r   Fc                     | a y)ac  Forces checkpoint to use the new implementation.

  The new checkpoint implementation is changing the saved metadata slightly,
  and therefore may break forward compatibility in newly saved checkpoints. This
  means:

    - Previous versions of TensorFlow may not be able to load new checkpoints.
    - Backwards compatibility is unchanged: Old checkpoints can still be loaded.

  TensorFlow guarantees 3 weeks of forward compatibility, so this flag will be
  removed in the future weeks, after which checkpoint conversion will happen by
  default.

  **What happens when this flag is enabled?**

  The checkpoint will be saved with different metadata, meaning that previous
  versions of TensorFlow (<=2.10) will not be able to load this checkpoint.

  Args:
    value: Boolean value, whether or not to force checkpoint conversion to the
      new implementation.
  N_FORCE_CHECKPOINT_CONVERSION)values    r	   force_checkpoint_conversionr   R   s
    2 "'r   c                      t         S r   r   r   r   r	   #force_checkpoint_conversion_enabledr   n   s    	%%r   c                       e Zd Zy)CheckpointConversionErrorN)__name__
__module____qualname__r   r   r	   r   r   r   s    r   r   N)T)	__doc__r   r   r   r   r   r   	Exceptionr   r   r   r	   <module>r      s;    0 0f:  % '8&	 r   