From 6ce2ad6eee75dd901deb901596eb7fda8d70a79d Mon Sep 17 00:00:00 2001 From: Jibin Varghese Date: Fri, 23 May 2025 02:08:56 +0000 Subject: [PATCH] Add a pytorch tensor representation type Signed-off-by: Jibin Varghese --- .../types/pydevd_plugin_pytorch_types.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 pydevd_plugins/extensions/types/pydevd_plugin_pytorch_types.py diff --git a/pydevd_plugins/extensions/types/pydevd_plugin_pytorch_types.py b/pydevd_plugins/extensions/types/pydevd_plugin_pytorch_types.py new file mode 100644 index 00000000..2eacb440 --- /dev/null +++ b/pydevd_plugins/extensions/types/pydevd_plugin_pytorch_types.py @@ -0,0 +1,17 @@ +from _pydevd_bundle.pydevd_extension_api import StrPresentationProvider +from .pydevd_helpers import find_mod_attr + + +class PyTorchTensorFormStr: + def can_provide(self, type_object, type_name): + torch_tensor_class = find_mod_attr('torch', 'Tensor') + return torch_tensor_class is not None and issubclass(type_object, torch_tensor_class) + + def get_str(self, val): + return "torch.Tensor [ %s , %s ]: %r" % (val.shape, val.device, val) + + +import sys + +if not sys.platform.startswith("java"): + StrPresentationProvider.register(PyTorchTensorFormStr)