o
    Õ2úhÃ  ã                   @   sB   d Z dZdd„ Zdd„ Zdaddd	„Zd
d„ ZG dd„ deƒZdS )zÃCheckpoint 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                    s   ‡ fd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                    s   t | tˆ ƒ | S ©N)Úsetattrr   ©Ú
cls_or_obj©Úname© úg/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorflow/python/checkpoint/saveable_compat.pyÚ	decoratorE   s   z'legacy_saveable_name.<locals>.decoratorr   )r   r
   r   r   r	   Úlegacy_saveable_name   s   -r   c                 C   s   t | td ƒS r   )Úgetattrr   r   r   r   r	   Úget_saveable_nameK   s   r   FTc                 C   s   | a dS )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)Úvaluer   r   r	   Úforce_checkpoint_conversionR   s   r   c                   C   s   t S r   r   r   r   r   r	   Ú#force_checkpoint_conversion_enabledn   s   r   c                   @   s   e Zd ZdS )ÚCheckpointConversionErrorN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r	   r   r   s    r   N)T)	Ú__doc__r   r   r   r   r   r   Ú	Exceptionr   r   r   r   r	   Ú<module>   s   3
