Fix a bug of literal prints in hlo_graph_dumper
authorA. Unique TensorFlower <gardener@tensorflow.org>
Wed, 9 May 2018 17:38:18 +0000 (10:38 -0700)
committerTensorFlower Gardener <gardener@tensorflow.org>
Wed, 9 May 2018 18:25:06 +0000 (11:25 -0700)
Sigterm was raised when no literal info is associated with constant instructions in HloProto.

PiperOrigin-RevId: 195992305

tensorflow/compiler/xla/service/hlo_graph_dumper.cc
tensorflow/compiler/xla/service/hlo_instruction.cc
tensorflow/compiler/xla/service/hlo_instruction.h

index b6b0387..55911ac 100644 (file)
@@ -825,7 +825,7 @@ string HloDotDumper::GetInstructionNodeInlinedOperands(
         *elem_count *= dim;
       }
     }
-    if (elem_count.has_value() && *elem_count <= 8) {
+    if (elem_count.has_value() && *elem_count <= 8 && constant->HasLiteral()) {
       return Printf("%s (%s)", constant->literal().ToString(),
                     ShapeUtil::HumanString(constant->shape()));
     }
index 857cd39..03e0391 100644 (file)
@@ -1557,6 +1557,8 @@ const Literal& HloInstruction::literal() const {
   return *literal_;
 }
 
+bool HloInstruction::HasLiteral() const { return literal_ != nullptr; }
+
 bool HloInstruction::CanHaveDimensionsField() const {
   return (opcode() == HloOpcode::kReverse ||
           opcode() == HloOpcode::kConcatenate ||
index 14be58d..511227a 100644 (file)
@@ -706,6 +706,9 @@ class HloInstruction {
   // Note: only constant and parameter opcodes have an associated literal.
   const Literal& literal() const;
 
+  // Returns whether there is literal associated with this instruction.
+  bool HasLiteral() const;
+
   // Returns the parameter number associated with this instruction.
   //
   // Note: only parameter opcodes have an associated parameter number.