mirror of
https://github.com/hpcaitech/ColossalAI.git
synced 2025-09-10 13:30:19 +00:00
[booster] added the plugin base and torch ddp plugin (#3180)
* [booster] added the plugin base and torch ddp plugin * polish code * polish code * polish code
This commit is contained in:
51
colossalai/booster/plugin/plugin_base.py
Normal file
51
colossalai/booster/plugin/plugin_base.py
Normal file
@@ -0,0 +1,51 @@
|
||||
from abc import ABC, abstractmethod
|
||||
from typing import Callable, List, Tuple, Union
|
||||
|
||||
import torch.nn as nn
|
||||
from torch.optim import Optimizer
|
||||
from torch.optim.lr_scheduler import _LRScheduler as LRScheduler
|
||||
from torch.utils.data import DataLoader
|
||||
|
||||
from colossalai.booster.interface import OptimizerWrapper
|
||||
|
||||
__all__ = ['Plugin']
|
||||
|
||||
|
||||
class Plugin(ABC):
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def supported_devices(self) -> List[str]:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def supported_precisions(self) -> List[str]:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def control_precision(self) -> bool:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def control_device(self) -> bool:
|
||||
pass
|
||||
|
||||
@property
|
||||
@abstractmethod
|
||||
def support_no_sync(self) -> bool:
|
||||
pass
|
||||
|
||||
@abstractmethod
|
||||
def configure(
|
||||
self,
|
||||
model: nn.Module,
|
||||
optimizer: Optimizer,
|
||||
criterion: Callable = None,
|
||||
dataloader: DataLoader = None,
|
||||
lr_scheduler: LRScheduler = None,
|
||||
) -> Tuple[Union[nn.Module, OptimizerWrapper, LRScheduler, DataLoader]]:
|
||||
# implement this method
|
||||
pass
|
Reference in New Issue
Block a user