Source code for pytorch_lightning.strategies.single_hpu
# Copyright The PyTorch Lightning team.## Licensed under the Apache License, Version 2.0 (the "License");# you may not use this file except in compliance with the License.# You may obtain a copy of the License at## http://www.apache.org/licenses/LICENSE-2.0## Unless required by applicable law or agreed to in writing, software# distributed under the License is distributed on an "AS IS" BASIS,# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.# See the License for the specific language governing permissions and# limitations under the License.fromtypingimportDict,Optionalimportpytorch_lightningasplfrompytorch_lightning.plugins.io.hpu_pluginimportHPUCheckpointIOfrompytorch_lightning.plugins.precisionimportPrecisionPluginfrompytorch_lightning.strategies.single_deviceimportSingleDeviceStrategyfrompytorch_lightning.utilitiesimport_HPU_AVAILABLEfrompytorch_lightning.utilities.exceptionsimportMisconfigurationExceptionfrompytorch_lightning.utilities.typesimport_DEVICEif_HPU_AVAILABLE:importhabana_frameworks.torch.core.hccl# noqa: F401fromhabana_frameworks.torch.utils.library_loaderimportload_habana_module
[docs]classSingleHPUStrategy(SingleDeviceStrategy):"""Strategy for training on single HPU device."""strategy_name="hpu_single"def__init__(self,device:_DEVICE="hpu",accelerator:Optional["pl.accelerators.accelerator.Accelerator"]=None,checkpoint_io:Optional[HPUCheckpointIO]=None,precision_plugin:Optional[PrecisionPlugin]=None,):ifnot_HPU_AVAILABLE:raiseMisconfigurationException("`SingleHPUStrategy` requires HPU devices to run")# This function is used to load Habana libraries required for PyTorch# to register HPU as one of the available devices.load_habana_module()super().__init__(accelerator=accelerator,device=device,checkpoint_io=checkpoint_ioorHPUCheckpointIO(),precision_plugin=precision_plugin,)@propertydefis_distributed(self)->bool:returnFalse
[docs]defsetup_optimizers(self,trainer:"pl.Trainer")->None:super().setup_optimizers(trainer)iflen(self.optimizers)>1:raiseMisconfigurationException("HPUs currently support only one optimizer.")
To analyze traffic and optimize your experience, we serve cookies on this site. By clicking or navigating, you agree to allow our usage of cookies. Read PyTorch Lightning's Privacy Policy.