
    BVh                         d Z ddlmZ ddlmZ ddlmZ ddlm	Z	  e	dg        G d d	             Z
 e	d
g       dede
fd       Zy)z{Methods for SavedModel fingerprinting.

This module contains classes and functions for reading the SavedModel
fingerprint.
    )Any)fingerprint_pb2)fingerprinting)	tf_exportz$saved_model.experimental.Fingerprint)v1c                       e Zd ZdZ	 	 	 	 	 	 ddedededededefd	Zed
ej                  dd fd       Z	de
defdZdefdZdefdZdej"                  fdZy)Fingerprintay  The SavedModel fingerprint.

  Each attribute of this class is named after a field name in the
  FingerprintDef proto and contains the value of the respective field in the
  protobuf.

  Attributes:
    saved_model_checksum: A uint64 containing the `saved_model_checksum`.
    graph_def_program_hash: A uint64 containing `graph_def_program_hash`.
    signature_def_hash: A uint64 containing the `signature_def_hash`.
    saved_object_graph_hash: A uint64 containing the `saved_object_graph_hash`.
    checkpoint_hash: A uint64 containing the`checkpoint_hash`.
    version: An int32 containing the producer field of the VersionDef.
  Nsaved_model_checksumgraph_def_program_hashsignature_def_hashsaved_object_graph_hashcheckpoint_hashversionc                 X    || _         || _        || _        || _        || _        || _        y)a  Initializes the instance based on values in the SavedModel fingerprint.

    Args:
      saved_model_checksum: Value of the`saved_model_checksum`.
      graph_def_program_hash: Value of the `graph_def_program_hash`.
      signature_def_hash: Value of the `signature_def_hash`.
      saved_object_graph_hash: Value of the `saved_object_graph_hash`.
      checkpoint_hash: Value of the `checkpoint_hash`.
      version: Value of the producer field of the VersionDef.
    N)r
   r   r   r   r   r   )selfr
   r   r   r   r   r   s          \/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/saved_model/fingerprinting.py__init__zFingerprint.__init__-   s3    & !5D"8D0D#:D *DDL    protoreturnc                 :   t        |t              rt        j                  j	                  |      }	 t        |j                  |j                  |j                  |j                  |j                  |j                        S # t        $ r}t        d|       dd}~ww xY w)z;Constructs Fingerprint object from protocol buffer message.z5Given proto could not be deserialized as fingerprint.N)
isinstancebytesr   FingerprintDef
FromStringr	   r
   r   r   r   r   r   AttributeError
ValueError)clsr   es      r   
from_protozFingerprint.from_protoG   s     %,,77>e

$
$

&
&

"
"

'
'



--   ACs   AA= =	BBBotherc                    t        |t              st        |t        j                        r	 | j                  |j                  k(  xrj | j
                  |j
                  k(  xrO | j                  |j                  k(  xr4 | j                  |j                  k(  xr | j                  |j                  k(  S y# t        $ r Y yw xY w)NF)
r   r	   r   r   r
   r   r   r   r   r   )r   r!   s     r   __eq__zFingerprint.__eq__Y   s    5+&5/889%%)C)CC :''5+G+GG:##u'?'??: ((E,I,II:   E$9$99	;   s   BB2 2	B>=B>c           	          dj                  dd| j                   d| j                   d| j                   d| j                   d| j
                   g      S )N
zSavedModel Fingerprintz  saved_model_checksum: z  graph_def_program_hash: z  signature_def_hash: z  saved_object_graph_hash: z  checkpoint_hash: )joinr
   r   r   r   r   r   s    r   __str__zFingerprint.__str__g   sp    99 
"4#<#<"=>
$T%@%@$AB
 !8!8 9:
%d&B&B%CD
d2234  r   c                     d| j                    d| j                   d| j                   d| j                   d| j                   dS )NzFingerprint(z, ))r
   r   r   r   r   r'   s    r   __repr__zFingerprint.__repr__q   sT    4445R**+2&&'r++,B##$A	' (r   c                 J   	 t        j                  | j                  | j                  | j                  | j
                        S # t        t         j                  f$ rG}t        d| j                   d| j                   d| j                   d| j
                   | 	      dd}~ww xY w)a  Canonical fingerprinting ID for a SavedModel.

    Uniquely identifies a SavedModel based on the regularized fingerprint
    attributes. (saved_model_checksum is sensitive to immaterial changes and
    thus non-deterministic.)

    Returns:
      The string concatenation of `graph_def_program_hash`,
      `signature_def_hash`, `saved_object_graph_hash`, and `checkpoint_hash`
      fingerprint attributes (separated by '/').

    Raises:
      ValueError: If the fingerprint fields cannot be used to construct the
      singleprint.
    z[Encounted invalid fingerprint values when constructing singleprint.graph_def_program_hash: zsignature_def_hash: zsaved_object_graph_hash: zcheckpoint_hash: N)	fingerprinting_pywrapSingleprintr   r   r   r   	TypeErrorFingerprintExceptionr   )r   r   s     r   singleprintzFingerprint.singleprintx   s     "..t/J/J/3/F/F/3/K/K/3/C/CE E ,AAB %%)%@%@$A !8!8 9%d&B&B%Cd223C s   ?A B"ABB")NNNNNN)__name__
__module____qualname____doc__intr   classmethodr   r   r    r   boolr#   strr(   r+   r-   r.   r1    r   r   r	   r	      s    " #'$( $%)! " 	
  #  4 _;;   "# $ s ( (0<< r   r	   z)saved_model.experimental.read_fingerprint
export_dirr   c                 8   	 t        j                  |       }t        j                  t        j                         j                  |            S # t         j                  $ r}t        d|       dd}~wt         j                  $ r}t        d|       dd}~ww xY w)a9  Reads the fingerprint of a SavedModel in `export_dir`.

  Returns a `tf.saved_model.experimental.Fingerprint` object that contains
  the values of the SavedModel fingerprint, which is persisted on disk in the
  `fingerprint.pb` file in the `export_dir`.

  Read more about fingerprints in the SavedModel guide at
  https://www.tensorflow.org/guide/saved_model.

  Args:
    export_dir: The directory that contains the SavedModel.

  Returns:
    A `tf.saved_model.experimental.Fingerprint`.

  Raises:
    FileNotFoundError: If no or an invalid fingerprint is found.
  zSavedModel Fingerprint Error: N)r-   ReadSavedModelFingerprintFileNotFoundExceptionFileNotFoundErrorr0   RuntimeErrorr	   r    r   r   r   )r;   fingerprintr   s      r   read_fingerprintrB      s    (G'AA*MK
 
		$$&11+>
@ @	 
	4	4 L
<QC@
AtK		3	3 G
7s;
<$FGs#   A B A//BBBN)r5   typingr   tensorflow.core.protobufr   0tensorflow.python.saved_model.pywrap_saved_modelr   r-    tensorflow.python.util.tf_exportr   r	   r9   rB   r:   r   r   <module>rG      sk     4 d 6 1b9w w :wt 62>@ @ @ ?@r   