Initialize the DeepSpeed Engine. Arguments: args: an object containing local_rank and deepspeed_config fields. This is optional if `config` is passed. model: Required: nn.module class before apply any wrappers optimizer: Optional: a user defined Optimizer o
(
args: Any = None,
model: torch.nn.Module = None,
optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None,
model_parameters: Optional[torch.nn.Module] = None,
training_data: Optional[torch.utils.data.Dataset] = None,
lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None,
distributed_port: int = TORCH_DISTRIBUTED_DEFAULT_PORT,
mpu: Any = None,
dist_init_required: Optional[bool] = None,
collate_fn: Optional[Callable] = None,
config: Optional[Union[str, Dict[str, Any]]] = None,
mesh_param: Any = None,
config_params: Optional[Union[str, Dict[str, Any]]] = None
)
| 91 | |
| 92 | |
| 93 | def initialize( |
| 94 | args: Any = None, |
| 95 | model: torch.nn.Module = None, |
| 96 | optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None, |
| 97 | model_parameters: Optional[torch.nn.Module] = None, |
| 98 | training_data: Optional[torch.utils.data.Dataset] = None, |
| 99 | lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None, |
| 100 | distributed_port: int = TORCH_DISTRIBUTED_DEFAULT_PORT, |
| 101 | mpu: Any = None, |
| 102 | dist_init_required: Optional[bool] = None, |
| 103 | collate_fn: Optional[Callable] = None, |
| 104 | config: Optional[Union[str, Dict[str, Any]]] = None, |
| 105 | mesh_param: Any = None, |
| 106 | config_params: Optional[Union[str, Dict[str, Any]]] = None |
| 107 | ) -> Tuple[DeepSpeedEngine, Optional[Union[Optimizer, DeepSpeedOptimizer]], Optional[DeepSpeedDataLoader], Any]: |
| 108 | """Initialize the DeepSpeed Engine. |
| 109 | |
| 110 | Arguments: |
| 111 | args: an object containing local_rank and deepspeed_config fields. |
| 112 | This is optional if `config` is passed. |
| 113 | |
| 114 | model: Required: nn.module class before apply any wrappers |
| 115 | |
| 116 | optimizer: Optional: a user defined Optimizer or Callable that returns an Optimizer object. |
| 117 | This overrides any optimizer definition in the DeepSpeed json config. |
| 118 | |
| 119 | model_parameters: Optional: An iterable of torch.Tensors or dicts. |
| 120 | Specifies what Tensors should be optimized. |
| 121 | |
| 122 | training_data: Optional: Dataset of type torch.utils.data.Dataset |
| 123 | |
| 124 | lr_scheduler: Optional: Learning Rate Scheduler Object or a Callable that takes an Optimizer and returns a Scheduler object. |
| 125 | The scheduler object should define a get_lr(), step(), state_dict(), and load_state_dict() methods |
| 126 | |
| 127 | distributed_port: Optional: Master node (rank 0)'s free port that needs to be used for communication during distributed training |
| 128 | |
| 129 | mpu: Optional: A model parallelism unit object that implements |
| 130 | get_{model,data}_parallel_{rank,group,world_size}() |
| 131 | |
| 132 | dist_init_required: Optional: None will auto-initialize torch distributed if needed, |
| 133 | otherwise the user can force it to be initialized or not via boolean. |
| 134 | |
| 135 | collate_fn: Optional: Merges a list of samples to form a |
| 136 | mini-batch of Tensor(s). Used when using batched loading from a |
| 137 | map-style dataset. |
| 138 | |
| 139 | config: Optional: Instead of requiring args.deepspeed_config you can pass your deepspeed config |
| 140 | as an argument instead, as a path or a dictionary. |
| 141 | |
| 142 | config_params: Optional: Same as `config`, kept for backwards compatibility. |
| 143 | |
| 144 | Returns: |
| 145 | A tuple of ``engine``, ``optimizer``, ``training_dataloader``, ``lr_scheduler`` |
| 146 | |
| 147 | * ``engine``: DeepSpeed runtime engine which wraps the client model for distributed training. |
| 148 | |
| 149 | * ``optimizer``: Wrapped optimizer if a user defined ``optimizer`` is supplied, or if |
| 150 | optimizer is specified in json config else ``None``. |