We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
unsupported Python type error from set_default_tensor_type()
Hi,
I've updated pytorch to the lastest master (`a54407a7`) from github, but got an error when I use `torch.set_default_tensor_type("torch.cuda.FloatTensor")`:
```
terminate called after throwing an instance of 'std::invalid_argument'
  what():  unsupported Python type
Aborted (core dumped)
```

What to do for workaround? Thanks!
Jin

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `torch/__init__.py`
Content:
```
1 """
2 The torch package contains data structures for multi-dimensional
3 tensors and mathematical operations over these are defined.
4 Additionally, it provides many utilities for efficient serializing of
5 Tensors and arbitrary types, and other useful utilities.
6 
7 It has a CUDA counterpart, that enables you to run your tensor computations
8 on an NVIDIA GPU with compute capability >= 3.0.
9 """
10 
11 import sys
12 import platform
13 from ._utils import _import_dotted_name
14 from .version import __version__
15 
16 __all__ = [
17     'typename', 'is_tensor', 'is_storage', 'set_default_tensor_type',
18     'set_rng_state', 'get_rng_state', 'manual_seed', 'initial_seed',
19     'save', 'load', 'set_printoptions', 'chunk', 'split', 'stack', 'matmul',
20     'no_grad', 'enable_grad',
21     'DoubleStorage', 'FloatStorage', 'LongStorage', 'IntStorage',
22     'ShortStorage', 'CharStorage', 'ByteStorage',
23     'DoubleTensor', 'FloatTensor', 'LongTensor', 'IntTensor',
24     'ShortTensor', 'CharTensor', 'ByteTensor',
25 ]
26 
27 ################################################################################
28 # Load the extension module
29 ################################################################################
30 
31 # Loading the extension with RTLD_GLOBAL option allows to not link extension
32 # modules against the _C shared object. Their missing THP symbols will be
33 # automatically filled by the dynamic loader.
34 import os as _dl_flags
35 
36 # if we have numpy, it *must* be imported before the call to setdlopenflags()
37 # or there is risk that later c modules will segfault when importing numpy
38 try:
39     import numpy as _np
40 except ImportError:
41     pass
42 
43 if platform.system() == 'Windows':
44     # first get nvToolsExt PATH
45     def get_nvToolsExt_path():
46         NVTOOLEXT_HOME = _dl_flags.getenv('NVTOOLSEXT_PATH', 'C:\\Program Files\\NVIDIA Corporation\\NvToolsExt')
47 
48         if _dl_flags.path.exists(NVTOOLEXT_HOME):
49             return NVTOOLEXT_HOME + '\\bin\\x64\\'
50         else:
51             return ''
52 
53     # then add the path to env
54     _dl_flags.environ['PATH'] = _dl_flags.path.dirname(
55         __file__) + '\\lib\\;' + get_nvToolsExt_path() + ';' + _dl_flags.environ['PATH']
56 
57 else:
58     # first check if the os package has the required flags
59     if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):
60         try:
61             # next try if DLFCN exists
62             import DLFCN as _dl_flags
63         except ImportError:
64             # as a last attempt, use compile-time constants
65             import torch._dl as _dl_flags
66 
67     old_flags = sys.getdlopenflags()
68     sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)
69 
70 del _dl_flags
71 
72 try:
73     import torch._nvrtc
74 except ImportError:
75     pass
76 
77 from torch._C import *
78 
79 __all__ += [name for name in dir(_C)
80             if name[0] != '_' and
81             not name.endswith('Base')]
82 
83 if platform.system() != 'Windows':
84     sys.setdlopenflags(old_flags)
85     del old_flags
86 
87 ################################################################################
88 # Define basic utilities
89 ################################################################################
90 
91 
92 def typename(o):
93     module = ''
94     class_name = ''
95     if hasattr(o, '__module__') and o.__module__ != 'builtins' \
96             and o.__module__ != '__builtin__' and o.__module__ is not None:
97         module = o.__module__ + '.'
98 
99     if hasattr(o, '__qualname__'):
100         class_name = o.__qualname__
101     elif hasattr(o, '__name__'):
102         class_name = o.__name__
103     else:
104         class_name = o.__class__.__name__
105 
106     return module + class_name
107 
108 
109 def is_tensor(obj):
110     r"""Returns True if `obj` is a pytorch tensor.
111 
112     Args:
113         obj (Object): Object to test
114     """
115     return type(obj) in _tensor_classes
116 
117 
118 def is_storage(obj):
119     r"""Returns True if `obj` is a pytorch storage object.
120 
121     Args:
122         obj (Object): Object to test
123     """
124     return type(obj) in _storage_classes
125 
126 
127 def set_default_tensor_type(t):
128     global Tensor
129     global Storage
130     Tensor = _import_dotted_name(t)
131     Storage = _import_dotted_name(t.replace('Tensor', 'Storage'))
132     _C._set_default_tensor_type(Tensor)
133 
134 
135 from .random import set_rng_state, get_rng_state, manual_seed, initial_seed
136 from .serialization import save, load
137 from ._tensor_str import set_printoptions
138 
139 ################################################################################
140 # Define Storage and Tensor classes
141 ################################################################################
142 
143 from .storage import _StorageBase
144 from .tensor import _TensorBase
145 
146 
147 class DoubleStorage(_C.DoubleStorageBase, _StorageBase):
148     pass
149 
150 
151 class FloatStorage(_C.FloatStorageBase, _StorageBase):
152     pass
153 
154 
155 class HalfStorage(_C.HalfStorageBase, _StorageBase):
156     pass
157 
158 
159 class LongStorage(_C.LongStorageBase, _StorageBase):
160     pass
161 
162 
163 class IntStorage(_C.IntStorageBase, _StorageBase):
164     pass
165 
166 
167 class ShortStorage(_C.ShortStorageBase, _StorageBase):
168     pass
169 
170 
171 class CharStorage(_C.CharStorageBase, _StorageBase):
172     pass
173 
174 
175 class ByteStorage(_C.ByteStorageBase, _StorageBase):
176     pass
177 
178 
179 class DoubleTensor(_C.DoubleTensorBase, _TensorBase):
180 
181     def is_signed(self):
182         return True
183 
184     @classmethod
185     def storage_type(cls):
186         return DoubleStorage
187 
188 
189 class FloatTensor(_C.FloatTensorBase, _TensorBase):
190 
191     def is_signed(self):
192         return True
193 
194     @classmethod
195     def storage_type(cls):
196         return FloatStorage
197 
198 
199 class HalfTensor(_C.HalfTensorBase, _TensorBase):
200 
201     def is_signed(self):
202         return True
203 
204     @classmethod
205     def storage_type(cls):
206         return HalfStorage
207 
208 
209 class LongTensor(_C.LongTensorBase, _TensorBase):
210 
211     def is_signed(self):
212         return True
213 
214     @classmethod
215     def storage_type(cls):
216         return LongStorage
217 
218 
219 class IntTensor(_C.IntTensorBase, _TensorBase):
220 
221     def is_signed(self):
222         return True
223 
224     @classmethod
225     def storage_type(cls):
226         return IntStorage
227 
228 
229 class ShortTensor(_C.ShortTensorBase, _TensorBase):
230 
231     def is_signed(self):
232         return True
233 
234     @classmethod
235     def storage_type(cls):
236         return ShortStorage
237 
238 
239 class CharTensor(_C.CharTensorBase, _TensorBase):
240 
241     def is_signed(self):
242         # TODO
243         return False
244 
245     @classmethod
246     def storage_type(cls):
247         return CharStorage
248 
249 
250 class ByteTensor(_C.ByteTensorBase, _TensorBase):
251 
252     def is_signed(self):
253         return False
254 
255     @classmethod
256     def storage_type(cls):
257         return ByteStorage
258 
259 
260 _storage_classes = {
261     DoubleStorage, FloatStorage, LongStorage, IntStorage, ShortStorage,
262     CharStorage, ByteStorage, HalfStorage
263 }
264 
265 _tensor_classes = {
266     DoubleTensor, FloatTensor, LongTensor, IntTensor, ShortTensor,
267     CharTensor, ByteTensor, HalfTensor
268 }
269 
270 _integer_tensor_classes = {
271     LongTensor, IntTensor, ShortTensor, CharTensor, ByteTensor
272 }
273 
274 
275 ################################################################################
276 # Import interface functions defined in Python
277 ################################################################################
278 
279 from .functional import *
280 
281 
282 ################################################################################
283 # Initialize extension
284 ################################################################################
285 
286 def manager_path():
287     if platform.system() == 'Windows':
288         return b""
289     import os
290     path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'torch_shm_manager')
291     if not os.path.exists(path):
292         raise RuntimeError("Unable to find torch_shm_manager at " + path)
293     return path.encode('utf-8')
294 
295 
296 # Shared memory manager needs to know the exact location of manager executable
297 _C._initExtension(manager_path())
298 del manager_path
299 
300 set_default_tensor_type('torch.FloatTensor')
301 
302 ################################################################################
303 # Remove unnecessary members
304 ################################################################################
305 
306 del DoubleStorageBase
307 del FloatStorageBase
308 del LongStorageBase
309 del IntStorageBase
310 del ShortStorageBase
311 del CharStorageBase
312 del ByteStorageBase
313 del DoubleTensorBase
314 del FloatTensorBase
315 del LongTensorBase
316 del IntTensorBase
317 del ShortTensorBase
318 del CharTensorBase
319 del ByteTensorBase
320 
321 del SparseDoubleTensorBase
322 del SparseFloatTensorBase
323 del SparseLongTensorBase
324 del SparseIntTensorBase
325 del SparseShortTensorBase
326 del SparseCharTensorBase
327 del SparseByteTensorBase
328 
329 ################################################################################
330 # Import most common subpackages
331 ################################################################################
332 
333 import torch.cuda
334 import torch.autograd
335 import torch.nn
336 import torch.optim
337 import torch.multiprocessing
338 import torch.sparse
339 import torch.utils.backcompat
340 import torch.onnx
341 import torch.random
342 import torch.distributions
343 import torch.testing
344 from torch.autograd import no_grad, enable_grad
345 
346 _C._init_names(list(torch._tensor_classes) + list(torch._storage_classes))
347 
348 # attach docstrings to torch and tensor functions
349 from . import _torch_docs, _tensor_docs, _storage_docs
350 del _torch_docs, _tensor_docs, _storage_docs
351
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/torch/__init__.py b/torch/__init__.py
--- a/torch/__init__.py
+++ b/torch/__init__.py
@@ -129,6 +129,11 @@
     global Storage
     Tensor = _import_dotted_name(t)
     Storage = _import_dotted_name(t.replace('Tensor', 'Storage'))
+
+    if 'cuda' in t:
+        import torch.cuda
+        torch.cuda.init()
+
     _C._set_default_tensor_type(Tensor)

{"golden_diff": "diff --git a/torch/__init__.py b/torch/__init__.py\n--- a/torch/__init__.py\n+++ b/torch/__init__.py\n@@ -129,6 +129,11 @@\n     global Storage\n     Tensor = _import_dotted_name(t)\n     Storage = _import_dotted_name(t.replace('Tensor', 'Storage'))\n+\n+    if 'cuda' in t:\n+        import torch.cuda\n+        torch.cuda.init()\n+\n     _C._set_default_tensor_type(Tensor)\n", "issue": "unsupported Python type error from set_default_tensor_type()\nHi,\r\nI've updated pytorch to the lastest master (`a54407a7`) from github, but got an error when I use `torch.set_default_tensor_type(\"torch.cuda.FloatTensor\")`:\r\n```\r\nterminate called after throwing an instance of 'std::invalid_argument'\r\n  what():  unsupported Python type\r\nAborted (core dumped)\r\n```\r\n\r\nWhat to do for workaround? Thanks!\r\nJin\n", "before_files": [{"content": "\"\"\"\nThe torch package contains data structures for multi-dimensional\ntensors and mathematical operations over these are defined.\nAdditionally, it provides many utilities for efficient serializing of\nTensors and arbitrary types, and other useful utilities.\n\nIt has a CUDA counterpart, that enables you to run your tensor computations\non an NVIDIA GPU with compute capability >= 3.0.\n\"\"\"\n\nimport sys\nimport platform\nfrom ._utils import _import_dotted_name\nfrom .version import __version__\n\n__all__ = [\n    'typename', 'is_tensor', 'is_storage', 'set_default_tensor_type',\n    'set_rng_state', 'get_rng_state', 'manual_seed', 'initial_seed',\n    'save', 'load', 'set_printoptions', 'chunk', 'split', 'stack', 'matmul',\n    'no_grad', 'enable_grad',\n    'DoubleStorage', 'FloatStorage', 'LongStorage', 'IntStorage',\n    'ShortStorage', 'CharStorage', 'ByteStorage',\n    'DoubleTensor', 'FloatTensor', 'LongTensor', 'IntTensor',\n    'ShortTensor', 'CharTensor', 'ByteTensor',\n]\n\n################################################################################\n# Load the extension module\n################################################################################\n\n# Loading the extension with RTLD_GLOBAL option allows to not link extension\n# modules against the _C shared object. Their missing THP symbols will be\n# automatically filled by the dynamic loader.\nimport os as _dl_flags\n\n# if we have numpy, it *must* be imported before the call to setdlopenflags()\n# or there is risk that later c modules will segfault when importing numpy\ntry:\n    import numpy as _np\nexcept ImportError:\n    pass\n\nif platform.system() == 'Windows':\n    # first get nvToolsExt PATH\n    def get_nvToolsExt_path():\n        NVTOOLEXT_HOME = _dl_flags.getenv('NVTOOLSEXT_PATH', 'C:\\\\Program Files\\\\NVIDIA Corporation\\\\NvToolsExt')\n\n        if _dl_flags.path.exists(NVTOOLEXT_HOME):\n            return NVTOOLEXT_HOME + '\\\\bin\\\\x64\\\\'\n        else:\n            return ''\n\n    # then add the path to env\n    _dl_flags.environ['PATH'] = _dl_flags.path.dirname(\n        __file__) + '\\\\lib\\\\;' + get_nvToolsExt_path() + ';' + _dl_flags.environ['PATH']\n\nelse:\n    # first check if the os package has the required flags\n    if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):\n        try:\n            # next try if DLFCN exists\n            import DLFCN as _dl_flags\n        except ImportError:\n            # as a last attempt, use compile-time constants\n            import torch._dl as _dl_flags\n\n    old_flags = sys.getdlopenflags()\n    sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)\n\ndel _dl_flags\n\ntry:\n    import torch._nvrtc\nexcept ImportError:\n    pass\n\nfrom torch._C import *\n\n__all__ += [name for name in dir(_C)\n            if name[0] != '_' and\n            not name.endswith('Base')]\n\nif platform.system() != 'Windows':\n    sys.setdlopenflags(old_flags)\n    del old_flags\n\n################################################################################\n# Define basic utilities\n################################################################################\n\n\ndef typename(o):\n    module = ''\n    class_name = ''\n    if hasattr(o, '__module__') and o.__module__ != 'builtins' \\\n            and o.__module__ != '__builtin__' and o.__module__ is not None:\n        module = o.__module__ + '.'\n\n    if hasattr(o, '__qualname__'):\n        class_name = o.__qualname__\n    elif hasattr(o, '__name__'):\n        class_name = o.__name__\n    else:\n        class_name = o.__class__.__name__\n\n    return module + class_name\n\n\ndef is_tensor(obj):\n    r\"\"\"Returns True if `obj` is a pytorch tensor.\n\n    Args:\n        obj (Object): Object to test\n    \"\"\"\n    return type(obj) in _tensor_classes\n\n\ndef is_storage(obj):\n    r\"\"\"Returns True if `obj` is a pytorch storage object.\n\n    Args:\n        obj (Object): Object to test\n    \"\"\"\n    return type(obj) in _storage_classes\n\n\ndef set_default_tensor_type(t):\n    global Tensor\n    global Storage\n    Tensor = _import_dotted_name(t)\n    Storage = _import_dotted_name(t.replace('Tensor', 'Storage'))\n    _C._set_default_tensor_type(Tensor)\n\n\nfrom .random import set_rng_state, get_rng_state, manual_seed, initial_seed\nfrom .serialization import save, load\nfrom ._tensor_str import set_printoptions\n\n################################################################################\n# Define Storage and Tensor classes\n################################################################################\n\nfrom .storage import _StorageBase\nfrom .tensor import _TensorBase\n\n\nclass DoubleStorage(_C.DoubleStorageBase, _StorageBase):\n    pass\n\n\nclass FloatStorage(_C.FloatStorageBase, _StorageBase):\n    pass\n\n\nclass HalfStorage(_C.HalfStorageBase, _StorageBase):\n    pass\n\n\nclass LongStorage(_C.LongStorageBase, _StorageBase):\n    pass\n\n\nclass IntStorage(_C.IntStorageBase, _StorageBase):\n    pass\n\n\nclass ShortStorage(_C.ShortStorageBase, _StorageBase):\n    pass\n\n\nclass CharStorage(_C.CharStorageBase, _StorageBase):\n    pass\n\n\nclass ByteStorage(_C.ByteStorageBase, _StorageBase):\n    pass\n\n\nclass DoubleTensor(_C.DoubleTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return DoubleStorage\n\n\nclass FloatTensor(_C.FloatTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return FloatStorage\n\n\nclass HalfTensor(_C.HalfTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return HalfStorage\n\n\nclass LongTensor(_C.LongTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return LongStorage\n\n\nclass IntTensor(_C.IntTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return IntStorage\n\n\nclass ShortTensor(_C.ShortTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return ShortStorage\n\n\nclass CharTensor(_C.CharTensorBase, _TensorBase):\n\n    def is_signed(self):\n        # TODO\n        return False\n\n    @classmethod\n    def storage_type(cls):\n        return CharStorage\n\n\nclass ByteTensor(_C.ByteTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return False\n\n    @classmethod\n    def storage_type(cls):\n        return ByteStorage\n\n\n_storage_classes = {\n    DoubleStorage, FloatStorage, LongStorage, IntStorage, ShortStorage,\n    CharStorage, ByteStorage, HalfStorage\n}\n\n_tensor_classes = {\n    DoubleTensor, FloatTensor, LongTensor, IntTensor, ShortTensor,\n    CharTensor, ByteTensor, HalfTensor\n}\n\n_integer_tensor_classes = {\n    LongTensor, IntTensor, ShortTensor, CharTensor, ByteTensor\n}\n\n\n################################################################################\n# Import interface functions defined in Python\n################################################################################\n\nfrom .functional import *\n\n\n################################################################################\n# Initialize extension\n################################################################################\n\ndef manager_path():\n    if platform.system() == 'Windows':\n        return b\"\"\n    import os\n    path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'torch_shm_manager')\n    if not os.path.exists(path):\n        raise RuntimeError(\"Unable to find torch_shm_manager at \" + path)\n    return path.encode('utf-8')\n\n\n# Shared memory manager needs to know the exact location of manager executable\n_C._initExtension(manager_path())\ndel manager_path\n\nset_default_tensor_type('torch.FloatTensor')\n\n################################################################################\n# Remove unnecessary members\n################################################################################\n\ndel DoubleStorageBase\ndel FloatStorageBase\ndel LongStorageBase\ndel IntStorageBase\ndel ShortStorageBase\ndel CharStorageBase\ndel ByteStorageBase\ndel DoubleTensorBase\ndel FloatTensorBase\ndel LongTensorBase\ndel IntTensorBase\ndel ShortTensorBase\ndel CharTensorBase\ndel ByteTensorBase\n\ndel SparseDoubleTensorBase\ndel SparseFloatTensorBase\ndel SparseLongTensorBase\ndel SparseIntTensorBase\ndel SparseShortTensorBase\ndel SparseCharTensorBase\ndel SparseByteTensorBase\n\n################################################################################\n# Import most common subpackages\n################################################################################\n\nimport torch.cuda\nimport torch.autograd\nimport torch.nn\nimport torch.optim\nimport torch.multiprocessing\nimport torch.sparse\nimport torch.utils.backcompat\nimport torch.onnx\nimport torch.random\nimport torch.distributions\nimport torch.testing\nfrom torch.autograd import no_grad, enable_grad\n\n_C._init_names(list(torch._tensor_classes) + list(torch._storage_classes))\n\n# attach docstrings to torch and tensor functions\nfrom . import _torch_docs, _tensor_docs, _storage_docs\ndel _torch_docs, _tensor_docs, _storage_docs\n", "path": "torch/__init__.py"}], "after_files": [{"content": "\"\"\"\nThe torch package contains data structures for multi-dimensional\ntensors and mathematical operations over these are defined.\nAdditionally, it provides many utilities for efficient serializing of\nTensors and arbitrary types, and other useful utilities.\n\nIt has a CUDA counterpart, that enables you to run your tensor computations\non an NVIDIA GPU with compute capability >= 3.0.\n\"\"\"\n\nimport sys\nimport platform\nfrom ._utils import _import_dotted_name\nfrom .version import __version__\n\n__all__ = [\n    'typename', 'is_tensor', 'is_storage', 'set_default_tensor_type',\n    'set_rng_state', 'get_rng_state', 'manual_seed', 'initial_seed',\n    'save', 'load', 'set_printoptions', 'chunk', 'split', 'stack', 'matmul',\n    'no_grad', 'enable_grad',\n    'DoubleStorage', 'FloatStorage', 'LongStorage', 'IntStorage',\n    'ShortStorage', 'CharStorage', 'ByteStorage',\n    'DoubleTensor', 'FloatTensor', 'LongTensor', 'IntTensor',\n    'ShortTensor', 'CharTensor', 'ByteTensor',\n]\n\n################################################################################\n# Load the extension module\n################################################################################\n\n# Loading the extension with RTLD_GLOBAL option allows to not link extension\n# modules against the _C shared object. Their missing THP symbols will be\n# automatically filled by the dynamic loader.\nimport os as _dl_flags\n\n# if we have numpy, it *must* be imported before the call to setdlopenflags()\n# or there is risk that later c modules will segfault when importing numpy\ntry:\n    import numpy as _np\nexcept ImportError:\n    pass\n\nif platform.system() == 'Windows':\n    # first get nvToolsExt PATH\n    def get_nvToolsExt_path():\n        NVTOOLEXT_HOME = _dl_flags.getenv('NVTOOLSEXT_PATH', 'C:\\\\Program Files\\\\NVIDIA Corporation\\\\NvToolsExt')\n\n        if _dl_flags.path.exists(NVTOOLEXT_HOME):\n            return NVTOOLEXT_HOME + '\\\\bin\\\\x64\\\\'\n        else:\n            return ''\n\n    # then add the path to env\n    _dl_flags.environ['PATH'] = _dl_flags.path.dirname(\n        __file__) + '\\\\lib\\\\;' + get_nvToolsExt_path() + ';' + _dl_flags.environ['PATH']\n\nelse:\n    # first check if the os package has the required flags\n    if not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_LAZY'):\n        try:\n            # next try if DLFCN exists\n            import DLFCN as _dl_flags\n        except ImportError:\n            # as a last attempt, use compile-time constants\n            import torch._dl as _dl_flags\n\n    old_flags = sys.getdlopenflags()\n    sys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_LAZY)\n\ndel _dl_flags\n\ntry:\n    import torch._nvrtc\nexcept ImportError:\n    pass\n\nfrom torch._C import *\n\n__all__ += [name for name in dir(_C)\n            if name[0] != '_' and\n            not name.endswith('Base')]\n\nif platform.system() != 'Windows':\n    sys.setdlopenflags(old_flags)\n    del old_flags\n\n################################################################################\n# Define basic utilities\n################################################################################\n\n\ndef typename(o):\n    module = ''\n    class_name = ''\n    if hasattr(o, '__module__') and o.__module__ != 'builtins' \\\n            and o.__module__ != '__builtin__' and o.__module__ is not None:\n        module = o.__module__ + '.'\n\n    if hasattr(o, '__qualname__'):\n        class_name = o.__qualname__\n    elif hasattr(o, '__name__'):\n        class_name = o.__name__\n    else:\n        class_name = o.__class__.__name__\n\n    return module + class_name\n\n\ndef is_tensor(obj):\n    r\"\"\"Returns True if `obj` is a pytorch tensor.\n\n    Args:\n        obj (Object): Object to test\n    \"\"\"\n    return type(obj) in _tensor_classes\n\n\ndef is_storage(obj):\n    r\"\"\"Returns True if `obj` is a pytorch storage object.\n\n    Args:\n        obj (Object): Object to test\n    \"\"\"\n    return type(obj) in _storage_classes\n\n\ndef set_default_tensor_type(t):\n    global Tensor\n    global Storage\n    Tensor = _import_dotted_name(t)\n    Storage = _import_dotted_name(t.replace('Tensor', 'Storage'))\n\n    if 'cuda' in t:\n        import torch.cuda\n        torch.cuda.init()\n\n    _C._set_default_tensor_type(Tensor)\n\n\nfrom .random import set_rng_state, get_rng_state, manual_seed, initial_seed\nfrom .serialization import save, load\nfrom ._tensor_str import set_printoptions\n\n################################################################################\n# Define Storage and Tensor classes\n################################################################################\n\nfrom .storage import _StorageBase\nfrom .tensor import _TensorBase\n\n\nclass DoubleStorage(_C.DoubleStorageBase, _StorageBase):\n    pass\n\n\nclass FloatStorage(_C.FloatStorageBase, _StorageBase):\n    pass\n\n\nclass HalfStorage(_C.HalfStorageBase, _StorageBase):\n    pass\n\n\nclass LongStorage(_C.LongStorageBase, _StorageBase):\n    pass\n\n\nclass IntStorage(_C.IntStorageBase, _StorageBase):\n    pass\n\n\nclass ShortStorage(_C.ShortStorageBase, _StorageBase):\n    pass\n\n\nclass CharStorage(_C.CharStorageBase, _StorageBase):\n    pass\n\n\nclass ByteStorage(_C.ByteStorageBase, _StorageBase):\n    pass\n\n\nclass DoubleTensor(_C.DoubleTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return DoubleStorage\n\n\nclass FloatTensor(_C.FloatTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return FloatStorage\n\n\nclass HalfTensor(_C.HalfTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return HalfStorage\n\n\nclass LongTensor(_C.LongTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return LongStorage\n\n\nclass IntTensor(_C.IntTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return IntStorage\n\n\nclass ShortTensor(_C.ShortTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return True\n\n    @classmethod\n    def storage_type(cls):\n        return ShortStorage\n\n\nclass CharTensor(_C.CharTensorBase, _TensorBase):\n\n    def is_signed(self):\n        # TODO\n        return False\n\n    @classmethod\n    def storage_type(cls):\n        return CharStorage\n\n\nclass ByteTensor(_C.ByteTensorBase, _TensorBase):\n\n    def is_signed(self):\n        return False\n\n    @classmethod\n    def storage_type(cls):\n        return ByteStorage\n\n\n_storage_classes = {\n    DoubleStorage, FloatStorage, LongStorage, IntStorage, ShortStorage,\n    CharStorage, ByteStorage, HalfStorage\n}\n\n_tensor_classes = {\n    DoubleTensor, FloatTensor, LongTensor, IntTensor, ShortTensor,\n    CharTensor, ByteTensor, HalfTensor\n}\n\n_integer_tensor_classes = {\n    LongTensor, IntTensor, ShortTensor, CharTensor, ByteTensor\n}\n\n\n################################################################################\n# Import interface functions defined in Python\n################################################################################\n\nfrom .functional import *\n\n\n################################################################################\n# Initialize extension\n################################################################################\n\ndef manager_path():\n    if platform.system() == 'Windows':\n        return b\"\"\n    import os\n    path = os.path.join(os.path.abspath(os.path.dirname(__file__)), 'lib', 'torch_shm_manager')\n    if not os.path.exists(path):\n        raise RuntimeError(\"Unable to find torch_shm_manager at \" + path)\n    return path.encode('utf-8')\n\n\n# Shared memory manager needs to know the exact location of manager executable\n_C._initExtension(manager_path())\ndel manager_path\n\nset_default_tensor_type('torch.FloatTensor')\n\n################################################################################\n# Remove unnecessary members\n################################################################################\n\ndel DoubleStorageBase\ndel FloatStorageBase\ndel LongStorageBase\ndel IntStorageBase\ndel ShortStorageBase\ndel CharStorageBase\ndel ByteStorageBase\ndel DoubleTensorBase\ndel FloatTensorBase\ndel LongTensorBase\ndel IntTensorBase\ndel ShortTensorBase\ndel CharTensorBase\ndel ByteTensorBase\n\ndel SparseDoubleTensorBase\ndel SparseFloatTensorBase\ndel SparseLongTensorBase\ndel SparseIntTensorBase\ndel SparseShortTensorBase\ndel SparseCharTensorBase\ndel SparseByteTensorBase\n\n################################################################################\n# Import most common subpackages\n################################################################################\n\nimport torch.cuda\nimport torch.autograd\nimport torch.nn\nimport torch.optim\nimport torch.multiprocessing\nimport torch.sparse\nimport torch.utils.backcompat\nimport torch.onnx\nimport torch.random\nimport torch.distributions\nimport torch.testing\nfrom torch.autograd import no_grad, enable_grad\n\n_C._init_names(list(torch._tensor_classes) + list(torch._storage_classes))\n\n# attach docstrings to torch and tensor functions\nfrom . import _torch_docs, _tensor_docs, _storage_docs\ndel _torch_docs, _tensor_docs, _storage_docs\n", "path": "torch/__init__.py"}]}