From 94af4bbbc0593ff1c13ae019fc38c66c43ec4288 Mon Sep 17 00:00:00 2001 From: Johannes Messner Date: Thu, 20 Apr 2023 19:48:27 +0200 Subject: [PATCH] fix: torch tensor with grad to numpy Signed-off-by: Johannes Messner --- docarray/index/abstract.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docarray/index/abstract.py b/docarray/index/abstract.py index a6eecbf185c..17da44221d8 100644 --- a/docarray/index/abstract.py +++ b/docarray/index/abstract.py @@ -854,9 +854,9 @@ def _to_numpy(self, val: Any, allow_passthrough=False) -> Any: return val.unwrap().numpy() if isinstance(val, (list, tuple)): return np.array(val) - if (torch is not None and isinstance(val, torch.Tensor)) or ( - tf is not None and isinstance(val, tf.Tensor) - ): + if torch is not None and isinstance(val, torch.Tensor): + return val.detach().numpy() + if tf is not None and isinstance(val, tf.Tensor): return val.numpy() if allow_passthrough: return val