• 文档 >
  • 模块代码 >
  • torch >
  • torch.cpu >
  • torch.cpu.amp.autocast 模式
快捷键

torch.cpu.amp.autocast 模式源代码

# mypy: 允许未类型化定义
from 打字 导入 任何
from typing_extensions 导入 已弃用

导入 火炬


全部 = ["自动转换"]


[文档]类 autocast(torch.amp.autocast_mode.autocast): r""" 查看 :class:`torch.autocast`。 ``torch.cpu.amp.autocast(args...)`` 已弃用。请使用 ``torch.amp.autocast("cpu", args...)`` 代替。 """ @deprecated( "``torch.cpu.amp.autocast(args...)`` 已弃用。" "请使用 ``torch.amp.autocast('cpu', args...)`` 代替。" category=FutureWarning ) def __init__( self, enabled: bool = True, dtype: torch.dtype = torch.bfloat16, cache_enabled: 布尔型 = True, ): if torch._jit_internal.is_scripting(): self._enabled = enabled self.device = "cpu" self.fast_dtype = dtype return super().__init__( "cpu", 启用=enabled, 数据类型=dtype, 缓存启用=cache_enabled ) def __enter__(self): if torch._jit_internal.is_scripting(): 返回自身 返回父类的 __enter__ 方法 # TODO: 讨论一个统一的适用于 TorchScript 的 autocast API def __exit__(self, exc_type: Any, exc_val: Any, exc_tb: Any): # 忽略[覆盖] if torch._jit_internal.is_scripting(): return return super().__exit__(exc_type, exc_val, exc_tb) def __call__(self, func): if torch._jit_internal.is_scripting(): 返回 func 返回 super().__call__(func)

© 版权所有 PyTorch 贡献者。

使用 Sphinx 构建,并使用 Read the Docs 提供的主题。

文档

查看 PyTorch 的全面开发者文档

查看文档

教程

深入了解初学者和高级开发者的教程

查看教程

资源

查找开发资源,获取您的疑问解答

查看资源