
    BVhY                     B    d Z ddlmZ ddlmZ ddlmZ  G d de      Z	y)z&A python interface for Grappler items.    )op_performance_data_pb2)meta_graph_pb2)_pywrap_tf_itemc                   V    e Zd ZdZ	 	 d
dZddZd Zd Zed        Z	ed        Z
d Zy	)ItemzGrapplerItem.c                     || _         t        j                         | _        | j                  j	                  |       || _        || _        d| _        | j                          y)a|  Creates an Item.

    Args:
      metagraph: a TensorFlow metagraph.
      ignore_colocation: if set, the tool will ignore all the colocation
        constraints generated by TensorFlow.
      ignore_user_placement: if set, all the placement annotations annotated in
        the metagraph will be ignored.
    Raises:
      ValueError: the metagraph is incomplete or invalid.
    N)	
_metagraphr   MetaGraphDef_item_graphCopyFrom_ignore_colocation_ignore_user_placement_tf_item_BuildTFItem)self	metagraphignore_colocationignore_user_placements       O/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/grappler/item.py__init__zItem.__init__   sS      DO%224Di(/D"7DDM    c                 B    t        j                  | j                   |      S N)tf_itemTF_IdentifyImportantOps)r   sort_topologicallys     r   IdentifyImportantOpszItem.IdentifyImportantOps0   s    **4<<9KLLr   c                    t        j                  | j                         }i }|j                         D ]K  \  }}g }|D ]:  }|j                  t        j
                  j                  j                  |             < |||<   M |S )zGet Op properties.)r   TF_GetOpPropertiesitemsappendr   OpInfoTensorProperties
FromString)r   props
propertieskeyvaluespropvalues          r   GetOpPropertieszItem.GetOpProperties3   s    &&t||4EJ{{} Vd O% 	#**;;FFuM	OO
 jo r   c                 @    t        j                  | j                         S )zReturn a list of hard colocation constraints.

    All the nodes in a colocation tuple must be placed on the same device for
    the model to work.

    Returns:
      A list of colocation tuples.
    )r   TF_GetColocationGroupsr   s    r   GetColocationGroupszItem.GetColocationGroupsA   s     ))$,,77r   c                     | j                   S r   )r	   r.   s    r   r   zItem.metagraphL   s    ??r   c                     | j                   | j                  k7  r5| j                          | j                   j                  | j                         | j                  S r   )r   r	   r   r   r   r.   s    r   r   zItem.tf_itemP   sB    4??*

0==r   c                     t        j                  | j                  j                         | j                  | j
                        | _        y r   )r   
TF_NewItemr	   SerializeToStringr   r   r   r.   s    r   r   zItem._BuildTFItemW   s6    &&t'H'H'J'+'>'>'+'B'BDDMr   N)TF)F)__name__
__module____qualname____doc__r   r   r+   r/   propertyr   r   r    r   r   r   r      sP     "&%*.M	8    Dr   r   N)
r8   tensorflow.core.grappler.costsr   tensorflow.core.protobufr   tensorflow.python.grapplerr   r   objectr   r:   r   r   <module>r?      s#    - B 3 ADD6 DDr   