
    AVh                        d Z ddlZddlZddlZddlZddlZddlZddlmZ ddlm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z! ddlm"Z" ddl#m$Z% ddl&m'Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl-m/Z/ ddl0m1Z1 dZ2 G d dejf                        Z4 e4       Z5 G d  d!      Z6d" Z7 e1d#g $      d%        Z8d& Z9d' Z: e1d(g $      e/jv                  d)               Z<d* Z=drd+Z>d, Z?d- Z@ e1d.g $      d/        ZA e1d0g $      d1        ZB e1d2g $       G d3 d4ej                  5             ZD G d6 d7eD      ZE G d8 d9 eFeE       eFe*j                              ZH G d: d;eEe*j                  eH5      ZI G d< d=eD      ZJ G d> d?eD      ZK e1d@g$      	 	 dsdA       ZL e1dBg $      	 	 	 	 	 	 dtdC       ZM	 	 	 	 dudDZN e1dEg $      dF        ZOdG ZPdH ZQ e1dIg$      dJ        ZRdK ZS ej                  dL      ZU e1dMg $      e/jv                  dvdN              ZV e1dOg $      dwdP       ZW e1dQg $      dsdR       ZXdrdSZYdwdTZZdsdUZ[dsdVZ\dxdWZ]dsdXZ^dsdYZ_ e1dZg $      d[        Z`drd\Za e1d]g $      dsd^       Zbdsd_Zcdrd`Zd e.j                  ddab      dc        Zfdd Zgde Zhdf ZidrdgZjdrdhZk ej                  didj      Zm ej                         Zodap e1dkg $      dydl       Zq e1dmg $      dsdn       Zr e1dog $      dp        Zsdq Zty)zzOperations to emit summaries.    N)	graph_pb2)summary_pb2)
config_pb2)api)layout)context)constant_op)dtypes)ops)
smart_cond)tensor)tensor_util)	array_ops)control_flow_ops)gen_resource_variable_ops)gen_summary_ops)math_ops)resource_variable_ops)summary_op_util)
tf_logging)profiler_v2)resource)training_util)deprecation)tf_contextlib)	tf_export_SUMMARY_WRITER_V2c                        e Zd Z fdZ xZS )_SummaryStatec                 b    t         t        |           d | _        d| _        d | _        d | _        y )NT)superr   __init__is_recording"is_recording_distribution_strategywriterstep)self	__class__s    T/home/dcms/DCMS/lib/python3.12/site-packages/tensorflow/python/ops/summary_ops_v2.pyr"   z_SummaryState.__init__<   s.    	-')D.2D+DKDI    )__name__
__module____qualname__r"   __classcell__r(   s   @r)   r   r   :   s     r*   r   c                   $    e Zd ZdZddZd Zd Zy)_SummaryContextManagerz8Context manager to implement SummaryWriter.as_default().Nc                 <    || _         || _        d | _        d | _        y N)_writer_step_old_writer	_old_step)r'   r%   r&   s      r)   r"   z_SummaryContextManager.__init__N   s    DLDJDDNr*   c                     t         j                  | _        | j                  t         _        | j                  *t         j
                  | _        | j                  t         _        | j                  S r3   )_summary_stater%   r6   r4   r5   r&   r7   r'   s    r)   	__enter__z _SummaryContextManager.__enter__T   sI    %,,D LLNzz%**dn JJn<<r*   c                     t         j                  j                          | j                  t         _        | j                  | j
                  t         _        yNF)r9   r%   flushr6   r5   r7   r&   )r'   excs     r)   __exit__z_SummaryContextManager.__exit__\   s=     ! ,,Nzz NNnr*   r3   )r+   r,   r-   __doc__r"   r;   r@    r*   r)   r1   r1   H   s    @
r*   r1   c                    t         j                  t        j                  d      S t	        t         j
                        s<t        j                  t         j
                        }||st        j                  d      S d } |t         j                        } |t         j
                        }|| }t        j                  ||      S )a  Returns boolean Tensor if summaries should/shouldn't be recorded.

  Now the summary condition is decided by logical "and" of below conditions:
  First, summary writer must be set. Given this constraint is met,
  ctx.summary_recording and ctx.summary_recording_distribution_strategy.
  The former one is usually set by user, and the latter one is controlled
  by DistributionStrategy (tf.distribute.ReplicaContext).

  Args:
    default_state: can be True or False. The default summary behavior when
    summary writer is set and the user does not specify
    ctx.summary_recording and ctx.summary_recording_distribution_strategy
    is True.
  Fc                 *    t        |       r |        S | S r3   )callable)xs    r)   <lambda>z3_should_record_summaries_internal.<locals>.<lambda>}   s    Xa[ac a r*   )r9   r%   r	   constantrE   r#   r   constant_valuer$   r   logical_and)default_statestatic_condresolvecond_distributedconds        r)   !_should_record_summaries_internalrP   f   s     "&&	.--	.,,^-H-HIK{!!%((/'^NNO	,,	-$	\D			.	55r*   zsummary.should_record_summaries)v1c                      t        d      S )a  Returns boolean Tensor which is True if summaries will be recorded.

  If no default summary writer is currently registered, this always returns
  False. Otherwise, this reflects the recording condition has been set via
  `tf.summary.record_if()` (except that it may return False for some replicas
  when using `tf.distribute.Strategy`). If no recording condition is active,
  it defaults to True.
  TrK   rP   rB   r*   r)   should_record_summariesrU      s     
+	>>r*   c                      t        d      S )zEReturns boolean Tensor which is true if summaries should be recorded.FrS   rT   rB   r*   r)   '_legacy_contrib_should_record_summariesrW      s    	*	??r*   c                  J    t         j                  duxr t         j                  S )zFReturns non-Tensor boolean indicating if summaries are being recorded.Nr9   r#   rB   r*   r)   is_recording_summariesrZ      s    		$	$D	0	P^5P5PPr*   zsummary.record_ifc              #      K   t         j                  }	 | t         _        d |t         _        y# |t         _        w xY ww)a  Sets summary recording on or off per the provided boolean value.

  The provided value can be a python boolean, a scalar boolean Tensor, or
  or a callable providing such a value; if a callable is passed it will be
  invoked on-demand to determine whether summary writing will occur.  Note that
  when calling record_if() in an eager mode context, if you intend to provide a
  varying condition like `step % 100 == 0`, you must wrap this in a
  callable to avoid immediate eager evaluation of the condition.  In particular,
  using a callable is the only way to have your condition evaluated as part of
  the traced body of an @tf.function that is invoked from within the
  `record_if()` context.

  Args:
    condition: can be True, False, a bool Tensor, or a callable providing such.

  Yields:
    Returns a context manager that sets this value on enter and restores the
    previous value on exit.
  NrY   )	conditionolds     r)   	record_ifr^      s3     , 	###&"+N	"%N#Ns   ?/ ?<?c                  &    t         j                  duS )zEReturns a boolean indicating whether a default summary writer exists.N)r9   r%   rB   r*   r)   has_default_writerr`      s    			d	**r*   c                      t        j                         t        j                  d      5   fd}t	        j
                         s |       }ddd       t        |      S # 1 sw Y   t              S xY w)zHSets the should_record_summaries Tensor to true if global_step % n == 0.Ncpu:0c                  6    t        j                   z  d      S )Nr   )r   equal)global_stepns   r)   rG   z7record_summaries_every_n_global_steps.<locals>.<lambda>   s    X^^K!OQ7 r*   )r   get_or_create_global_stepr   devicer   executing_eagerlyr^   )rf   re   shoulds   `` r)   %record_summaries_every_n_global_stepsrk      se    99;K
zz' 7F$$&xf 
6		 
6	s   "A##A6c                      t        d      S )z7Sets the should_record_summaries Tensor to always true.Tr^   rB   r*   r)   always_record_summariesrn      s    	4r*   c                      t        d      S )z8Sets the should_record_summaries Tensor to always false.Frm   rB   r*   r)   never_record_summariesrp      s    	5	r*   zsummary.experimental.get_stepc                  "    t         j                  S )zReturns the default summary step for the current thread.

  Returns:
    The step set by `tf.summary.experimental.set_step()` if one has been set,
    otherwise None.
  r9   r&   rB   r*   r)   get_steprs      s     
		r*   zsummary.experimental.set_stepc                     | t         _        y)a  Sets the default summary step for the current thread.

  For convenience, this function sets a default value for the `step` parameter
  used in summary-writing functions elsewhere in the API so that it need not
  be explicitly passed in every such invocation. The value can be a constant
  or a variable, and can be retrieved via `tf.summary.experimental.get_step()`.

  Note: when using this with @tf.functions, the step value will be captured at
  the time the function is traced, so changes to the step outside the function
  will not be reflected inside the function unless using a `tf.Variable` step.

  Args:
    step: An `int64`-castable default step value, or None to unset.
  Nrr   r&   s    r)   set_steprv      s      .r*   zsummary.SummaryWriterc                   2    e Zd ZdZddZddZd Zd Zd Zy)	SummaryWriterz8Interface representing a stateful summary writer object.Nc                 B    | j                  |      j                          y)a  Enables this summary writer for the current thread.

    For convenience, if `step` is not None, this function also sets a default
    value for the `step` parameter used in summary-writing functions elsewhere
    in the API so that it need not be explicitly passed in every such
    invocation. The value can be a constant or a variable.

    Note: when setting `step` in a @tf.function, the step value will be
    captured at the time the function is traced, so changes to the step outside
    the function will not be reflected inside the function unless using
    a `tf.Variable` step.

    Args:
      step: An `int64`-castable default step value, or `None`. When not `None`,
        the current step is modified to the given value. When `None`, the
        current step is not modified.
    N)
as_defaultr;   r'   r&   s     r)   set_as_defaultzSummaryWriter.set_as_default   s    $ 	OOD##%r*   c                     t        | |      S )a3  Returns a context manager that enables summary writing.

    For convenience, if `step` is not None, this function also sets a default
    value for the `step` parameter used in summary-writing functions elsewhere
    in the API so that it need not be explicitly passed in every such
    invocation. The value can be a constant or a variable.

    Note: when setting `step` in a @tf.function, the step value will be
    captured at the time the function is traced, so changes to the step outside
    the function will not be reflected inside the function unless using
    a `tf.Variable` step.

    For example, `step` can be used as:

    ```python
    with writer_a.as_default(step=10):
      tf.summary.scalar(tag, value)   # Logged to writer_a with step 10
      with writer_b.as_default(step=20):
        tf.summary.scalar(tag, value) # Logged to writer_b with step 20
      tf.summary.scalar(tag, value)   # Logged to writer_a with step 10
    ```

    Args:
      step: An `int64`-castable default step value, or `None`. When not `None`,
        the current step is captured, replaced by a given one, and the original
        one is restored when the context manager exits. When `None`, the current
        step is not modified (and not restored when the context manager exits).

    Returns:
      The context manager.
    )r1   r{   s     r)   rz   zSummaryWriter.as_default  s    @ "$--r*   c                     t               )zInitializes the summary writer.NotImplementedErrorr:   s    r)   initzSummaryWriter.init.      

r*   c                     t               )zFlushes any buffered data.r   r:   s    r)   r>   zSummaryWriter.flush2  r   r*   c                     t               )z&Flushes and closes the summary writer.r   r:   s    r)   closezSummaryWriter.close6  r   r*   r3   )	r+   r,   r-   rA   r|   rz   r   r>   r   rB   r*   r)   rx   rx      s    @&( .D   r*   rx   )	metaclassc                   P     e Zd ZdZd	dZd Zd	 fd	Zd	 fd	Zd Zd Z	d Z
 xZS )
_ResourceSummaryWriterzHImplementation of SummaryWriter using a SummaryWriterInterface resource.c                    |Pt        j                  |j                               5   |       | _         || j                        | _        d d d        n# |       | _         || j                        | _        d| _        t        j                         r| j                          || _        y t        j                  t        | j                         || _        y # 1 sw Y   hxY wr=   )dtensor_apidefault_mesh	host_mesh	_resource_init_op_closedr   ri   _set_up_resource_deleterr   add_to_collection$_SUMMARY_WRITER_INIT_COLLECTION_NAME_meshr'   	create_fn
init_op_fnmeshs       r)   r"   z_ResourceSummaryWriter.__init__>  s    ##DNN$45 3""4>>23 3 !{dn 0dmDL  "
##% DJ 
@$--PDJ3 3s   $CCc                 P    t        j                  | j                  d      | _        y Nrb   )handlehandle_device)r   EagerResourceDeleterr   _resource_deleterr:   s    r)   r   z/_ResourceSummaryWriter._set_up_resource_deleterQ  s    2GG~~W6Dr*   c                     t        j                         r| j                  rt        d| d      t        |   |       y)z#See `SummaryWriter.set_as_default`.SummaryWriter  is already closedN)r   ri   r   RuntimeErrorr!   r|   r'   r&   r(   s     r)   r|   z%_ResourceSummaryWriter.set_as_defaultU  s7      "t||>$1CDEE	G4 r*   c                     t        j                         r| j                  rt        d| d      t        |   |      S )zSee `SummaryWriter.as_default`.r   r   )r   ri   r   r   r!   rz   r   s     r)   rz   z!_ResourceSummaryWriter.as_default[  s:      "t||>$1CDEE7d##r*   c                 x    t        j                         r| j                  rt        d| d      | j                  S )See `SummaryWriter.init`.r   r   )r   ri   r   r   r   r:   s    r)   r   z_ResourceSummaryWriter.inita  s3      "t||>$1CDEE==r*   c                     t        j                         r| j                  ryt        j                  d      5  t        j                  | j                        cddd       S # 1 sw Y   yxY w)See `SummaryWriter.flush`.Nrb   )r   ri   r   r   rh   r   flush_summary_writerr   r:   s    r)   r>   z_ResourceSummaryWriter.flushg  sN      "t||	G	 B11$..AB B Bs   A  A)c                    t        j                         r| j                  ry	 t        j                  | j                         g      5  t        j                  d      5  t        j                  | j                        cddd       cddd       t        j                         rd| _        S S # 1 sw Y   nxY w	 ddd       n# 1 sw Y   nxY wt        j                         rd| _        yy# t        j                         rd| _        w w xY w)See `SummaryWriter.close`.Nrb   T)
r   ri   r   r   control_dependenciesr>   rh   r   close_summary_writerr   r:   s    r)   r   z_ResourceSummaryWriter.closen  s      "t||##TZZ\N3 FZZ  	F 55dnnE	F 	FF F 
	"	"	$ 
%	F 	F 	FF F F 
	"	"	$ 
%	"	"	$ 
%sA   $C* CB+<	C	C* +B4	0C8	C* C
C* *Dr3   )r+   r,   r-   rA   r"   r   r|   rz   r   r>   r   r.   r/   s   @r)   r   r   ;  s*    P&6!$B
r*   r   c                       e Zd Zy)_MultiMetaclassN)r+   r,   r-   rB   r*   r)   r   r   {  s    r*   r   c                   0    e Zd ZdZddZd Zd Zd Zd Zy)	_TrackableResourceSummaryWriterzHA `_ResourceSummaryWriter` subclass that implements `TrackableResource`.Nc                      t         j                  j                   d       | _        | _        t
        j                    fd||       y )Nz/CPU:0)rh   c                       j                   S r3   )resource_handler:   s   r)   rG   z:_TrackableResourceSummaryWriter.__init__.<locals>.<lambda>  s    $.. r*   r   r   r   )r   TrackableResourcer"   
_create_fn_init_op_fnr   r   s   `   r)   r"   z(_TrackableResourceSummaryWriter.__init__  sL    ''X'>DO!D ##.	 $ r*   c                 "    | j                         S r3   )r   r:   s    r)   _create_resourcez0_TrackableResourceSummaryWriter._create_resource  s    ??r*   c                 8    | j                  | j                        S r3   )r   r   r:   s    r)   _initializez+_TrackableResourceSummaryWriter._initialize  s    D0011r*   c                 F    t        j                  | j                  d       y )NT)ignore_lookup_error)r   destroy_resource_opr   r:   s    r)   _destroy_resourcez1_TrackableResourceSummaryWriter._destroy_resource  s    11$8r*   c                      y r3   rB   r:   s    r)   r   z8_TrackableResourceSummaryWriter._set_up_resource_deleter  s     	r*   r3   )	r+   r,   r-   rA   r"   r   r   r   r   rB   r*   r)   r   r     s!     Q 28	r*   r   c                   (    e Zd ZdZd Zd Zd Zd Zy)_LegacyResourceSummaryWriterz<Legacy resource-backed SummaryWriter for tf.contrib.summary.c                     || _         || _        | j                         }t        j                         r't        j                  | j                   d      | _        y t        j                  t        |       y r   )r   r   r   r   ri   r   r   r   r   r   r   )r'   r   r   init_ops       r)   r"   z%_LegacyResourceSummaryWriter.__init__  sW    DN!DiikG  "4IIw 8d 
@'Jr*   c                 8    | j                  | j                        S )r   )r   r   r:   s    r)   r   z!_LegacyResourceSummaryWriter.init  s    DNN++r*   c                     t        j                  d      5  t        j                  | j                        cddd       S # 1 sw Y   yxY w)r   rb   N)r   rh   r   r   r   r:   s    r)   r>   z"_LegacyResourceSummaryWriter.flush  s9    	G	 B11$..AB B Bs	   ?Ac                    t        j                  | j                         g      5  t        j                  d      5  t	        j
                  | j                        cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)r   rb   N)r   r   r>   rh   r   r   r   r:   s    r)   r   z"_LegacyResourceSummaryWriter.close  s    		!	!4::<.	1 D::g D33DNNCD DD DD D DD D Ds"   BA-	B-A6	2BBN)r+   r,   r-   rA   r"   r   r>   r   rB   r*   r)   r   r     s    DK,B
Dr*   r   c                   P    e Zd ZdZddZej                  dd       Zd Zd Z	d Z
y)	_NoopSummaryWriterz=A summary writer that does nothing, for create_noop_writer().Nc                      y r3   rB   r{   s     r)   r|   z!_NoopSummaryWriter.set_as_default      r*   c              #      K   d  y wr3   rB   r{   s     r)   rz   z_NoopSummaryWriter.as_default  s	     	s   c                      y r3   rB   r:   s    r)   r   z_NoopSummaryWriter.init  r   r*   c                      y r3   rB   r:   s    r)   r>   z_NoopSummaryWriter.flush  r   r*   c                      y r3   rB   r:   s    r)   r   z_NoopSummaryWriter.close  r   r*   r3   )r+   r,   r-   rA   r|   r   contextmanagerrz   r   r>   r   rB   r*   r)   r   r     s3    E	 
  
			r*   r   zsummary.initializec                 |   t        j                         ryt        j                  t	        d      |!t        j                         }|t        d      |j                  t                      | Nt        |       }t        j                  t        j                        }|j                  t        |d      ||i       yy)a  Initializes summary writing for graph execution mode.

  This operation is a no-op when executing eagerly.

  This helper method provides a higher-level alternative to using
  `tf.contrib.summary.summary_writer_initializer_op` and
  `tf.contrib.summary.graph`.

  Most users will also want to call `tf.compat.v1.train.create_global_step`
  which can happen before or after this function is called.

  Args:
    graph: A `tf.Graph` or `tf.compat.v1.GraphDef` to output to the writer.
      This function will not write the default graph by default. When
      writing to an event log file, the associated step will be zero.
    session: So this method can call `tf.Session.run`. This defaults
      to `tf.compat.v1.get_default_session`.

  Raises:
    RuntimeError: If  the current thread has no default
      `tf.contrib.summary.SummaryWriter`.
    ValueError: If session wasn't passed and no default session.
  Nz1No default tf.contrib.summary.SummaryWriter foundz=Argument `session must be passed if no default session existsr   )	feed_dict)r   ri   r9   r%   r   r   get_default_session
ValueErrorrunsummary_writer_initializer_op_serialize_graphr   placeholderr
   stringgraph_v1)graphsessiondatarF   s       r)   
initializer     s    6  
"
J
KK_%%'G ( ) )	+++-.
E"Dfmm,AKKA1d)K4 r*   zsummary.create_file_writerc           
      Z  
 | t        d      t        j                         }t        j                  d      5 
t        j                  d      5  t        j
                         5  t        j                         rt        || |||       t        j                  | t        j                        } |t        j                  d      }|t        j                  d      }|t        j                  d	      }
fd
}t        j                  t         j"                  | |||      }	|r)t%        ||	|      cddd       cddd       cddd       S t'        ||	|      cddd       cddd       cddd       S # 1 sw Y   nxY w	 ddd       n# 1 sw Y   nxY wddd       y# 1 sw Y   yxY w)a  Creates a summary file writer for the given log directory.

  Args:
    logdir: a string specifying the directory in which to write an event file.
    max_queue: the largest number of summaries to keep in a queue; will flush
      once the queue gets bigger than this. Defaults to 10.
    flush_millis: the largest interval between flushes. Defaults to 120,000.
    filename_suffix: optional suffix for the event file name. Defaults to `.v2`.
    name: a name for the op that creates the writer.
    experimental_trackable: a boolean that controls whether the returned writer
      will be a `TrackableResource`, which makes it compatible with SavedModel
      when used as a `tf.Module` property.
    experimental_mesh: a `tf.experimental.dtensor.Mesh` instance. When running
      with DTensor, the mesh (experimental_mesh.host_mesh()) will be used for
      bringing all the DTensor logging from accelerator to CPU mesh.

  Returns:
    A SummaryWriter object.
  Nz Argument `logdir` cannot be Nonecreate_file_writerrb   logdir	max_queueflush_millisfilename_suffixdtype
    .v2c                      t        j                         rt        j                         } nt        j                        } t        j                  |       S )N)shared_namename)r   ri   anonymous_namer   name_from_scope_namer   summary_writer)r   r   scopes    r)   r   z(create_file_writer_v2.<locals>.create_fn7  sG     $$&..0+007+--#$0 	0r*   r   )r   r   inside_function
name_scoperh   
init_scoper   ri   _check_create_file_writer_argsconvert_to_tensorr
   r   r	   rH   	functoolspartialr   create_summary_file_writerr   r   )r   r   r   r   r   experimental_trackableexperimental_meshr   r   r   r   s       `     @r)   create_file_writer_v2r     s   < ^
7
88'')/
~~d01 )
UCJJw<O )
		 '
		"	"	$&%+	- $$V6==Af		((,			"++M:		 %..u50 $$

4
4#)+j 
 .J=N
C'
 '
)
 )
 )
N &J=N
K'
 '
)
 )
 )
'
 '
 '
)
 )
 )
 )
 )
 )
sT   F!F%CE61	F:	F!E6	F#	F!6E?;F	F!F	F!!F*c                    | 
t               S t        |       } t        j                  d      5  |t	        j
                  d      }|t	        j
                  d      }|t	        j
                  d      }|d| z   }t        j                  |      }t        |t        j                  t        j                  | |||      	      cddd       S # 1 sw Y   yxY w)
a  Creates a summary file writer in the current context under the given name.

  Args:
    logdir: a string, or None. If a string, creates a summary file writer
     which writes to the directory named by the string. If None, returns
     a mock object which acts like a summary writer but does nothing,
     useful to use as a context manager.
    max_queue: the largest number of summaries to keep in a queue; will
     flush once the queue gets bigger than this. Defaults to 10.
    flush_millis: the largest interval between flushes. Defaults to 120,000.
    filename_suffix: optional suffix for the event file name. Defaults to `.v2`.
    name: Shared name for this SummaryWriter resource stored to default
      Graph. Defaults to the provided logdir prefixed with `logdir:`. Note: if a
      summary writer resource with this shared name already exists, the returned
      SummaryWriter wraps that resource and the other arguments have no effect.

  Returns:
    Either a summary writer or an empty object which can be used as a
    summary writer.
  Nrb   r   r   r   zlogdir:)r   r   )r   r   )r   strr   rh   r	   rH   r   r   r   r   r   r   )r   r   r   r   r   r   s         r)   r   r   Q  s    2 ^v;&
zz' .&&r*i ))-8l#,,U3o|d--$?H'$$66%+-.. . .s   BCCzsummary.create_noop_writerc                      t               S )zyReturns a summary writer that does nothing.

  This is useful as a placeholder in code that expects a context manager.
  )r   rB   r*   r)   create_noop_writerr     s     
	r*   c                     t        |t              r.|j                  |      t        |  d| d|j                         t        j                  |t        j                        S )Nz (z) must match )	
isinstancer   searchr   patternr   r   r
   r   )r   r  values      r)   _cleanse_stringr    sR    su 5 =
vRwmGOO3DE
FF			ufmm	44r*   c                  ,    t        j                  d      S )z8Convenient else branch for when summaries do not record.F)r	   rH   rB   r*   r)   _nothingr    s    			e	$$r*   zsummary.all_v2_summary_opsc                      t        j                         ryt        j                  t        j                  j
                        S )ab  Returns all V2-style summary ops defined in the current default graph.

  This includes ops from TF 2.0 tf.summary and TF 1.x tf.contrib.summary (except
  for `tf.contrib.summary.graph` and `tf.contrib.summary.import_event`), but
  does *not* include TF 1.x tf.summary ops.

  Returns:
    List of summary ops, or None if called under eager execution.
  N)r   ri   r   get_collection	GraphKeys_SUMMARY_COLLECTIONrB   r*   r)   all_v2_summary_opsr    s.      			CMM==	>>r*   c                  r    t        j                         rt        d      t        j                  t
              S )zGraph-mode only. Returns the list of ops to create all summary writers.

  Returns:
    The initializer ops.

  Raises:
    RuntimeError: If in Eager mode.
  zQtf.contrib.summary.summary_writer_initializer_op is only supported in graph mode.)r   ri   r   r   r
  r   rB   r*   r)   r   r     s6      
	#$ $ 
		@	AAr*   z[^-_/.A-Za-z0-9]z"summary.experimental.summary_scopec              #      K   | xs |} t        j                         }|r|dz   | z   n| }t        j                  d|       xs d} t        j                  | ||d      5 }||f ddd       y# 1 sw Y   yxY ww)a  Experimental context manager for use when defining a custom summary op.

  This behaves similarly to `tf.name_scope`, except that it returns a generated
  summary tag in addition to the scope name. The tag is structurally similar to
  the scope name - derived from the user-provided name, prefixed with enclosing
  name scopes if any - but we relax the constraint that it be uniquified, as
  well as the character set limitation (so the user-provided name can contain
  characters not legal for scope names; in the scope name these are removed).

  This makes the summary tag more predictable and consistent for the user.

  For example, to define a new summary op called `my_op`:

  ```python
  def my_op(name, my_value, step):
    with tf.summary.summary_scope(name, "MyOp", [my_value]) as (tag, scope):
      my_value = tf.convert_to_tensor(my_value)
      return tf.summary.write(tag, my_value, step=step)
  ```

  Args:
    name: string name for the summary.
    default_name: Optional; if provided, used as default name of the summary.
    values: Optional; passed as `values` parameter to name_scope.

  Yields:
    A tuple `(tag, scope)` as described above.
  / NF)skip_on_eager)r   get_name_scope_INVALID_SCOPE_CHARACTERSsubr   )r   default_namevaluescurrent_scopetagr   s         r)   summary_scoper    s~     > 
	$$$&-&3d"# 
#	&	&r4	0	8D$
~~dL&F %
u*  s   AA8A,#	A8,A51A8zsummary.writec                     t        j                  |d      5 t        j                  t	        j
                  d      cddd       S 
t               |dnt        |d      r|j                         n| fd}t        j                  t               |t        d      }t        j                         s.t        j                  t         j                  j                   |       |cddd       S # 1 sw Y   yxY w)	a  Writes a generic summary to the default SummaryWriter if one exists.

  This exists primarily to support the definition of type-specific summary ops
  like scalar() and image(), and is not intended for direct use unless defining
  a new type-specific summary op.

  Args:
    tag: string tag used to identify the summary (e.g. in TensorBoard), usually
      generated with `tf.summary.summary_scope`
    tensor: the Tensor holding the summary data to write or a callable that
      returns this Tensor. If a callable is passed, it will only be called when
      a default SummaryWriter exists and the recording condition specified by
      `record_if()` is met.
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.
    metadata: Optional SummaryMetadata, as a proto or serialized bytes
    name: Optional string name for this op.

  Returns:
    True on success, or false if no summary was written because no default
    summary writer was available.

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  write_summaryNFr*   SerializeToStringc            	         t        d      t        j                  d      5  t        	      r 	       nt	        j
                  	      } t        j                  }t        ||       }t        |      }t        j                  |j                  ||      }t        j                  |g      5  t        j                  d      cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)*Record the actual summary and return True.NpNo step set. Please specify one either through the `step` argument or through tf.summary.experimental.set_step()rb   r   T)r   r   rh   rE   r   identityr9   r%    _maybe_convert_tensor_to_dtensorr   r  r   r   r	   rH   )
summary_tensorr%   summary_value
step_valuewrite_summary_opr   serialized_metadatar&   r  r   s
        r)   recordzwrite.<locals>.record
  s    	 > ? 	?
 ::g ,%-f%59;M;M<
  &&8P5fdC
*88
 %%'7&89 	,%%d+	, 	,%, ,$	, 	, 	,%, , ,s$   BC-/C	C-C 	C--C6summary_condr!  )r   r   r9   r%   r	   rH   rs   hasattrr  r   rU   r  r   ri   r   r  r  )	r  r   r&   metadatar   r)  opr   r(  s	   ```    @@r)   writer.    s    : ~~dO, -$!!%(- - |Zd	.	/$668$, ,: 
		!68.
JB$$&	CMM==rB[- - -s   %C6B!C66C?z!summary.experimental.write_raw_pbc                 8    t        j                  |d      5 t        j                  t	        j
                  d      cddd       S t               t        d       fd}t        j                  d      5  t        j                  t               |t        d      }t        j                         s.t        j                  t         j                  j                   |       |cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)	a<  Writes a summary using raw `tf.compat.v1.Summary` protocol buffers.

  Experimental: this exists to support the usage of V1-style manual summary
  writing (via the construction of a `tf.compat.v1.Summary` protocol buffer)
  with the V2 summary writing API.

  Args:
    tensor: the string Tensor holding one or more serialized `Summary` protobufs
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.
    name: Optional string name for this op.

  Returns:
    True on success, or false if no summary was written because no default
    summary writer was available.

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  write_raw_pbNFr   c                  x   t        j                  d      5  t        j                  t        j
                  j                  t        j                              } t        j                  | g      5  t        j                  d      cddd       cddd       S # 1 sw Y   nxY w	 ddd       y# 1 sw Y   yxY w)r  rb   r!  TN)r   rh   r   write_raw_proto_summaryr9   r%   r   r   r"  r   r	   rH   )raw_summary_opr   r&   r   s    r)   r)  zwrite_raw_pb.<locals>.recordO  s     ::g ,(@@!!++v&	
 %%~&67 	,%%d+	, 	,, ,	, 	, 	,, , ,s$   AB02B	B0B#	B00B9rb   r*  r!  )r   r   r9   r%   r	   rH   rs   r   rh   r   rU   r  r   ri   r   r  r  )r   r&   r   r)  r-  r   s   ``   @r)   r0  r0  .  s    . ~~dN+ u$!!%(  |Zd	 > ? 	?
, 
G	   
!
#VXNLb&&(cmm??D - ,  -  s*   %D	5D>A)C:'	D:D	?DDc                     t        j                         rdz   fd}t        j                  t	        j
                         S t        j                  d      5  t        j                  t               |t        d      }t        j                         s.t        j                  t         j                  j                  |       ddd       |S # 1 sw Y   S xY w)a   Helper function to write summaries.

  Args:
    name: name of the summary
    tensor: main tensor to form the summary
    function: function taking a tag and a scope which writes the summary
    family: optional, the summary's family

  Returns:
    The result of writing the summary.
  r  c                  t   t        j                        5  t        j                  g      5 \  } }t        j                   | |      g      5  t        j                  d      cd d d        cd d d        cd d d        S # 1 sw Y   nxY w	 d d d        n# 1 sw Y   nxY wd d d        y # 1 sw Y   y xY w)N)r  T)r   r   r   r  r   r	   rH   )r  r   familyfunctionr   r   r   s     r)   r)  z'summary_writer_function.<locals>.records  s    	
	# *_%B%BffX&' **63##Xc5%9$:; *##D)* ** * ** * ** * * * * *s@   B.!BB'	B0	B.BB	B.B"	B..B7Nrb   r  r!  )r   r  r9   r%   r   no_oprh   r   rW   r  r   ri   r   r  r  )r   r   r7  r6  r)  r-  r   s   ````  @r)   summary_writer_functionr9  c  s     !!#*#J* * "!!##
zz' C			/168"
NB$$&	CMM==rB	C
 
)C
 
)s   #A(CCc                 4    fd}t        | ||      S )z$Writes a tensor summary if possible.c                 6   t        j                  d      }n2t        d      r$t        j                  j                               }n}t	        j
                  t        j                  j                  t              t        j                        | ||      S )Nr  r  r!  )r	   rH   r+  r  r   r  r9   r%   r   _choose_stepr   r"  )r  r   r(  r,  r&   r   s      r)   r7  zgeneric.<locals>.function  s    '004	.	/'001K1K1MN$((''T6" r*   r6  r9  )r   r   r,  r6  r&   r7  s    `` ` r)   genericr?    s     
!vx	GGr*   c                 0    fd}t        | ||      S )a  Writes a scalar summary if possible.

  Unlike `tf.contrib.summary.generic` this op may change the dtype
  depending on the writer, for both practical and efficiency concerns.

  Args:
    name: An arbitrary name for this summary.
    tensor: A `tf.Tensor` Must be one of the following types:
      `float32`, `float64`, `int32`, `int64`, `uint8`, `int16`,
      `int8`, `uint16`, `half`, `uint32`, `uint64`.
    family: Optional, the summary's family.
    step: The `int64` monotonic step variable, which defaults
      to `tf.compat.v1.train.get_global_step`.

  Returns:
    The created `tf.Operation` or a `tf.no_op` if summary writing has
    not been enabled for this context.
  c                     t        j                  t        j                  j                  t              | t        j                        |      S Nr!  )r   write_scalar_summaryr9   r%   r   r<  r   r"  r  r   r&   r   s     r)   r7  zscalar.<locals>.function  sA    //''T6" r*   r=  r>  r   r   r6  r&   r7  s    ` ` r)   scalarrF    s    ( 
!vx	GGr*   c                 0    fd}t        | ||      S )z'Writes a histogram summary if possible.c                     t        j                  t        j                  j                  t              | t        j                        |      S rB  )r   write_histogram_summaryr9   r%   r   r<  r   r"  rD  s     r)   r7  zhistogram.<locals>.function  sA    22''T6" r*   r=  r>  rE  s    ` ` r)   	histogramrJ    s     
!vx	GGr*   c                 8    fd}t        | ||      S )z$Writes an image summary if possible.c           	          't        j                  g dt        j                        n}t	        j
                  t        j                  j                  t              | t        j                        ||      S )N)   r   r   rM  r   r!  )r	   rH   r
   uint8r   write_image_summaryr9   r%   r   r<  r   r"  )r  r   
bad_color_	bad_color
max_imagesr&   r   s      r)   r7  zimage.<locals>.function  sn    & &&'7v||L,5  ..''T6" r*   r=  r>  )r   r   rQ  rR  r6  r&   r7  s    ``` ` r)   imagerS    s     
!vx	GGr*   c                 8    fd}t        | ||      S )z$Writes an audio summary if possible.c           	          t        j                  t        j                  j                  t              | t        j                        |      S )N)sample_ratemax_outputsr   )r   write_audio_summaryr9   r%   r   r<  r   r"  )r  r   rW  rV  r&   r   s     r)   r7  zaudio.<locals>.function  sG    ..''T6" r*   r=  r>  )r   r   rV  rW  r6  r&   r7  s    ``` ` r)   audiorY    s    	 
!vx	GGr*   c                 |   t        j                         s?t        | t        j                        s%t        d|  dt        |       j                   d      t        j                  }|t        j                         S t        j                  d      5  t        | t        j                  t        j                   f      r.t        j"                  t%        |       t&        j(                        }nt+        j,                  |       }t/        j0                  |j2                  t5        |      ||      cddd       S # 1 sw Y   yxY w)a  Writes a TensorFlow graph to the summary interface.

  The graph summary is, strictly speaking, not a summary. Conditions
  like `tf.summary.should_record_summaries` do not apply. Only
  a single graph can be associated with a particular run. If multiple
  graphs are written, then only the last one will be considered by
  TensorBoard.

  When not using eager execution mode, the user should consider passing
  the `graph` parameter to `tf.compat.v1.summary.initialize` instead of
  calling this function. Otherwise special care needs to be taken when
  using the graph to record the graph.

  Args:
    param: A `tf.Tensor` containing a serialized graph proto. When
      eager execution is enabled, this function will automatically
      coerce `tf.Graph`, `tf.compat.v1.GraphDef`, and string types.
    step: The global step variable. This doesn't have useful semantics
      for graph summaries, but is used anyway, due to the structure of
      event log files. This defaults to the global step.
    name: A name for the operation (optional).

  Returns:
    The created `tf.Operation` or a `tf.no_op` if summary writing has
    not been enabled for this context.

  Raises:
    TypeError: If `param` isn't already a `tf.Tensor` in graph mode.
  zigraph() needs a argument `param` to be tf.Tensor (e.g. tf.placeholder) in graph mode, but received param=	 of type .Nrb   r!  )r   ri   r  
tensor_libTensor	TypeErrortyper+   r9   r%   r   r8  r   rh   Graphr   GraphDefr   r   r
   r   r   r"  r   write_graph_summaryr   r<  )paramr&   r   r%   r   s        r)   r   r     s   < 
	"	"	$ZZ. 	ye!5!5 6a	9 
   &^!!##
zz' A%#))Y%7%789$$%5e%<fmmLf!!%(f..,t,f4AA A As   BD22D;zsummary.graphc           	         t        j                         st        d      t        j                  }|t        j                  d      S t        j                  d      5  t               st        j                  d      cddd       S t        | t        j                  t        j                  f      r.t        j                  t        |       t         j"                        }n%t        d|  dt%        |       j&                   d      t)        j*                  |j,                  d|       t        j                  d	      cddd       S # 1 sw Y   yxY w)
a  Writes a TensorFlow graph summary.

  Write an instance of `tf.Graph` or `tf.compat.v1.GraphDef` as summary only
  in an eager mode. Please prefer to use the trace APIs (`tf.summary.trace_on`,
  `tf.summary.trace_off`, and `tf.summary.trace_export`) when using
  `tf.function` which can automatically collect and record graphs from
  executions.

  Usage Example:
  ```py
  writer = tf.summary.create_file_writer("/tmp/mylogs")

  @tf.function
  def f():
    x = constant_op.constant(2)
    y = constant_op.constant(3)
    return x**y

  with writer.as_default():
    tf.summary.graph(f.get_concrete_function().graph)

  # Another example: in a very rare use case, when you are dealing with a TF v1
  # graph.
  graph = tf.Graph()
  with graph.as_default():
    c = tf.constant(30.0)
  with writer.as_default():
    tf.summary.graph(graph)
  ```

  Args:
    graph_data: The TensorFlow graph to write, as a `tf.Graph` or a
      `tf.compat.v1.GraphDef`.

  Returns:
    True on success, or False if no summary was written because no default
    summary writer was available.

  Raises:
    ValueError: `graph` summary API is invoked in a graph mode.
  z1graph() cannot be invoked inside a graph context.NFrb   zTArgument 'graph_data' is not tf.Graph or tf.compat.v1.GraphDef. Received graph_data=r[  r\  r   T)r   ri   r   r9   r%   r	   rH   r   rh   rU   r  ra  r   rb  r   r   r
   r   r`  r+   r   rc  r   )
graph_datar%   r   s      r)   r   r     s   V 
	"	"	$
H
II  &^&&
zz' &"$!!%(& & *syy)*<*<=>$$
:
&7f  E$YtJ/?/H/H.IL M M ''		 %%& & &s   EB2EE
c                 b    t        j                  t        j                  j                  | |      S )a  Writes a `tf.compat.v1.Event` binary proto.

  This can be used to import existing event logs into a new summary writer sink.
  Please note that this is lower level than the other summary functions and
  will ignore the `tf.summary.should_record_summaries` setting.

  Args:
    tensor: A `tf.Tensor` of type `string` containing a serialized
      `tf.compat.v1.Event` proto.
    name: A name for the operation (optional).

  Returns:
    The created `tf.Operation`.
  r!  )r   import_eventr9   r%   r   )r   r   s     r)   rh  rh  b  s*     
	%	%%%vD
: :r*   zsummary.flushc                     ~| &t         j                  } | t        j                         S t	        | t
              r| j                         S t        d|       )a  Forces summary writer to send any buffered data to storage.

  This operation blocks until that finishes.

  Args:
    writer: The `tf.summary.SummaryWriter` to flush. If None, the current
      default writer will be used instead; if there is no current writer, this
      returns `tf.no_op`.
    name: Ignored legacy argument for a name for the operation.

  Returns:
    The created `tf.Operation`.
  zInvalid argument to flush(): )r9   r%   r   r8  r  rx   r>   r   r%   r   s     r)   r>   r>   u  sO     ^""F~##%%&<<>@AAr*   c                     | t        | t              rt        | |      S t        j                  d      5  t        j                  | |      cddd       S # 1 sw Y   yxY w)aM  Legacy version of flush() that accepts a raw resource tensor for `writer`.

  Do not use this function in any new code. Not supported and not part of the
  public TF APIs.

  Args:
    writer: The `tf.summary.SummaryWriter` to flush. If None, the current
      default writer will be used instead; if there is no current writer, this
      returns `tf.no_op`. For this legacy version only, also accepts a raw
      resource tensor pointing to the underlying C++ writer resource.
    name: Ignored legacy argument for a name for the operation.

  Returns:
    The created `tf.Operation`.
  Nrb   r!  )r  rx   r>   r   rh   r   r   rj  s     r)   legacy_raw_flushrl    sV      ^z&-8 
G	 E11&tDE E Es   AAc                 X    t         j                  j                  | |sd      S d|z         S )z.Construct a logdir for an eval summary writer.evaleval_)ospathjoin)	model_dirr   s     r)   eval_dirrt    s%    	it	HH4	HHr*   z Renamed to create_file_writer().)dateinstructionsc                  B    t        j                  d       t        | i |S )z3Please use `tf.contrib.summary.create_file_writer`.zQDeprecation Warning: create_summary_file_writer was renamed to create_file_writer)loggingwarningr   )argskwargss     r)   r   r     s%     
// * +	T	,V	,,r*   c                     t        | t        j                        r | j                  d      j	                         S | j	                         S )NT)
add_shapes)r  r   ra  as_graph_defr  )arbitrary_graphs    r)   r   r     s<    +''4'8JJLL,,..r*   c                     | t        j                         S t        | t        j                        s$t        j                  | t        j                        S | S r3   )	r   rg   r  r]  r^  r   r   r
   int64ru   s    r)   r<  r<    sB    	\2244	D*++	,  v||44	+r*   c                     |j                         D ][  \  }}t        |t        j                        r!t	        j
                  |      s7| rt        d| d| d      t        d| d| d       y)a'  Helper to check the validity of arguments to a create_file_writer() call.

  Args:
    inside_function: whether the create_file_writer() call is in a tf.function
    **kwargs: the arguments to check, as kwargs to give them names.

  Raises:
    ValueError: if the arguments are graph tensors.
  zInvalid graph Tensor argument '=z' to create_file_writer() inside an @tf.function. The create call will be lifted into the outer eager execution context, so it cannot consume graph tensors defined inside the function body.z+' to eagerly executed create_file_writer().N)itemsr  r   EagerTensorr   
is_tf_typer   )r   r{  arg_nameargs       r)   r   r     s     ||~ .mhc3??+0F0Fs0K	-hZq >F FG 	G -hZq >- -. 	..r*   c                    t        j                         }d|j                  _        d|j                  _        t        | d||g      5 \  }}t        j                  d      5  t        j                  |j                         t        j                        }ddd       t        |||      cddd       S # 1 sw Y   !xY w# 1 sw Y   yxY w)a  Writes entire RunMetadata summary.

  A RunMetadata can contain DeviceStats, partition graphs, and function graphs.
  Please refer to the proto for definition of each field.

  Args:
    name: A name for this summary. The summary tag used for TensorBoard will be
      this name prefixed by any active name scopes.
    data: A RunMetadata proto to write.
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.

  Returns:
    True on success, or false if no summary was written because no default
    summary writer was available.

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  graph_run_metadata   1graph_run_metadata_summaryrb   r   Nr  r   r&   r,  )r   SummaryMetadataplugin_dataplugin_namecontentr  r   rh   r	   rH   r  r
   r   r.  r   r   r&   summary_metadatar  _r   s          r)   run_metadatar    s    , !002 .B*)-&T1D\# 
#&.sA	G	 9##D$:$:$<*0--9f9 !	#
# 
#9 9
# 
#s$   B?4B3B?3B<	8B??Cc                    t        j                         }d|j                  _        d|j                  _        t        j                  |j                  |j                        }t        | d||g      5 \  }}t        j                  d      5  t        j                  |j                         t        j                         }ddd       t#        |||      cddd       S # 1 sw Y   !xY w# 1 sw Y   yxY w)	a  Writes graphs from a RunMetadata summary.

  Args:
    name: A name for this summary. The summary tag used for TensorBoard will be
      this name prefixed by any active name scopes.
    data: A RunMetadata proto to write.
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.

  Returns:
    True on success, or false if no summary was written because no default
    summary writer was available.

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  graph_run_metadata_graphr  )function_graphspartition_graphs graph_run_metadata_graph_summaryrb   r   Nr  )r   r  r  r  r  r   RunMetadatar  r  r  r   rh   r	   rH   r  r
   r   r.  r  s          r)   run_metadata_graphsr    s    & !002 .H*)-&			**,,
.$ T7D\# 
#&.sA	G	 9##D$:$:$<*0--9f9 !	#
# 
#9 9
# 
#s$   1C*
4C>C*C'	#C**C3TraceContextr   profilerzsummary.trace_onc                 4   t        j                         rt        j                  d       yt	        j
                         st        j                  d       yt        5  t        rt        j                  d       	 ddd       y| r$|s"t	        j                         j                          |rO|t        j                  d       n7t	        j                         j                          t        j                  |       t        | |      addd       y# 1 sw Y   yxY w)a  Starts a trace to record computation graphs and profiling information.

  Must be invoked in eager mode.

  When enabled, TensorFlow runtime will collect information that can later be
  exported and consumed by TensorBoard. The trace is activated across the entire
  TensorFlow runtime and affects all threads of execution.

  To stop the trace and export the collected information, use
  `tf.summary.trace_export`. To stop the trace without exporting, use
  `tf.summary.trace_off`.

  Args:
    graph: If True, enables collection of executed graphs. It includes ones from
      tf.function invocation and ones from the legacy graph mode. The default is
      True.
    profiler: If True, enables the advanced profiler. Enabling profiler
      implicitly enables the graph collection. The profiler may incur a high
      memory overhead. The default is False.
    profiler_outdir: Output directory for profiler. It is required when profiler
      is enabled when trace was started. Otherwise, it is ignored.
  z)Cannot enable trace inside a tf.function.Nz Must enable trace in eager mode.zTrace already enabledzENo `profiler_outdir` passed to trace_on(). Profiler won't be enabled.r  )r   r   rx  warnr   ri   _current_trace_context_lock_current_trace_contextenable_graph_collectionenable_run_metadata	_profilerstart_TraceContext)r   r  profiler_outdirs      r)   trace_onr  6  s    0 	LL<=
		"	"	$LL34
 # Kll*+K K
 Xoo//1		  		

 	--/(*J'K K Ks   DBDDzsummary.trace_exportc                    t        j                         rt        j                  d       yt	        j
                         st        j                  d       yt        5  t        t        d      t        \  }}ddd       t	        j                         j                         }rst        | ||       nt        | ||       r+|rt        j                  d       t        j                          t                y# 1 sw Y   xY w)a  Stops and exports the active trace as a Summary and/or profile file.

  Stops the trace and exports all metadata collected during the trace to the
  default SummaryWriter, if one has been set.

  Args:
    name: A name for the summary to be written.
    step: Explicit `int64`-castable monotonic step value for this summary. If
      omitted, this defaults to `tf.summary.experimental.get_step()`, which must
      not be None.
    profiler_outdir: This arg is a no-op. Please set this in trace_on().

  Raises:
    ValueError: if a default writer exists, but no step was provided and
      `tf.summary.experimental.get_step()` is None.
  z)Cannot export trace inside a tf.function.Nz.Can only export trace while executing eagerly.z<Must enable trace before export through tf.summary.trace_on.zZIgnoring `profiler_outdir` passed to trace_export(). Please pass it to trace_on() instead.)r   r   rx  r  r   ri   r  r  r   export_run_metadatar  r  r  stop	trace_off)r   r&   r  r   r  run_metas         r)   trace_exportr  n  s    , 	LL<=
		"	"	$LLAB
" -% . / /,OE8	- __224(
8h-x&ll$ NN++- -s   C77D zsummary.trace_offc                  @   t         5  t        
	 ddd       yt        \  } }daddd        r"t        j                         j                          r	 t	        j
                          yy# 1 sw Y   FxY w# t        $ r }t        j                  d|       Y d}~yd}~ww xY w)z?Stops the current trace and discards any collected information.Nz!Error while stopping profiler: %s)	r  r  r   disable_run_metadatar  r  	Exceptionrx  r  )r   r  es      r)   r  r    s     # "%" " -OE8!	" OO**,nn " "  ll6:
s(   A(A(A4 (A14	B=BBc                     t        | dd       c| j                  j                         }t        j                  |t
        j                  j                  ||j                  j                              }|S )Nr   )rank)
getattrr   r   r   copy_to_mesh
layout_libLayout
replicatedshaper  )r%   r   r   s      r)   r#  r#    s_    VWd#/<<!!#D%%
!!,,T8I8I,JF 
-r*   r3   )NN)NNNNFN)NNNN)summaryN)NNN)N   NN)TFN)urA   abccollectionsr   rp  re	threadingtensorflow.core.frameworkr   r   tensorflow.core.protobufr   tensorflow.dtensor.pythonr   r   r   r  tensorflow.python.eagerr   tensorflow.python.frameworkr	   r
   r   r   r   r]  r   tensorflow.python.opsr   r   r   r   r   r   r   tensorflow.python.platformr   rx  tensorflow.python.profilerr   r  tensorflow.python.trackabler   tensorflow.python.trainingr   tensorflow.python.utilr   r    tensorflow.python.util.tf_exportr   r   localr   r9   r1   rP   rU   rW   rZ   r   r^   r`   rk   rn   rp   rs   rv   ABCMetarx   r   r`  r   r   r   r   r   r   r   r   r   r  r  r  r   compiler  r  r.  r0  r9  r?  rF  rJ  rS  rY  r   r   rh  r>   rl  rt  
deprecatedr   r   r<  r   r  r  
namedtupler  Lockr  r  r  r  r  r#  rB   r*   r)   <module>r     s6    $ 
   	 	  / 1 / 8 : + 3 . + 2 < 3 + 2 ; 1 * 7 1 < ? 0 4 . 0 6
 (< $IOO   <6> ,4	? 5	?@
Q
 2&&  '&8+

 *r2 3 *r2 3$ "r*C ckk C  +C L=] =@	 $x'A'A"B
%	%	PD= D:	 	( #$%
'5 &'5T 'B/ 	 I
 0I
Z "&$('+ 	-.` 'B/ 05%
 +,-? .?B  'BJJ':;  /B7$  8$N ?r"I #IX .261 71h@H*H@HH&H"/Ad ?r"A& #A&H:& ?r"B #B0E2I
 T%GI-I-/.0'#T(#V '&&~7LM,inn.   "%2K &2Kn !b)1 *1h 2& '*r*   