@@ -158,76 +158,6 @@ def forward(self, x):
158
158
msg = f"CUDA Graph Python TRT outputs don't match with the original model. (trial: { i } )" ,
159
159
)
160
160
161
- def test_cudagraphs_dynamic_py (self ):
162
- class SampleModel (torch .nn .Module ):
163
- def forward (self , x ):
164
- return torch .relu ((x + 2 ) * 0.5 )
165
-
166
- # TODO: more dynamic dim
167
- # TODO: multiple output
168
- # TODO: module that graph cannot be used
169
- inputs = torch_tensorrt .Input (
170
- min_shape = (1 , 3 , 224 , 224 ),
171
- opt_shape = (8 , 3 , 224 , 224 ),
172
- max_shape = (16 , 3 , 224 , 224 ),
173
- dtype = torch .float ,
174
- name = "x" ,
175
- )
176
- fx_graph = torch .fx .symbolic_trace (SampleModel ())
177
-
178
- # Validate that the results between Torch and Torch-TRT are similar
179
- optimized_model = torch_tensorrt .compile (
180
- fx_graph ,
181
- "dynamo" ,
182
- inputs ,
183
- min_block_size = 1 ,
184
- pass_through_build_failures = True ,
185
- torch_executed_ops = {"torch.ops.aten.mul.Tensor" },
186
- use_python_runtime = True ,
187
- )
188
-
189
- result_samples = []
190
- torch_results_samples = []
191
-
192
- inputs = []
193
- for i in [1 , 3 , 8 , 11 , 16 ]:
194
- inputs .append (torch .randn ((i , 3 , 224 , 224 )).cuda ())
195
-
196
- for n in range (len (inputs ) * TRIALS ):
197
- i = n // TRIALS
198
- # disable cuda graph at all index for all trials
199
- if n % TRIALS == n // TRIALS :
200
- torch_tensorrt .runtime .set_cudagraphs_mode (False )
201
- else :
202
- torch_tensorrt .runtime .set_cudagraphs_mode (True )
203
-
204
- result_samples .append (optimized_model (inputs [i ]).detach ().cpu ())
205
- torch_results_samples .append (fx_graph (inputs [i ]).detach ().cpu ())
206
-
207
- for n in range (len (inputs ) * TRIALS ):
208
- i = n // TRIALS
209
- # enable cuda graph at all index for all trials
210
- if n % TRIALS == n // TRIALS :
211
- torch_tensorrt .runtime .set_cudagraphs_mode (True )
212
- else :
213
- torch_tensorrt .runtime .set_cudagraphs_mode (False )
214
-
215
- result_samples .append (optimized_model (inputs [i ]).detach ().cpu ())
216
- torch_results_samples .append (fx_graph (inputs [i ]).detach ().cpu ())
217
-
218
- for i , (optimized_model_results , torch_model_results ) in enumerate (
219
- zip (result_samples , torch_results_samples )
220
- ):
221
- max_diff = float (
222
- torch .max (torch .abs (optimized_model_results - torch_model_results ))
223
- )
224
- self .assertAlmostEqual (
225
- max_diff ,
226
- 0 ,
227
- DECIMALS_OF_AGREEMENT ,
228
- msg = f"CUDA Graph Python TRT outputs don't match with the original model. (trial: { i } )" ,
229
- )
230
-
231
161
232
162
if __name__ == "__main__" :
233
163
run_tests ()
0 commit comments