o
    2h                     @   s4   d Z ddlmZ dd Zdd Zdd Zd	d
 ZdS )zUtilities for graph plugin.    )	graph_pb2c                 C      d| |f S )Nz%s/%s )prefixop_namer   r   _/var/www/html/chatgem/venv/lib/python3.10/site-packages/tensorboard/plugins/graph/graph_util.py_prefixed_op_name   s   r   c                 C   r   )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
    z%s_%sr   )r   	func_namer   r   r   _prefixed_func_name   s   r
   c           	         s   |j D ];}|j  }|| t |j|_ fdd|jD |jd d < |jdkr>|jd r>t |jd j	j|jd j	_q|j
jD ]}|j
j }|| t |jj|j_qC|j
jD ]}|j
j }|| t |j|_t |j|_q^d S )Nc                    s   g | ]}t  |qS r   )r   ).0
input_namer   r   r   
<listcomp>/   s    
z-_add_with_prepended_names.<locals>.<listcomp>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_noder   new_funcr   new_gradientr   r   r   _add_with_prepended_names*   s>   






r$   c                 C   s   t | dkr
| d S t | dkrt S t }| d jjr'|j| d j t| D ]\}}|jj|jjkr;tdtd|d  || q+|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_defr   r   r   merge_graph_defsP   s    
r0   N)__doc__tensorboard.compat.protor   r   r
   r$   r0   r   r   r   r   <module>   s   &