/
usr
/
local
/
lib64
/
python3.6
/
site-packages
/
torch
/
/usr/local/lib64/python3.6/site-packages/torch
mkdir
upload
Name
Size
Mode
Actions
ao/
-
0755
rm
autograd/
-
0755
rm
backends/
-
0755
rm
bin/
-
0755
rm
contrib/
-
0755
rm
cpu/
-
0755
rm
cuda/
-
0755
rm
distributed/
-
0755
rm
distributions/
-
0755
rm
fft/
-
0755
rm
for_onnx/
-
0755
rm
futures/
-
0755
rm
fx/
-
0755
rm
include/
-
0755
rm
jit/
-
0755
rm
lib/
-
0755
rm
linalg/
-
0755
rm
multiprocessing/
-
0755
rm
nn/
-
0755
rm
onnx/
-
0755
rm
optim/
-
0755
rm
package/
-
0755
rm
profiler/
-
0755
rm
quantization/
-
0755
rm
share/
-
0755
rm
sparse/
-
0755
rm
special/
-
0755
rm
testing/
-
0755
rm
utils/
-
0755
rm
_C/
-
0755
rm
__pycache__/
-
0755
rm
autocast_mode.py
9663
0644
edit
dl
rm
functional.py
71257
0644
edit
dl
rm
hub.py
23371
0644
edit
dl
rm
overrides.py
84146
0644
edit
dl
rm
py.typed
0
0644
edit
dl
rm
quasirandom.py
7489
0644
edit
dl
rm
random.py
4828
0644
edit
dl
rm
serialization.py
36544
0644
edit
dl
rm
storage.py
5762
0644
edit
dl
rm
torch_version.py
3468
0644
edit
dl
rm
types.py
1552
0644
edit
dl
rm
version.py
125
0644
edit
dl
rm
_appdirs.py
26245
0644
edit
dl
rm
_C.cpython-36m-x86_64-linux-gnu.so
29296
0755
edit
dl
rm
_classes.py
1717
0644
edit
dl
rm
_deploy.py
3100
0644
edit
dl
rm
_dl.cpython-36m-x86_64-linux-gnu.so
29832
0755
edit
dl
rm
_jit_internal.py
46910
0644
edit
dl
rm
_linalg_utils.py
2373
0644
edit
dl
rm
_lobpcg.py
44076
0644
edit
dl
rm
_lowrank.py
11031
0644
edit
dl
rm
_namedtensor_internals.py
5351
0644
edit
dl
rm
_ops.py
4457
0644
edit
dl
rm
_python_dispatcher.py
7011
0644
edit
dl
rm
_six.py
1858
0644
edit
dl
rm
_sources.py
3882
0644
edit
dl
rm
_storage_docs.py
1298
0644
edit
dl
rm
_tensor.py
50854
0644
edit
dl
rm
_tensor_docs.py
113474
0644
edit
dl
rm
_tensor_str.py
18091
0644
edit
dl
rm
_torch_docs.py
364678
0644
edit
dl
rm
_utils.py
21617
0644
edit
dl
rm
_utils_internal.py
1687
0644
edit
dl
rm
_VF.py
656
0644
edit
dl
rm
_vmap_internals.py
13219
0644
edit
dl
rm
__config__.py
551
0644
edit
dl
rm
__future__.py
813
0644
edit
dl
rm
__init__.py
31199
0644
edit
dl
rm
Edit:
/usr/local/lib64/python3.6/site-packages/torch/autocast_mode.py
(9663B)
import torch import functools import warnings class autocast(object): r""" Instances of :class:`autocast` serve as context managers or decorators that allow regions of your script to run in mixed precision. In these regions, ops run in an op-specific dtype chosen by autocast to improve performance while maintaining accuracy. See the :ref:`Autocast Op Reference<autocast-op-reference>` for details. When entering an autocast-enabled region, Tensors may be any type. You should not call ``half()`` or ``bfloat16()`` on your model(s) or inputs when using autocasting. :class:`autocast` should wrap only the forward pass(es) of your network, including the loss computation(s). Backward passes under autocast are not recommended. Backward ops run in the same type that autocast used for corresponding forward ops. Example for CUDA Devices:: # Creates model and optimizer in default precision model = Net().cuda() optimizer = optim.SGD(model.parameters(), ...) for input, target in data: optimizer.zero_grad() # Enables autocasting for the forward pass (model + loss) with autocast(): output = model(input) loss = loss_fn(output, target) # Exits the context manager before backward() loss.backward() optimizer.step() See the :ref:`Automatic Mixed Precision examples<amp-examples>` for usage (along with gradient scaling) in more complex scenarios (e.g., gradient penalty, multiple models/losses, custom autograd functions). :class:`autocast` can also be used as a decorator, e.g., on the ``forward`` method of your model:: class AutocastModel(nn.Module): ... @autocast() def forward(self, input): ... Floating-point Tensors produced in an autocast-enabled region may be ``float16``. After returning to an autocast-disabled region, using them with floating-point Tensors of different dtypes may cause type mismatch errors. If so, cast the Tensor(s) produced in the autocast region back to ``float32`` (or other dtype if desired). If a Tensor from the autocast region is already ``float32``, the cast is a no-op, and incurs no additional overhead. CUDA Example:: # Creates some tensors in default dtype (here assumed to be float32) a_float32 = torch.rand((8, 8), device="cuda") b_float32 = torch.rand((8, 8), device="cuda") c_float32 = torch.rand((8, 8), device="cuda") d_float32 = torch.rand((8, 8), device="cuda") with autocast(): # torch.mm is on autocast's list of ops that should run in float16. # Inputs are float32, but the op runs in float16 and produces float16 output. # No manual casts are required. e_float16 = torch.mm(a_float32, b_float32) # Also handles mixed input types f_float16 = torch.mm(d_float32, e_float16) # After exiting autocast, calls f_float16.float() to use with d_float32 g_float32 = torch.mm(d_float32, f_float16.float()) CPU Example:: # Creates some tensors in default dtype (here assumed to be float32) a_float32 = torch.rand((8, 8), device="cpu") b_float32 = torch.rand((8, 8), device="cpu") c_float32 = torch.rand((8, 8), device="cpu") d_float32 = torch.rand((8, 8), device="cpu") with autocast(dtype=torch.bfloat16, device_type="cpu"): # torch.mm is on autocast's list of ops that should run in bfloat16. # Inputs are float32, but the op runs in bfloat16 and produces bfloat16 output. # No manual casts are required. e_bfloat16 = torch.mm(a_float32, b_float32) # Also handles mixed input types f_bfloat16 = torch.mm(d_float32, e_bfloat16) # After exiting autocast, calls f_float16.float() to use with d_float32 g_float32 = torch.mm(d_float32, f_bfloat16.float()) Type mismatch errors *in* an autocast-enabled region are a bug; if this is what you observe, please file an issue. ``autocast(enabled=False)`` subregions can be nested in autocast-enabled regions. Locally disabling autocast can be useful, for example, if you want to force a subregion to run in a particular ``dtype``. Disabling autocast gives you explicit control over the execution type. In the subregion, inputs from the surrounding region should be cast to ``dtype`` before use:: # Creates some tensors in default dtype (here assumed to be float32) a_float32 = torch.rand((8, 8), device="cuda") b_float32 = torch.rand((8, 8), device="cuda") c_float32 = torch.rand((8, 8), device="cuda") d_float32 = torch.rand((8, 8), device="cuda") with autocast(): e_float16 = torch.mm(a_float32, b_float32) with autocast(enabled=False): # Calls e_float16.float() to ensure float32 execution # (necessary because e_float16 was created in an autocasted region) f_float32 = torch.mm(c_float32, e_float16.float()) # No manual casts are required when re-entering the autocast-enabled region. # torch.mm again runs in float16 and produces float16 output, regardless of input types. g_float16 = torch.mm(d_float32, f_float32) The autocast state is thread-local. If you want it enabled in a new thread, the context manager or decorator must be invoked in that thread. This affects :class:`torch.nn.DataParallel` and :class:`torch.nn.parallel.DistributedDataParallel` when used with more than one GPU per process (see :ref:`Working with Multiple GPUs<amp-multigpu>`). Args: device_type(string, required): Whether to use 'cuda' or 'cpu' device enabled(bool, optional, default=True): Whether autocasting should be enabled in the region. dtype(torch_dtype, optional): Whether to use torch.float16 or torch.bfloat16. cache_enabled(bool, optional, default=True): Whether the weight cache inside autocast should be enabled. """ def __init__(self, device_type, enabled=True, **kwargs): self.device = device_type if self.device == 'cuda': self.fast_dtype = torch.get_autocast_gpu_dtype() elif self.device == 'cpu': self.fast_dtype = torch.get_autocast_cpu_dtype() else: raise RuntimeError('User specified autocast device_type must be \'cuda\' or \'cpu\'') self._cache_enabled = torch.is_autocast_cache_enabled() if torch.cuda.amp.common.amp_definitely_not_available() and self.device == 'cuda': warnings.warn('User provided device_type of \'cuda\', but CUDA is not available. Disabling') enabled = False for key, value in kwargs.items(): if key == 'dtype': self.fast_dtype = value if key == 'cache_enabled': self._cache_enabled = value if not ((key == 'dtype') or (key == 'cache_enabled')): raise RuntimeError('Unrecognized optional argument supplied to autocast context manager: ' + str(key)) if self.device == 'cpu': supported_dtype = [torch.bfloat16] if self.fast_dtype not in supported_dtype: error_message = 'In CPU autocast, but the target dtype is not supported. Disabling autocast.\n' error_message += 'CPU Autocast only supports dtype of torch.bfloat16 currently.' warnings.warn(error_message) enabled = False if self.device == 'cuda': if self.fast_dtype == torch.bfloat16 and not torch.cuda.is_bf16_supported(): raise RuntimeError('Current CUDA Device does not support bfloat16. Please switch dtype to float16.') self._enabled = enabled def __enter__(self): self.prev_cache_enabled = torch.is_autocast_cache_enabled() if self.device == 'cpu': self.prev = torch.is_autocast_cpu_enabled() self.prev_fastdtype = torch.get_autocast_cpu_dtype() torch.set_autocast_cpu_enabled(self._enabled) torch.set_autocast_cpu_dtype(self.fast_dtype) torch.autocast_increment_nesting() else: self.prev = torch.is_autocast_enabled() self.prev_fastdtype = torch.get_autocast_gpu_dtype() torch.set_autocast_gpu_dtype(self.fast_dtype) torch.set_autocast_enabled(self._enabled) torch.autocast_increment_nesting() torch.set_autocast_cache_enabled(self._cache_enabled) def __exit__(self, *args): # Drop the cache when we exit to a nesting level that's outside any instance of autocast. if self.device == 'cpu': if torch.autocast_decrement_nesting() == 0: torch.clear_autocast_cache() torch.set_autocast_cpu_enabled(self.prev) torch.set_autocast_cpu_dtype(self.prev_fastdtype) else: if torch.autocast_decrement_nesting() == 0: torch.clear_autocast_cache() torch.set_autocast_enabled(self.prev) torch.set_autocast_gpu_dtype(self.prev_fastdtype) torch.set_autocast_cache_enabled(self.prev_cache_enabled) return False def __call__(self, func): @functools.wraps(func) def decorate_autocast(*args, **kwargs): with self: return func(*args, **kwargs) return decorate_autocast
Save
cmd:
run