From c064aee5daab315a40d671875dcf5b9df2949f1a Mon Sep 17 00:00:00 2001 From: Daniel Galvez Date: Wed, 26 Apr 2023 15:58:35 -0700 Subject: [PATCH] polygraphy: Misc fixes for pytorch runner Fixes: ``` Fix [W] pytorch-runner-N0-04/26/23-22:50:28 | `inference_time` was not set. Inference time will be incorrect! To correctly compare runtimes, please set the `inference_time` attribute in `infer_impl()` ``` Also fixes `RuntimeError: Can't call numpy() on Tensor that requires grad. Use tensor.detach().numpy() instead.` --- tools/Polygraphy/polygraphy/backend/pyt/runner.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/Polygraphy/polygraphy/backend/pyt/runner.py b/tools/Polygraphy/polygraphy/backend/pyt/runner.py index 3f8e8b2d..32c63bc6 100644 --- a/tools/Polygraphy/polygraphy/backend/pyt/runner.py +++ b/tools/Polygraphy/polygraphy/backend/pyt/runner.py @@ -68,8 +68,9 @@ def infer_impl(self, feed_dict): out_dict = OrderedDict() for name, output in zip(self.output_names, outputs): - out_dict[name] = output.cpu().numpy() - return out_dict, end - start + out_dict[name] = output.detach().cpu().numpy() + self.inference_time = end - start + return out_dict def deactivate_impl(self): del self.model