@@ -59,6 +59,88 @@ def test_fused_matmul11(self):
59
59
got = ref .run (None , {"X" : a , "Y" : a })
60
60
self .assertEqualArray (a .T @ a .T , got [0 ])
61
61
62
+ def test_memcpy (self ):
63
+ model = make_model (
64
+ make_graph (
65
+ [
66
+ make_node ("MemcpyToHost" , ["X" ], ["Z" ]),
67
+ make_node ("MemcpyFromHost" , ["X" ], ["Z" ]),
68
+ ],
69
+ "name" ,
70
+ [make_tensor_value_info ("X" , TensorProto .FLOAT , None )],
71
+ [make_tensor_value_info ("Z" , TensorProto .FLOAT , None )],
72
+ ),
73
+ opset_imports = [make_opsetid ("" , 18 ), make_opsetid ("com.microsoft" , 1 )],
74
+ ir_version = 9 ,
75
+ )
76
+ a = np .arange (4 ).reshape (- 1 , 2 ).astype (np .float32 )
77
+ ref = ExtendedReferenceEvaluator (model )
78
+ got = ref .run (None , {"X" : a })
79
+ self .assertEqualArray (a , got [0 ])
80
+
81
+ def test_quick_gelu (self ):
82
+ from onnxruntime import InferenceSession
83
+
84
+ for alpha in [0.0 , 2.0 ]:
85
+ model = make_model (
86
+ make_graph (
87
+ [
88
+ make_node (
89
+ "QuickGelu" ,
90
+ ["X" ],
91
+ ["Z" ],
92
+ domain = "com.microsoft" ,
93
+ alpha = alpha ,
94
+ )
95
+ ],
96
+ "name" ,
97
+ [make_tensor_value_info ("X" , TensorProto .FLOAT , None )],
98
+ [make_tensor_value_info ("Z" , TensorProto .FLOAT , None )],
99
+ ),
100
+ opset_imports = [make_opsetid ("" , 18 ), make_opsetid ("com.microsoft" , 1 )],
101
+ ir_version = 9 ,
102
+ )
103
+ sess = InferenceSession (
104
+ model .SerializeToString (), providers = ["CPUExecutionProvider" ]
105
+ )
106
+ a = np .arange (4 ).reshape (- 1 , 2 ).astype (np .float32 )
107
+ expected = sess .run (None , {"X" : a })
108
+ ref = ExtendedReferenceEvaluator (model )
109
+ got = ref .run (None , {"X" : a })
110
+ self .assertEqualArray (expected [0 ], got [0 ])
111
+
112
+ def test_scatter_elements (self ):
113
+ model = make_model (
114
+ make_graph (
115
+ [
116
+ make_node (
117
+ "ScatterElements" ,
118
+ ["data" , "indices" , "updates" ],
119
+ ["Z" ],
120
+ axis = 3 ,
121
+ reduction = "add" ,
122
+ )
123
+ ],
124
+ "name" ,
125
+ [
126
+ make_tensor_value_info ("data" , TensorProto .FLOAT , None ),
127
+ make_tensor_value_info ("indices" , TensorProto .INT64 , None ),
128
+ make_tensor_value_info ("updates" , TensorProto .FLOAT , None ),
129
+ ],
130
+ [make_tensor_value_info ("Z" , TensorProto .FLOAT , None )],
131
+ ),
132
+ opset_imports = [make_opsetid ("" , 18 )],
133
+ )
134
+ data = np .zeros (2 ** 4 , dtype = np .float32 ).reshape ((2 , 2 , 2 , 2 ))
135
+ indices = np .array ([[[[0 ]]]], dtype = np .int64 )
136
+ updates = np .array ([[[[1 ]]]], dtype = np .float32 )
137
+ y = np .array (
138
+ [1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ], dtype = np .float32
139
+ ).reshape ((2 , 2 , 2 , 2 ))
140
+ ref = ExtendedReferenceEvaluator (model )
141
+ got = ref .run (None , {"data" : data , "indices" : indices , "updates" : updates })
142
+ self .assertEqualArray (y , got [0 ])
143
+
62
144
63
145
if __name__ == "__main__" :
64
146
unittest .main (verbosity = 2 )
0 commit comments