@@ -165,6 +165,34 @@ def test_compile(self):
165
165
msg = f"tuple_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
166
166
)
167
167
168
+ def test_compile_full_compilation (self ):
169
+ self .input = torch .randn ((1 , 3 , 224 , 224 )).to ("cuda" )
170
+ self .model = (
171
+ torch .jit .load (MODULE_DIR + "/tuple_input_output_scripted.jit.pt" )
172
+ .eval ()
173
+ .to ("cuda" )
174
+ )
175
+
176
+ compile_spec = {
177
+ "input_signature" : (
178
+ (torchtrt .Input (self .input .shape ), torchtrt .Input (self .input .shape )),
179
+ ),
180
+ "device" : torchtrt .Device ("gpu:0" ),
181
+ "enabled_precisions" : {torch .float },
182
+ "min_block_size" : 1 ,
183
+ "require_full_compilation" : True ,
184
+ }
185
+
186
+ trt_mod = torchtrt .ts .compile (self .model , ** compile_spec )
187
+ trt_out = trt_mod ((self .input , self .input ))
188
+ pyt_out = self .model ((self .input , self .input ))
189
+ for (t , p ) in zip (trt_out , pyt_out ):
190
+ cos_sim = cosine_similarity (t , p )
191
+ self .assertTrue (
192
+ cos_sim > COSINE_THRESHOLD ,
193
+ msg = f"tuple_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
194
+ )
195
+
168
196
169
197
class TestListInputOutput (unittest .TestCase ):
170
198
def test_compile (self ):
@@ -196,6 +224,36 @@ def test_compile(self):
196
224
msg = f"list_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
197
225
)
198
226
227
+ def test_compile_full_compilation (self ):
228
+
229
+ self .input = torch .randn ((1 , 3 , 224 , 224 )).to ("cuda" )
230
+ self .model = (
231
+ torch .jit .load (MODULE_DIR + "/list_input_output_scripted.jit.pt" )
232
+ .eval ()
233
+ .to ("cuda" )
234
+ )
235
+
236
+ compile_spec = {
237
+ "input_signature" : (
238
+ [torchtrt .Input (self .input .shape ), torchtrt .Input (self .input .shape )],
239
+ ),
240
+ "device" : torchtrt .Device ("gpu:0" ),
241
+ "enabled_precisions" : {torch .float },
242
+ "min_block_size" : 1 ,
243
+ "require_full_compilation" : True ,
244
+ }
245
+
246
+ trt_mod = torchtrt .ts .compile (self .model , ** compile_spec )
247
+ trt_out = trt_mod ((self .input , self .input ))
248
+ pyt_out = self .model ((self .input , self .input ))
249
+
250
+ for (t , p ) in zip (trt_out , pyt_out ):
251
+ cos_sim = cosine_similarity (t , p )
252
+ self .assertTrue (
253
+ cos_sim > COSINE_THRESHOLD ,
254
+ msg = f"list_input_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
255
+ )
256
+
199
257
200
258
class TestListInputTupleOutput (unittest .TestCase ):
201
259
def test_compile (self ):
@@ -226,6 +284,35 @@ def test_compile(self):
226
284
msg = f"list_input_tuple_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
227
285
)
228
286
287
+ def test_compile_full_compilation (self ):
288
+
289
+ self .input = torch .randn ((1 , 3 , 224 , 224 )).to ("cuda" )
290
+ self .model = (
291
+ torch .jit .load (MODULE_DIR + "/list_input_tuple_output_scripted.jit.pt" )
292
+ .eval ()
293
+ .to ("cuda" )
294
+ )
295
+
296
+ compile_spec = {
297
+ "input_signature" : (
298
+ [torchtrt .Input (self .input .shape ), torchtrt .Input (self .input .shape )],
299
+ ),
300
+ "device" : torchtrt .Device ("gpu:0" ),
301
+ "enabled_precisions" : {torch .float },
302
+ "min_block_size" : 1 ,
303
+ "require_full_compilation" : True ,
304
+ }
305
+
306
+ trt_mod = torchtrt .ts .compile (self .model , ** compile_spec )
307
+ trt_out = trt_mod ((self .input , self .input ))
308
+ pyt_out = self .model ((self .input , self .input ))
309
+ for (t , p ) in zip (trt_out , pyt_out ):
310
+ cos_sim = cosine_similarity (t , p )
311
+ self .assertTrue (
312
+ cos_sim > COSINE_THRESHOLD ,
313
+ msg = f"list_input_tuple_output_scripted TRT outputs don't match with the original model. Cosine sim score: { cos_sim } Threshold: { COSINE_THRESHOLD } " ,
314
+ )
315
+
229
316
230
317
if __name__ == "__main__" :
231
318
unittest .main ()
0 commit comments