From 6a3203048895085475a09600ec355c7bff70b6cd Mon Sep 17 00:00:00 2001 From: noklam Date: Sun, 11 Oct 2020 00:06:42 +0800 Subject: [PATCH 1/3] fix test1, need torch dependency --- testing/test1.py | 1 + 1 file changed, 1 insertion(+) diff --git a/testing/test1.py b/testing/test1.py index c960157..7008cac 100644 --- a/testing/test1.py +++ b/testing/test1.py @@ -23,6 +23,7 @@ """ import numpy as np import dis +import torch a = np.array([1,2,3]) g = globals() From f1ed689b815056e5cf7e519edde87c4ed9e613c1 Mon Sep 17 00:00:00 2001 From: noklam Date: Sun, 11 Oct 2020 00:07:06 +0800 Subject: [PATCH 2/3] avoding torch dependecies, checking type.__name__ instead of th e instance --- tsensor/analysis.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tsensor/analysis.py b/tsensor/analysis.py index abc624e..a9d902c 100644 --- a/tsensor/analysis.py +++ b/tsensor/analysis.py @@ -24,7 +24,6 @@ import os import sys import traceback -import torch import inspect import hashlib @@ -457,7 +456,7 @@ def istensor(x): def _shape(v): # do we have a shape and it answers len()? Should get stuff right. if hasattr(v, "shape") and hasattr(v.shape,"__len__"): - if isinstance(v.shape, torch.Size): + if type(v.shape).__name__ == "Size": if len(v.shape)==0: return None return list(v.shape) From 7494652519644035c437c7805f75437eab34aa0b Mon Sep 17 00:00:00 2001 From: noklam Date: Sun, 11 Oct 2020 00:51:06 +0800 Subject: [PATCH 3/3] Add checking for __module__ =='torch' --- tsensor/analysis.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tsensor/analysis.py b/tsensor/analysis.py index a9d902c..37c8269 100644 --- a/tsensor/analysis.py +++ b/tsensor/analysis.py @@ -455,8 +455,8 @@ def istensor(x): def _shape(v): # do we have a shape and it answers len()? Should get stuff right. - if hasattr(v, "shape") and hasattr(v.shape,"__len__"): - if type(v.shape).__name__ == "Size": + if hasattr(v, "shape") and hasattr(v.shape, "__len__"): + if v.shape.__class__.__module__ == "torch" and v.shape.__class__.__name__ == "Size": if len(v.shape)==0: return None return list(v.shape)