@@ -51,7 +51,7 @@ TEST(HloProtoToModuleTest, FixNonConsecutiveInstructionIds) {
5151 }
5252 }
5353 id: 4294967303
54- operand_ids: 6
54+ operand_ids: 1
5555 }
5656 id: 1
5757 root_id: 4294967303
@@ -88,6 +88,102 @@ TEST(HloProtoToModuleTest, FixNonConsecutiveInstructionIds) {
8888 ElementsAre (Property (&xla::HloInstruction::local_id, 0 ),
8989 Property (&xla::HloInstruction::local_id, 1 ),
9090 Property (&xla::HloInstruction::local_id, 2 )));
91+ // Check correct operand translation
92+ EXPECT_EQ (module ->entry_computation ()->parameter_instruction (0 )->name (),
93+ " arg0.1" );
94+ EXPECT_EQ (module ->entry_computation ()->parameter_instruction (0 )->local_id (),
95+ 0 );
96+ EXPECT_THAT (
97+ module ->entry_computation ()->root_instruction ()->operands (),
98+ ElementsAre (module ->entry_computation ()->parameter_instruction (0 )));
99+ }
100+
101+ TEST (HloProtoToModuleTest, FixNonConsecutiveInstructionIdsForModule) {
102+ xla::HloProto hlo_proto;
103+ ASSERT_TRUE (google::protobuf::TextFormat::ParseFromString (
104+ R"pb(
105+ hlo_module {
106+ name: "some_module"
107+ entry_computation_name: "some_module"
108+ computations {
109+ name: "some_module"
110+ instructions {
111+ name: "arg0.1"
112+ opcode: "parameter"
113+ shape {
114+ element_type: S32
115+ layout { tail_padding_alignment_in_elements: 1 }
116+ }
117+ id: 4294967297
118+ }
119+ instructions {
120+ name: "arg1.1"
121+ opcode: "parameter"
122+ shape {
123+ element_type: S32
124+ layout { tail_padding_alignment_in_elements: 1 }
125+ }
126+ parameter_number: 1
127+ id: 4294967298
128+ }
129+ instructions {
130+ name: "XLA_Retvals.1"
131+ opcode: "tuple"
132+ shape {
133+ element_type: TUPLE
134+ tuple_shapes {
135+ element_type: S32
136+ layout { tail_padding_alignment_in_elements: 1 }
137+ }
138+ }
139+ id: 4294967303
140+ operand_ids: 1
141+ }
142+ id: 1
143+ root_id: 4294967303
144+ }
145+ host_program_shape {
146+ parameters {
147+ element_type: S32
148+ layout { tail_padding_alignment_in_elements: 1 }
149+ }
150+ parameters {
151+ element_type: S32
152+ layout { tail_padding_alignment_in_elements: 1 }
153+ }
154+ result {
155+ element_type: TUPLE
156+ tuple_shapes {
157+ element_type: S32
158+ layout { tail_padding_alignment_in_elements: 1 }
159+ }
160+ }
161+ parameter_names: "arg0"
162+ parameter_names: "arg1"
163+ }
164+ id: 1
165+ entry_computation_id: 1
166+ }
167+ )pb" ,
168+ &hlo_proto));
169+
170+
171+ ASSERT_OK_AND_ASSIGN (auto module ,
172+ ConvertHloProtoToModule (hlo_proto));
173+ EXPECT_EQ (module ->entry_computation ()->instruction_count (), 3 );
174+ // Check that ids are consecutive
175+ EXPECT_THAT (module ->entry_computation ()->instructions (),
176+ ElementsAre (Property (&xla::HloInstruction::local_id, 0 ),
177+ Property (&xla::HloInstruction::local_id, 1 ),
178+ Property (&xla::HloInstruction::local_id, 2 )));
179+ // Check correct operand translation
180+ EXPECT_EQ (module ->entry_computation ()->parameter_instruction (0 )->name (),
181+ " arg0.1" );
182+ EXPECT_EQ (module ->entry_computation ()->parameter_instruction (0 )->local_id (),
183+ 0 );
184+ EXPECT_THAT (
185+ module ->entry_computation ()->root_instruction ()->operands (),
186+ ElementsAre (module ->entry_computation ()->parameter_instruction (0 )));
91187}
92188
93189} // namespace
0 commit comments