a
    \=icY  ã                   @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZ	dS )z&A python interface for Grappler items.é    )Úop_performance_data_pb2)Úmeta_graph_pb2)Ú_pywrap_tf_itemc                   @   sT   e Zd ZdZddd„Zddd„Zdd	„ Zd
d„ Zedd„ ƒZ	edd„ ƒZ
dd„ ZdS )ÚItemzGrapplerItem.TFc                 C   s:   || _ t ¡ | _| j |¡ || _|| _d| _|  ¡  dS )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   ZMetaGraphDefÚ_item_graphÚCopyFromÚ_ignore_colocationÚ_ignore_user_placementÚ_tf_itemÚ_BuildTFItem)ÚselfÚ	metagraphZignore_colocationZignore_user_placement© r   úp/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/tensorflow/python/grappler/item.pyÚ__init__   s    
zItem.__init__c                 C   s   t  | j |¡S ©N)Útf_itemZTF_IdentifyImportantOps)r   Zsort_topologicallyr   r   r   ÚIdentifyImportantOps0   s    zItem.IdentifyImportantOpsc                 C   sP   t  | j ¡}i }| ¡ D ]2\}}g }|D ]}| tjj |¡¡ q(|||< q|S )zGet Op properties.)r   ZTF_GetOpPropertiesÚitemsÚappendr   ZOpInfoZTensorPropertiesZ
FromString)r   ÚpropsÚ
propertiesÚkeyÚvaluesÚpropÚvaluer   r   r   ÚGetOpProperties3   s    ÿ
zItem.GetOpPropertiesc                 C   s   t  | j ¡S )zÉReturn 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   ZTF_GetColocationGroups©r   r   r   r   ÚGetColocationGroupsA   s    	zItem.GetColocationGroupsc                 C   s   | j S r   )r   r   r   r   r   r   L   s    zItem.metagraphc                 C   s(   | j | jkr"|  ¡  | j  | j¡ | jS r   )r   r   r   r   r   r   r   r   r   r   P   s    zItem.tf_itemc                 C   s   t  | j ¡ | j| j¡| _d S r   )r   Z
TF_NewItemr   ZSerializeToStringr	   r
   r   r   r   r   r   r   W   s    þzItem._BuildTFItemN)TF)F)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úpropertyr   r   r   r   r   r   r   r      s     ý



r   N)
r#   Ztensorflow.core.grappler.costsr   Ztensorflow.core.protobufr   Ztensorflow.python.grapplerr   r   Úobjectr   r   r   r   r   Ú<module>   s   