// "{} (f32[42, 0, 10])". The alternative, calling Literal::ToString(),
// enumerates all of its empty dimensions (e.g. "{ { {}, {} }, ..."), which
// is just noise.
- if (ShapeUtil::HasZeroElements(shape)) {
+ if (!ShapeUtil::IsTuple(shape) && ShapeUtil::HasZeroElements(shape)) {
return Printf("{} (%s)", ShapeUtil::HumanString(constant->shape()));
}
EXPECT_THAT(graph, Not(HasSubstr("i_am_a_constant_root_instruction")));
}
+TEST(HloGraphDumperTest, TupleConstant) {
+ Shape tuple_shape = ShapeUtil::MakeTupleShape(
+ {ShapeUtil::MakeShape(F32, {3, 2}), ShapeUtil::MakeShape(S32, {4, 5})});
+ HloComputation::Builder b("b");
+ auto constant = b.AddInstruction(
+ HloInstruction::CreateConstant(Literal::CreateFromShape(tuple_shape)));
+ auto gte = b.AddInstruction(HloInstruction::CreateGetTupleElement(
+ ShapeUtil::MakeShape(F32, {3, 2}), constant, 0));
+
+ HloModuleConfig config;
+ HloModule m(TestName(), config);
+ HloComputation* root_computation = m.AddEntryComputation(b.Build(gte));
+ string graph = hlo_graph_dumper::DumpGraph(
+ *root_computation, /*label=*/"tuple_constant", DebugOptions());
+ EXPECT_THAT(graph, HasSubstr("tuple_constant"));
+ EXPECT_THAT(graph, HasSubstr("constant (f32[3,2], s32[4,5])"));
+}
+
} // anonymous namespace
} // namespace xla