We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
torch.is_tensor(torch.HalfTensor()) returns False. 
The problem is [here](https://github.com/pytorch/pytorch/blob/master/torch/__init__.py#L274).

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

{"golden_diff": "diff --git a/torch/__init__.py b/torch/__init__.py\n--- a/torch/__init__.py\n+++ b/torch/__init__.py\n@@ -268,12 +268,12 @@\n \n _storage_classes = {\n     DoubleStorage, FloatStorage, LongStorage, IntStorage, ShortStorage,\n-    CharStorage, ByteStorage,\n+    CharStorage, ByteStorage, HalfStorage\n }\n \n _tensor_classes = {\n     DoubleTensor, FloatTensor, LongTensor, IntTensor, ShortTensor,\n-    CharTensor, ByteTensor,\n+    CharTensor, ByteTensor, HalfTensor\n }\n", "issue": "torch.is_tensor(torch.HalfTensor()) returns False. \nThe problem is [here](https://github.com/pytorch/pytorch/blob/master/torch/__init__.py#L274).\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 >= 2.0.\n\"\"\"\n\nimport sys\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    '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:\n    pass\n\n# first check if the os package has the required flags\nif not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_NOW'):\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\nold_flags = sys.getdlopenflags()\nsys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_NOW)\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\nsys.setdlopenflags(old_flags)\ndel _dl_flags\ndel 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\ndef set_rng_state(new_state):\n    r\"\"\"Sets the random number generator state.\n\n    Args:\n        new_state (torch.ByteTensor): The desired state\n    \"\"\"\n    default_generator.set_state(new_state)\n\n\ndef get_rng_state():\n    r\"\"\"Returns the random number generator state as a ByteTensor.\"\"\"\n    return default_generator.get_state()\n\n\ndef manual_seed(seed):\n    r\"\"\"Sets the seed for generating random numbers. And returns a\n    `torch._C.Generator` object.\n\n    Args:\n        seed (int or long): The desired seed.\n    \"\"\"\n    if torch.cuda.is_available() and not torch.cuda._in_bad_fork:\n        torch.cuda.manual_seed_all(seed)\n\n    return default_generator.manual_seed(seed)\n\n\ndef initial_seed():\n    r\"\"\"Returns the initial seed for generating random numbers as a\n    python `long`.\n    \"\"\"\n    return default_generator.initial_seed()\n\n\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,\n}\n\n_tensor_classes = {\n    DoubleTensor, FloatTensor, LongTensor, IntTensor, ShortTensor,\n    CharTensor, ByteTensor,\n}\n\n\nset_default_tensor_type('torch.FloatTensor')\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    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\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\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 >= 2.0.\n\"\"\"\n\nimport sys\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    '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:\n    pass\n\n# first check if the os package has the required flags\nif not hasattr(_dl_flags, 'RTLD_GLOBAL') or not hasattr(_dl_flags, 'RTLD_NOW'):\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\nold_flags = sys.getdlopenflags()\nsys.setdlopenflags(_dl_flags.RTLD_GLOBAL | _dl_flags.RTLD_NOW)\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\nsys.setdlopenflags(old_flags)\ndel _dl_flags\ndel 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\ndef set_rng_state(new_state):\n    r\"\"\"Sets the random number generator state.\n\n    Args:\n        new_state (torch.ByteTensor): The desired state\n    \"\"\"\n    default_generator.set_state(new_state)\n\n\ndef get_rng_state():\n    r\"\"\"Returns the random number generator state as a ByteTensor.\"\"\"\n    return default_generator.get_state()\n\n\ndef manual_seed(seed):\n    r\"\"\"Sets the seed for generating random numbers. And returns a\n    `torch._C.Generator` object.\n\n    Args:\n        seed (int or long): The desired seed.\n    \"\"\"\n    if torch.cuda.is_available() and not torch.cuda._in_bad_fork:\n        torch.cuda.manual_seed_all(seed)\n\n    return default_generator.manual_seed(seed)\n\n\ndef initial_seed():\n    r\"\"\"Returns the initial seed for generating random numbers as a\n    python `long`.\n    \"\"\"\n    return default_generator.initial_seed()\n\n\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\nset_default_tensor_type('torch.FloatTensor')\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    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\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\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"}]}