已合并
[sync] PR-38376: fix: remove the deprecated get_cann_version() in _optim.py to reduce import time #38522
ascend-robot创建于 6月15日
[sync] PR-38376: fix: remove the deprecated get_cann_version() in _optim.py to reduce import time #38522
已合并
共 1 个文件变更+2-20
| @@ -1,30 +1,12 @@ | |||
| 1 | import torch | 1 | import torch |
| 2 | import torch.optim.optimizer as opt | 2 | import torch.optim.optimizer as opt |
| 3 | import torch_npu | 3 | import torch_npu |
| 4 | -from torch_npu.utils.collect_env import get_cann_version | ||
| 5 | - | ||
| 6 | - | ||
| 7 | -_device_name = None | ||
| 8 | -_cann_version = get_cann_version() | ||
| 9 | -_foreach_black_list_for_cann_starts_with = ['8.0.RC1', '8.0.RC2'] | ||
| 10 | -_foreach_black_list_for_cann_all = ['not known', '8.0.T1', '8.0.T2', '8.0.T3', '8.0.T5', '8.0.T6', '8.0.T7', | ||
| 11 | - '8.0.T8', '8.0.T10', '8.0.T13', '8.0.T16', '8.0.T37', '8.0.T38', '8.0.T39', '8.0.T50', '8.0.T51', '8.0.T52'] | ||
| 12 | 4 | ||
| 13 | 5 | ||
| 14 | def patch_supported_devices(): | 6 | def patch_supported_devices(): |
| 15 | - global _device_name | 7 | + device_name = torch_npu.npu.get_device_name(torch_npu.npu.current_device()) |
| 16 | - _device_name = (_device_name if _device_name is not None | ||
| 17 | - else torch_npu.npu.get_device_name(torch_npu.npu.current_device())) | ||
| 18 | 8 | ||
| 19 | - global _cann_version | 9 | + if (device_name > "Ascend910B" and device_name < "Ascend910PremiumA") or (device_name > "Ascend910_9"): |
| 20 | - if _cann_version is None or _cann_version < '8.0' or _cann_version in _foreach_black_list_for_cann_all: | ||
| 21 | - return ["cuda", "xpu"] | ||
| 22 | - | ||
| 23 | - for ver in _foreach_black_list_for_cann_starts_with: | ||
| 24 | - if _cann_version.startswith(ver): | ||
| 25 | - return ["cuda", "xpu"] | ||
| 26 | - | ||
| 27 | - if (_device_name > "Ascend910B" and _device_name < "Ascend910PremiumA") or (_device_name > "Ascend910_9"): | ||
| 28 | return ["cuda", "xpu", torch._C._get_privateuse1_backend_name()] | 10 | return ["cuda", "xpu", torch._C._get_privateuse1_backend_name()] |
| 29 | 11 | ||
| 30 | return ["cuda", "xpu"] | 12 | return ["cuda", "xpu"] |