@@ -151,6 +151,48 @@ def test_mini_onnx_builder_transformers_sep(self):
151151 restored = create_input_tensors_from_onnx_model (model , sep = "#" )
152152 self .assertEqualAny (inputs , restored )
153153
154+ def test_specific_data (self ):
155+ data = {
156+ ("amain" , 0 , "I" ): (
157+ (
158+ torch .rand ((2 , 16 , 3 , 448 , 448 ), dtype = torch .float16 ),
159+ torch .rand ((2 , 16 , 32 , 32 ), dtype = torch .float16 ),
160+ torch .rand ((2 , 2 )).to (torch .int64 ),
161+ ),
162+ {},
163+ ),
164+ }
165+ model = create_onnx_model_from_input_tensors (data )
166+ shapes = [
167+ tuple (d .dim_value for d in i .type .tensor_type .shape .dim )
168+ for i in model .graph .output
169+ ]
170+ self .assertEqual (shapes , [(2 , 16 , 3 , 448 , 448 ), (2 , 16 , 32 , 32 ), (2 , 2 ), (0 ,)])
171+ names = [i .name for i in model .graph .output ]
172+ self .assertEqual (
173+ [
174+ "dict._((amain,0,I))___tuple_0___tuple_0___tensor" ,
175+ "dict._((amain,0,I))___tuple_0___tuple_1___tensor" ,
176+ "dict._((amain,0,I))___tuple_0___tuple_2.___tensor" ,
177+ "dict._((amain,0,I))___tuple_1.___dict.___empty" ,
178+ ],
179+ names ,
180+ )
181+ shapes = [tuple (i .dims ) for i in model .graph .initializer ]
182+ self .assertEqual (shapes , [(2 , 16 , 3 , 448 , 448 ), (2 , 16 , 32 , 32 ), (2 , 2 ), (0 ,)])
183+ names = [i .name for i in model .graph .initializer ]
184+ self .assertEqual (
185+ [
186+ "t_dict._((amain,0,I))___tuple_0___tuple_0___tensor" ,
187+ "t_dict._((amain,0,I))___tuple_0___tuple_1___tensor" ,
188+ "t_dict._((amain,0,I))___tuple_0___tuple_2.___tensor" ,
189+ "t_dict._((amain,0,I))___tuple_1.___dict.___empty" ,
190+ ],
191+ names ,
192+ )
193+ restored = create_input_tensors_from_onnx_model (model )
194+ self .assertEqualAny (data , restored )
195+
154196
155197if __name__ == "__main__" :
156198 unittest .main (verbosity = 2 )
0 commit comments