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
)
| 438 | |
| 439 | |
| 440 | def initialize( |
| 441 | args: Any = None, |
| 442 | model: torch.nn.Module = None, |
| 443 | optimizer: Optional[Union[Optimizer, DeepSpeedOptimizerCallable]] = None, |
| 444 | model_parameters: Optional[torch.nn.Module] = None, |
| 445 | training_data: Optional[torch.utils.data.Dataset] = None, |
| 446 | lr_scheduler: Optional[Union[_LRScheduler, DeepSpeedSchedulerCallable]] = None, |
| 447 | distributed_port: int = TORCH_DISTRIBUTED_DEFAULT_PORT, |
| 448 | mpu: Any = None, |
| 449 | dist_init_required: Optional[bool] = None, |
| 450 | collate_fn: Optional[Callable] = None, |
| 451 | config: Optional[Union[str, Dict[str, Any]]] = None, |
| 452 | mesh_param: Any = None, |
| 453 | config_params: Optional[Union[str, Dict[str, Any]]] = None |
| 454 | ) -> Tuple[DeepSpeedEngine, Optional[Union[Optimizer, DeepSpeedOptimizer]], Optional[DeepSpeedDataLoader], Any]: |
| 455 | """Initialize the DeepSpeed Engine. |
| 456 | |
| 457 | Arguments: |
| 458 | args: an object containing local_rank and deepspeed_config fields. |
| 459 | This is optional if `config` is passed. |
| 460 | |
| 461 | model: Required: nn.module class before apply any wrappers |
| 462 | |
| 463 | optimizer: Optional: a user defined Optimizer or Callable that returns an Optimizer object. |
| 464 | This overrides any optimizer definition in the DeepSpeed json config. |
| 465 | |
| 466 | model_parameters: Optional: An iterable of torch.Tensors or dicts. |
| 467 | Specifies what Tensors should be optimized. |
| 468 | |
| 469 | training_data: Optional: Dataset of type torch.utils.data.Dataset |
| 470 | |
| 471 | lr_scheduler: Optional: Learning Rate Scheduler Object or a Callable that takes an Optimizer and returns a Scheduler object. |
| 472 | The scheduler object should define a get_lr(), step(), state_dict(), and load_state_dict() methods |
| 473 | |
| 474 | distributed_port: Optional: Master node (rank 0)'s free port that needs to be used for communication during distributed training |
| 475 | |
| 476 | mpu: Optional: A model parallelism unit object that implements |
| 477 | get_{model,data}_parallel_{rank,group,world_size}() |
| 478 | |
| 479 | dist_init_required: Optional: None will auto-initialize torch distributed if needed, |
| 480 | otherwise the user can force it to be initialized or not via boolean. |
| 481 | |
| 482 | collate_fn: Optional: Merges a list of samples to form a |
| 483 | mini-batch of Tensor(s). Used when using batched loading from a |
| 484 | map-style dataset. |
| 485 | |
| 486 | config: Optional: Instead of requiring args.deepspeed_config you can pass your deepspeed config |
| 487 | as an argument instead, as a path or a dictionary. |
| 488 | |
| 489 | config_params: Optional: Same as `config`, kept for backwards compatibility. |
| 490 | |
| 491 | Returns: |
| 492 | A tuple of ``engine``, ``optimizer``, ``training_dataloader``, ``lr_scheduler`` |
| 493 | |
| 494 | * ``engine``: DeepSpeed runtime engine which wraps the client model for distributed training. |
| 495 | |
| 496 | * ``optimizer``: Wrapped optimizer if a user defined ``optimizer`` is supplied, or if |
| 497 | optimizer is specified in json config else ``None``. |