
    1Vh                     ,    d Z ddlmZ d Zd Zd Zd Zy)zUtilities for graph plugin.    )	graph_pb2c                     | d|S )N/ )prefixop_names     T/home/dcms/DCMS/lib/python3.12/site-packages/tensorboard/plugins/graph/graph_util.py_prefixed_op_namer
      s    g&&    c                     | d|S )aq  Returns function name prefixed with `prefix`.

    For function libraries, which are often created out of autographed Python
    function, are factored out in the graph vis. They are grouped under a
    function name which often has a shape of
    `__inference_[py_func_name]_[numeric_suffix]`.

    While it does not have some unique information about which graph it is from,
    creating another wrapping structure with graph prefix and "/" is less than
    ideal so we join the prefix and func_name using underscore.

    TODO(stephanwlee): add business logic to strip "__inference_" for more user
    friendlier name
    _r   )r   	func_names     r	   _prefixed_func_namer      s     i((r   c                    |j                   D ]  }|j                   j                         }|j                  |       t        | |j                        |_        |j
                  D cg c]  }t        | |       c}|j
                  d d  |j                  dk(  s|j                  d   st        | |j                  d   j                  j                        |j                  d   j                  _         |j                  j                  D ]f  }|j                  j                  j                         }|j                  |       t        | |j                  j                        |j                  _        h |j                  j                  D ]m  }|j                  j                  j                         }	|	j                  |       t        | |	j                        |	_        t        | |	j                        |	_        o y c c}w )NPartitionedCallf)nodeaddCopyFromr
   nameinputopattrr   funclibraryfunction	signaturegradientfunction_namegradient_func)
r   graph_to_adddestination_graphr   new_node
input_namer   new_funcr   new_gradients
             r	   _add_with_prepended_namesr'   *   s   !! $))--/$)&$))<DHJJ
6@fj1
q ;;++c0B+>c"'',,,HMM###(" $$-- 
$,,5599;$"5H&&++#

 !((11 

(0099==?h'%8&&&
" &9&&&
"

)
s   $G8c                    t        |       dk(  r| d   S t        |       dk(  rt        j                         S t        j                         }| d   j                  j                  r(|j                  j                  | d   j                         t        |       D ]P  \  }}|j                  j                  |j                  j                  k7  rt        d      t        d|dz   z  ||       R |S )a  Merges GraphDefs by adding unique prefix, `graph_{ind}`, to names.

    All GraphDefs are expected to be of TensorBoard's.

    When collecting graphs using the `tf.summary.trace` API, node names are not
    guranteed to be unique.  When non-unique names are not considered, it can
    lead to graph visualization showing them as one which creates inaccurate
    depiction of the flow of the graph (e.g., if there are A -> B -> C and D ->
    B -> E, you may see {A, D} -> B -> E).  To prevent such graph, we checked
    for uniquenss while merging but it resulted in
    https://github.com/tensorflow/tensorboard/issues/1929.

    To remedy these issues, we simply "apply name scope" on each graph by
    prefixing it with unique name (with a chance of collision) to create
    unconnected group of graphs.

    In case there is only one graph def passed, it returns the original
    graph_def. In case no graph defs are passed, it returns an empty GraphDef.

    Args:
      graph_defs: TensorBoard GraphDefs to merge.

    Returns:
      TensorBoard GraphDef that merges all graph_defs with unique prefixes.

    Raises:
      ValueError in case GraphDef versions mismatch.
       r   z/Cannot combine GraphDefs of different versions.zgraph_%d)	lenr   GraphDefversionsproducerr   	enumerate
ValueErrorr'   )
graph_defsdst_graph_defindex	graph_defs       r	   merge_graph_defsr4   P   s    : :!!}	ZA	!!##&&(M!}&&''
1(>(>?%j1 
y!!**i.@.@.I.IINOO!%!)$	
	
 r   N)__doc__tensorboard.compat.protor   r
   r   r'   r4   r   r   r	   <module>r7      s"    " .')$#
L1r   