@@ -1918,7 +1918,7 @@ def update_dim(tensor, dim, i, j, dim_param_prefix):
19181918
19191919 onnx .checker .check_model (model )
19201920 return model
1921-
1921+
19221922 onnx_model = update_inputs_dims (onnx_model , inputs_shapes )
19231923 onnx .save (onnx_model , model_path )
19241924
@@ -2517,7 +2517,7 @@ def get_name(self, op_type):
25172517 self .name_dict [op_type ] += 1
25182518 else :
25192519 self .name_dict [op_type ] = 0
2520-
2520+
25212521 return "{}.{}" .format (op_type , self .name_dict [op_type ])
25222522
25232523 node_name_manager = NodeNameManager ()
@@ -2607,3 +2607,42 @@ def make_node_with_constant(op_type, constant_value, inputs=None, outputs=None,
26072607
26082608gelu_approximation = nn .GELU ('tanh' )
26092609save_data_and_model ("gelu_approximation" , x , gelu_approximation )
2610+
2611+ # Test data for a part of model: https://huggingface.co/openai/clip-vit-base-patch32
2612+ input = np .random .standard_normal ((1 , 1 , 3 )).astype (np .float32 )
2613+ embedding = np .array ([4 , 5 , 6 ], dtype = np .float32 )
2614+ data = np .random .standard_normal ((2 , 3 )).astype (np .float32 )
2615+ indices = np .array ([[0 , 1 ]], dtype = np .int64 )
2616+
2617+ output = np .concatenate ((embedding .reshape (1 , 1 , 3 ), input ), axis = 1 ) + np .take (data , indices , axis = 0 )
2618+
2619+ embedding = onnx .numpy_helper .from_array (embedding , name = 'embedding' )
2620+ X = onnx .helper .make_tensor_value_info ('input' , onnx .TensorProto .FLOAT , input .shape )
2621+ Y = onnx .helper .make_tensor_value_info ('output' , onnx .TensorProto .FLOAT , output .shape )
2622+
2623+ shape = np .array ([1 , 1 , - 1 ], dtype = np .int32 )
2624+ shape = onnx .numpy_helper .from_array (shape , name = 'shape' )
2625+ expand = onnx .helper .make_node ("Expand" , inputs = ['embedding' , 'shape' ], outputs = ['expand' ])
2626+
2627+ one = np .array ([1 , 1 , 1 ], dtype = np .float32 )
2628+ one = onnx .numpy_helper .from_array (one , name = 'one' )
2629+ mul = onnx .helper .make_node ("Mul" , inputs = ['input' , 'one' ], outputs = ['input_mul' ])
2630+
2631+ concat = onnx .helper .make_node ("Concat" , inputs = ['expand' , 'input_mul' ], outputs = ['concat' ], axis = 1 )
2632+
2633+ data = onnx .numpy_helper .from_array (data , name = 'data' )
2634+ indices = onnx .numpy_helper .from_array (indices , name = 'indices' )
2635+
2636+ gather = onnx .helper .make_node ("Gather" , inputs = ['data' , 'indices' ], outputs = ['gather' ])
2637+ add = onnx .helper .make_node ("Add" , inputs = ['concat' , 'gather' ], outputs = ['output' ])
2638+
2639+ name = "clip-vit-base-head"
2640+ graph = onnx .helper .make_graph ([mul , expand , concat , gather , add ], name , [X ], [Y ], [embedding , data , indices , shape , one ])
2641+
2642+ model = onnx .helper .make_model (graph , producer_name = name )
2643+ onnx .save (model , os .path .join ("models" , name + ".onnx" ))
2644+
2645+ input_files = os .path .join ("data" , "input_" + name )
2646+ np .save (input_files , input .data )
2647+ output_files = os .path .join ("data" , "output_" + name )
2648+ np .save (output_files , np .ascontiguousarray (output .data ))
0 commit comments