@@ -26,13 +26,15 @@ pub(crate) const SCALARS_PLUGIN_NAME: &str = "scalars";
2626pub ( crate ) const IMAGES_PLUGIN_NAME : & str = "images" ;
2727pub ( crate ) const AUDIO_PLUGIN_NAME : & str = "audio" ;
2828pub ( crate ) const GRAPHS_PLUGIN_NAME : & str = "graphs" ;
29+ pub ( crate ) const GRAPH_TAGGED_RUN_METADATA_PLUGIN_NAME : & str = "graph_tagged_run_metadata" ;
2930
3031/// The inner contents of a single value from an event.
3132///
3233/// This does not include associated step, wall time, tag, or summary metadata information. Step
3334/// and wall time are available on every event and just not tracked here. Tag and summary metadata
34- /// information are materialized on `Event`s whose `oneof what` is `summary`, but implicit for
35- /// graph defs. See [`GraphDefValue::initial_metadata`] and [`SummaryValue::initial_metadata`] for
35+ /// information are materialized on `Event`s whose `oneof what` is `tagged_run_metadata` or
36+ /// `summary`, but implicit for graph defs. See [`GraphDefValue::initial_metadata`],
37+ /// [`TaggedRunMetadataValue::initial_metadata`], and [`SummaryValue::initial_metadata`] for
3638/// type-specific helpers to determine summary metadata given appropriate information.
3739///
3840/// This is kept as close as possible to the on-disk event representation, since every record in
@@ -46,18 +48,20 @@ pub(crate) const GRAPHS_PLUGIN_NAME: &str = "graphs";
4648#[ derive( Debug ) ]
4749pub enum EventValue {
4850 GraphDef ( GraphDefValue ) ,
51+ TaggedRunMetadata ( TaggedRunMetadataValue ) ,
4952 Summary ( SummaryValue ) ,
5053}
5154
5255impl EventValue {
5356 /// Consumes this event value and enriches it into a scalar.
5457 ///
5558 /// This supports `simple_value` (TF 1.x) summaries as well as rank-0 tensors of type
56- /// `DT_FLOAT`. Returns `DataLoss` if the value is a `GraphDef`, is an unsupported summary, or
57- /// is a tensor of the wrong rank.
59+ /// `DT_FLOAT`. Returns `DataLoss` if the value is a `GraphDef`, a tagged run metadata proto,
60+ /// an unsupported summary, or a tensor of the wrong rank.
5861 pub fn into_scalar ( self ) -> Result < ScalarValue , DataLoss > {
5962 let value_box = match self {
6063 EventValue :: GraphDef ( _) => return Err ( DataLoss ) ,
64+ EventValue :: TaggedRunMetadata ( _) => return Err ( DataLoss ) ,
6165 EventValue :: Summary ( SummaryValue ( v) ) => v,
6266 } ;
6367 match * value_box {
@@ -72,16 +76,20 @@ impl EventValue {
7276
7377 /// Consumes this event value and enriches it into a blob sequence.
7478 ///
75- /// For now, this supports `GraphDef`s, summaries with `image` or `audio`, or summaries with
76- /// `tensor` set to a rank-1 tensor of type `DT_STRING`. If the summary metadata indicates that
77- /// this is audio data, `tensor` may also be a string tensor of shape `[k, 2]`, in which case
78- /// the second axis is assumed to represent string labels and is dropped entirely.
79+ /// For now, this supports `GraphDef`s, tagged run metadata protos, summaries with `image` or
80+ /// `audio`, or summaries with `tensor` set to a rank-1 tensor of type `DT_STRING`. If the
81+ /// summary metadata indicates that this is audio data, `tensor` may also be a string tensor of
82+ /// shape `[k, 2]`, in which case the second axis is assumed to represent string labels and is
83+ /// dropped entirely.
7984 pub fn into_blob_sequence (
8085 self ,
8186 metadata : & pb:: SummaryMetadata ,
8287 ) -> Result < BlobSequenceValue , DataLoss > {
8388 match self {
8489 EventValue :: GraphDef ( GraphDefValue ( blob) ) => Ok ( BlobSequenceValue ( vec ! [ blob] ) ) ,
90+ EventValue :: TaggedRunMetadata ( TaggedRunMetadataValue ( run_metadata) ) => {
91+ Ok ( BlobSequenceValue ( vec ! [ run_metadata] ) )
92+ }
8593 EventValue :: Summary ( SummaryValue ( value_box) ) => match * value_box {
8694 pb:: summary:: value:: Value :: Image ( im) => {
8795 let w = format ! ( "{}" , im. width) . into_bytes ( ) ;
@@ -155,6 +163,12 @@ fn tensor_proto_to_scalar(tp: &pb::TensorProto) -> Option<f32> {
155163/// plugin metadata, but these are not materialized.
156164pub struct GraphDefValue ( pub Vec < u8 > ) ;
157165
166+ /// A value from an `Event` whose `tagged_run_metadata` field is set.
167+ ///
168+ /// This contains only the `run_metadata` from the event (not the tag). This itself represents the
169+ /// encoding of a `RunMetadata` proto, but that is deserialized at the plugin level.
170+ pub struct TaggedRunMetadataValue ( pub Vec < u8 > ) ;
171+
158172/// A value from an `Event` whose `summary` field is set.
159173///
160174/// This contains a [`summary::value::Value`], which represents the underlying `oneof value` field
@@ -183,6 +197,17 @@ impl GraphDefValue {
183197 }
184198}
185199
200+ impl TaggedRunMetadataValue {
201+ /// Determines the metadata for a time series whose first event is a
202+ /// [`TaggedRunMetadata`][`EventValue::TaggedRunMetadata`].
203+ pub fn initial_metadata ( ) -> Box < pb:: SummaryMetadata > {
204+ blank (
205+ GRAPH_TAGGED_RUN_METADATA_PLUGIN_NAME ,
206+ pb:: DataClass :: BlobSequence ,
207+ )
208+ }
209+ }
210+
186211impl SummaryValue {
187212 /// Determines the metadata for a time series given its first event.
188213 ///
@@ -237,6 +262,14 @@ impl Debug for GraphDefValue {
237262 }
238263}
239264
265+ impl Debug for TaggedRunMetadataValue {
266+ fn fmt ( & self , f : & mut std:: fmt:: Formatter < ' _ > ) -> std:: fmt:: Result {
267+ f. debug_tuple ( "TaggedRunMetadataValue" )
268+ . field ( & format_args ! ( "<{} bytes>" , self . 0 . len( ) ) )
269+ . finish ( )
270+ }
271+ }
272+
240273/// Creates a summary metadata value with plugin name and data class, but no other contents.
241274fn blank ( plugin_name : & str , data_class : pb:: DataClass ) -> Box < pb:: SummaryMetadata > {
242275 Box :: new ( pb:: SummaryMetadata {
@@ -518,6 +551,16 @@ mod tests {
518551 assert_eq ! ( md. data_class, i32 :: from( pb:: DataClass :: BlobSequence ) ) ;
519552 }
520553
554+ #[ test]
555+ fn test_metadata_tagged_run_metadata ( ) {
556+ let md = TaggedRunMetadataValue :: initial_metadata ( ) ;
557+ assert_eq ! (
558+ & md. plugin_data. unwrap( ) . plugin_name,
559+ GRAPH_TAGGED_RUN_METADATA_PLUGIN_NAME
560+ ) ;
561+ assert_eq ! ( md. data_class, i32 :: from( pb:: DataClass :: BlobSequence ) ) ;
562+ }
563+
521564 #[ test]
522565 fn test_metadata_tf1x_image ( ) {
523566 let v = SummaryValue ( Box :: new ( Value :: Image ( pb:: summary:: Image {
@@ -637,6 +680,15 @@ mod tests {
637680 ) ;
638681 }
639682
683+ #[ test]
684+ fn test_enrich_tagged_run_metadata ( ) {
685+ let v = EventValue :: TaggedRunMetadata ( TaggedRunMetadataValue ( vec ! [ 1 , 2 , 3 , 4 ] ) ) ;
686+ assert_eq ! (
687+ v. into_blob_sequence( GraphDefValue :: initial_metadata( ) . as_ref( ) ) ,
688+ Ok ( BlobSequenceValue ( vec![ vec![ 1 , 2 , 3 , 4 ] ] ) )
689+ ) ;
690+ }
691+
640692 #[ test]
641693 fn test_enrich_tf1x_image ( ) {
642694 let v = SummaryValue ( Box :: new ( Value :: Image ( pb:: summary:: Image {
0 commit comments